From da9d4a5c25bcc2f4a6cd4447137f38e4c3b2a588 Mon Sep 17 00:00:00 2001 From: oleg Date: Sat, 10 May 2014 13:36:07 +0400 Subject: [PATCH] scm fixes --- lib/scm/base.js | 16 +++++++--------- lib/scm/mercurial.js | 6 +++--- test/scm.js | 25 ++++++++++++++++++++++--- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/lib/scm/base.js b/lib/scm/base.js index 4b6604c..055659d 100644 --- a/lib/scm/base.js +++ b/lib/scm/base.js @@ -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; diff --git a/lib/scm/mercurial.js b/lib/scm/mercurial.js index c0b9d71..d603add 100644 --- a/lib/scm/mercurial.js +++ b/lib/scm/mercurial.js @@ -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); }); diff --git a/test/scm.js b/test/scm.js index 31af893..374051d 100644 --- a/test/scm.js +++ b/test/scm.js @@ -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); });