scm fixes

This commit is contained in:
oleg 2014-05-10 13:36:07 +04:00
parent dc00488eea
commit da9d4a5c25
3 changed files with 32 additions and 15 deletions

View File

@ -4,14 +4,12 @@ var spawn = require('child_process').spawn,
EventEmitter = require('events').EventEmitter,
inherits = require('util').inherits;
function BaseScm(config) {
var self = this;
self.config = config;
['src'].forEach(function(key) {
if (key in self.config === false) throw new Error(key + ' is not set');
self[key] = self.config[key];
});
self.cwd = config.cwd;
function BaseScm(params) {
this.repository = params.repository;
this.cwd = params.cwd;
if (!this.repository && !this.cwd) throw new Error(
'`repository` or `cwd` must be set'
);
}
module.exports = BaseScm;
@ -34,7 +32,7 @@ BaseScm.prototype._exec = function(command, args, callback) {
var err = null;
if (code !== 0) err = new Error(
'Scm command exits with non-zero code: ' + code
)
);
callback(err, stdout);
});
return cmd;

View File

@ -3,8 +3,8 @@
var BaseScm = require('./base'),
inherits = require('util').inherits;
function MercurialScm(config) {
BaseScm.call(this, config);
function MercurialScm(params) {
BaseScm.call(this, params);
}
module.exports = MercurialScm;
@ -15,7 +15,7 @@ MercurialScm.prototype.defaultRev = 'default';
MercurialScm.prototype.clone = function(dst, rev, callback) {
var self = this;
this._exec('hg', ['clone', '--rev', rev, this.src, dst], function(err) {
this._exec('hg', ['clone', '--rev', rev, this.repository, dst], function(err) {
self.cwd = dst;
callback(err);
});

View File

@ -22,9 +22,13 @@ var expect = require('expect.js'),
}));
});
var scm = createScm({
type: type,
src: path.join(__dirname, 'repos', type)
var scm;
it('create scm instance attached to new repository without errors', function() {
scm = createScm({
type: type,
repository: path.join(__dirname, 'repos', type)
});
});
var currentRev = data.rev0.id;
@ -81,6 +85,21 @@ var expect = require('expect.js'),
});
});
it('create scm instance attached to existing `cwd` without errors', function() {
scm = createScm({type: type, cwd: repositoryPath});
});
it('expect repository log from rev0 to default revision equals to ' +
'rev1 and rev2 (in reverse order)', function(done) {
scm.getChanges(data.rev0.id, scm.defaultRev, function(err, changes) {
if (err) return done(err);
expect(changes).ok();
expect(changes).length(2);
expect(changes).eql([data.rev2, data.rev1]);
done();
});
});
it('remove test repository dir', function(done) {
scm._exec('rm', ['-R', repositoryPath], done);
});