nci/lib/scm/mercurial.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

'use strict';
2014-05-10 10:19:47 +00:00
var ParentScm = require('./base').BaseScm,
inherits = require('util').inherits;
2014-05-10 10:19:47 +00:00
function Scm(params) {
ParentScm.call(this, params);
}
2014-05-10 10:19:47 +00:00
exports.MercurialScm = Scm;
2014-05-10 10:19:47 +00:00
inherits(Scm, ParentScm);
2014-05-10 10:19:47 +00:00
Scm.prototype.defaultRev = 'default';
2014-05-10 10:19:47 +00:00
Scm.prototype.clone = function(dst, rev, callback) {
var self = this;
2014-05-10 10:19:47 +00:00
this.exec({
cmd: 'hg',
args: ['clone', '--rev', rev, this.repository, dst]
}, function(err) {
self.cwd = dst;
callback(err);
});
};
2014-05-10 10:19:47 +00:00
Scm.prototype.pull = function(rev, callback) {
this.exec({cmd: 'hg', args: ['pull', '--rev', rev]}, callback);
};
2014-05-10 10:19:47 +00:00
Scm.prototype.getId = function(callback) {
this.exec({cmd: 'hg', args: ['id', '--id']}, function(err, stdout) {
callback(err, !err && stdout.replace('\n', ''));
});
};
2014-05-10 10:19:47 +00:00
Scm.prototype.getChanges = function(rev1, rev2, callback) {
this.exec({cmd: 'hg', args: [
'log', '--rev', rev2 + ':' + rev1,
'--template', '{node|short};;;{author};;;{date|date};;;{desc}\n'
2014-05-10 10:19:47 +00:00
]}, function(err, stdout) {
callback(err, !err && stdout.split('\n').slice(0, -2).map(function(str) {
var parts = str.split(';;;');
return {
id: parts[0],
author: parts[1],
date: new Date(parts[2]).getTime(),
comment: parts[3]
};
}));
});
};
2014-05-10 10:19:47 +00:00
Scm.prototype.update = function(rev, callback) {
this.exec({cmd: 'hg', args: ['up', rev]}, callback);
};