better git support + allow run tests with git instead of mercurial

This commit is contained in:
oleg 2015-07-15 14:06:02 +03:00
parent ae860ad54e
commit 9c0ba72c1b
6 changed files with 72 additions and 37 deletions

View File

@ -4,6 +4,9 @@ scm:
repository: ./
rev: master
# catchRev:
# comment: !!js/regexp //
notify:
on:
- error

View File

@ -76,8 +76,30 @@ Scm.prototype.clone = function(dst, rev, callback) {
};
Scm.prototype.pull = function(rev, callback) {
// TODO: pull changes without update
this.run({cmd: 'git', args: ['pull']}, callback);
var self = this;
Steppy(
function() {
// get current rev to update on it after pull
self.getCurrent(this.slot());
},
function(err, currentRev) {
this.pass(currentRev);
self.run({cmd: 'git', args: ['pull']}, this.slot());
},
function(err, currentRev) {
self.update(currentRev.id, this.slot());
},
function(err) {
// ignore "You are not currently on a branch" error
if (
err && err.stderr &&
/You are not currently on a branch/.test(err.stderr)
) {
err = null;
}
callback(err);
}
);
};
Scm.prototype.getRev = function(rev, callback) {
@ -113,7 +135,7 @@ Scm.prototype.getChanges = function(rev1, rev2, callback) {
Steppy(
function() {
self.run({cmd: 'git', args: [
'log', rev1 + '..' + rev2,
'log', rev1 ? rev1 + '..' + rev2 : rev2,
'--pretty=' + self._revTemplate
]}, this.slot());
},

View File

@ -20,11 +20,7 @@ describe('Distributor run self after catch', function() {
projects: [{
name: 'project1',
dir: __dirname,
scm: {
type: 'mercurial',
repository: path.join(__dirname, '..', 'repos', 'mercurial'),
rev: 'default'
},
scm: helpers.repository.scm,
steps: [
{type: 'shell', cmd: 'echo 1'}
],
@ -50,8 +46,9 @@ describe('Distributor run self after catch', function() {
});
it('should run without errors', function(done) {
distributor.run({projectName: 'project1'}, function(err) {
expect(err).not.ok();
distributor.run({projectName: 'project1'}, function(err, build) {
if (err) return done(err);
expect(build.error).not.ok();
done();
});
});
@ -61,7 +58,7 @@ describe('Distributor run self after catch', function() {
expect(executorRunSpy.getCall(callIndex).thisValue.project.name)
.equal('project1');
expect(scmDataSpy.getCall(callIndex).args[0].rev)
.eql(helpers.mercurialRevs[revIndex]);
.eql(helpers.repository.revs[revIndex]);
});
};
@ -69,7 +66,7 @@ describe('Distributor run self after catch', function() {
itRunWithRev(1, 1);
itRunWithRev(2, 2);
var revsCount = helpers.mercurialRevs.length;
var revsCount = helpers.repository.revs.length;
it('should call run ' + revsCount + ' times in total', function() {
expect(executorRunSpy.callCount).equal(revsCount);
});

View File

@ -5,7 +5,7 @@ var expect = require('expect.js'),
createExecutor = require('../lib/executor').createExecutor,
_ = require('underscore'),
helpers = require('./helpers'),
mercurialRevs = helpers.mercurialRevs;
repository = require('./helpers').repository;
['local'].forEach(function(type) {
@ -23,11 +23,7 @@ var expect = require('expect.js'),
project: _({
dir: __dirname,
name: 'test project',
scm: {
type: 'mercurial',
repository: path.join(__dirname, 'repos', 'mercurial'),
rev: 'default'
},
scm: repository.scm,
steps: [
{type: 'shell', cmd: 'echo 1'},
{type: 'shell', cmd: 'echo 2'}
@ -56,8 +52,8 @@ var expect = require('expect.js'),
'scm data should be rev: last, changes: [0-last], is latest',
function() {
expect(scmData).eql({
rev: mercurialRevs[mercurialRevs.length - 1],
changes: mercurialRevs.slice().reverse(),
rev: repository.revs[repository.revs.length - 1],
changes: repository.revs.slice().reverse(),
isLatest: true
});
}
@ -102,8 +98,8 @@ var expect = require('expect.js'),
it('scm data should be rev: 1, changes: [0, 1], not latest',
function() {
expect(scmData).eql({
rev: mercurialRevs[1],
changes: mercurialRevs.slice(0, 2).reverse(),
rev: repository.revs[1],
changes: repository.revs.slice(0, 2).reverse(),
isLatest: false
});
});
@ -118,8 +114,8 @@ var expect = require('expect.js'),
'scm data should be rev: last, changes: [2-last], is latest',
function() {
expect(scmData).eql({
rev: mercurialRevs[mercurialRevs.length - 1],
changes: mercurialRevs.slice(2).reverse(),
rev: repository.revs[repository.revs.length - 1],
changes: repository.revs.slice(2).reverse(),
isLatest: true
});
}
@ -158,8 +154,8 @@ var expect = require('expect.js'),
it('scm data should be rev: 2, changes: [0, 2], not latest',
function() {
expect(scmData).eql({
rev: mercurialRevs[2],
changes: mercurialRevs.slice(0, 3).reverse(),
rev: repository.revs[2],
changes: repository.revs.slice(0, 3).reverse(),
isLatest: false
});
});
@ -172,8 +168,8 @@ var expect = require('expect.js'),
'scm data should be rev: last, changes: [3-last], is latest',
function() {
expect(scmData).eql({
rev: mercurialRevs[mercurialRevs.length - 1],
changes: mercurialRevs.slice(3).reverse(),
rev: repository.revs[repository.revs.length - 1],
changes: repository.revs.slice(3).reverse(),
isLatest: true
});
}

View File

@ -2,6 +2,7 @@
var SpawnCommand = require('../lib/command/spawn').Command,
fs = require('fs'),
path = require('path'),
db = require('../db');
@ -19,8 +20,10 @@ exports.removeDirIfExists = function(dir, done) {
}));
};
exports.revs = {};
// revisions for the test mercurial repo
exports.mercurialRevs = [{
exports.revs.mercurial = [{
id: 'da2762e71e87',
tags: ['zero revision'],
author: 'kotbegemot',
@ -44,7 +47,7 @@ exports.mercurialRevs = [{
comment: 'add tags'
}];
exports.gitRevs = [{
exports.revs.git = [{
id: '4ec4643',
tags: ['zero'],
author: 'oleg',
@ -63,6 +66,25 @@ exports.gitRevs = [{
comment: 'third revision'
}];
exports.scm = {};
exports.scm.mercurial = {
type: 'mercurial',
repository: path.join(__dirname, 'repos', 'mercurial'),
rev: 'default'
};
exports.scm.git = {
type: 'git',
repository: path.join(__dirname, 'repos', 'git'),
rev: 'master'
};
exports.repository = {
scm: exports.scm.mercurial,
revs: exports.revs.mercurial
};
exports.initDb = function(callback) {
db.init('path/to/db/ignored/for/memdown', {
db: require('memdown'),

View File

@ -6,18 +6,13 @@ var expect = require('expect.js'),
fs = require('fs'),
createScm = require('../lib/scm').createScm,
SpawnCommand = require('../lib/command/spawn').Command,
mercurialRevs = require('./helpers').mercurialRevs,
helpers = require('./helpers'),
gitRevs = require('./helpers').gitRevs;
var getTestData = function(type) {
if (type === 'mercurial') return mercurialRevs;
if (type === 'git') return gitRevs;
};
['mercurial', 'git'].forEach(function(type) {
describe(type, function() {
var data = getTestData(type),
var data = helpers.revs[type],
originalRepositoryPath = path.join(__dirname, 'repos', type),
repositoryName = 'test-repository',
repositoryPath = path.join(