2014-05-09 23:27:35 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var spawn = require('child_process').spawn,
|
|
|
|
EventEmitter = require('events').EventEmitter,
|
|
|
|
inherits = require('util').inherits;
|
|
|
|
|
2014-05-10 09:36:07 +00:00
|
|
|
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'
|
|
|
|
);
|
2014-05-09 23:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = BaseScm;
|
|
|
|
|
|
|
|
inherits(BaseScm, EventEmitter);
|
|
|
|
|
|
|
|
BaseScm.prototype._exec = function(command, args, callback) {
|
|
|
|
var self = this,
|
|
|
|
stdout = '';
|
|
|
|
var cmd = spawn(command, args, {cwd: this.cwd});
|
|
|
|
cmd.stdout.on('data', function(data) {
|
|
|
|
if (self.isEmit) self.emit('stdout', data);
|
|
|
|
stdout += data;
|
|
|
|
});
|
|
|
|
cmd.stderr.on('data', function(data) {
|
|
|
|
callback(new Error('Scm outputs to stderr: ' + data));
|
|
|
|
cmd.kill();
|
|
|
|
});
|
|
|
|
cmd.on('exit', function(code) {
|
|
|
|
var err = null;
|
|
|
|
if (code !== 0) err = new Error(
|
|
|
|
'Scm command exits with non-zero code: ' + code
|
2014-05-10 09:36:07 +00:00
|
|
|
);
|
2014-05-09 23:27:35 +00:00
|
|
|
callback(err, stdout);
|
|
|
|
});
|
|
|
|
return cmd;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clone repository to the `dst` update to `rev` and set `this.cwd` to `dst`
|
|
|
|
*/
|
|
|
|
BaseScm.prototype.clone = function(dst, rev, callback) {
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pull changes from remote repository without update
|
|
|
|
*/
|
|
|
|
BaseScm.prototype.pull = function(rev, callback) {
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns string id of current revision
|
|
|
|
*/
|
|
|
|
BaseScm.prototype.getId = function(callback) {
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns array of changes between revisions
|
|
|
|
*/
|
|
|
|
BaseScm.prototype.getChanges = function(rev1, rev2, callback) {
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates to revision
|
|
|
|
*/
|
|
|
|
BaseScm.prototype.update = function(rev, callback) {
|
|
|
|
};
|
|
|
|
|