From 9c0ba72c1becd5749b850398911c735af48b45fb Mon Sep 17 00:00:00 2001 From: oleg Date: Wed, 15 Jul 2015 14:06:02 +0300 Subject: [PATCH] better git support + allow run tests with git instead of mercurial --- data/projects/nci/config.yaml | 3 +++ lib/scm/git.js | 28 +++++++++++++++++++++--- test/distributor/runSelfAfterCatchRev.js | 15 +++++-------- test/executor.js | 28 ++++++++++-------------- test/helpers.js | 26 ++++++++++++++++++++-- test/scm.js | 9 ++------ 6 files changed, 72 insertions(+), 37 deletions(-) diff --git a/data/projects/nci/config.yaml b/data/projects/nci/config.yaml index 5aca4d4..9c3be6b 100644 --- a/data/projects/nci/config.yaml +++ b/data/projects/nci/config.yaml @@ -4,6 +4,9 @@ scm: repository: ./ rev: master +# catchRev: +# comment: !!js/regexp // + notify: on: - error diff --git a/lib/scm/git.js b/lib/scm/git.js index 3c76dd3..3b5e717 100644 --- a/lib/scm/git.js +++ b/lib/scm/git.js @@ -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()); }, diff --git a/test/distributor/runSelfAfterCatchRev.js b/test/distributor/runSelfAfterCatchRev.js index f246baf..06761e4 100644 --- a/test/distributor/runSelfAfterCatchRev.js +++ b/test/distributor/runSelfAfterCatchRev.js @@ -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); }); diff --git a/test/executor.js b/test/executor.js index bec2423..8e60ba2 100644 --- a/test/executor.js +++ b/test/executor.js @@ -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 }); } diff --git a/test/helpers.js b/test/helpers.js index 8e68fcb..4970f77 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -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'), diff --git a/test/scm.js b/test/scm.js index c1b0be8..07eaeb4 100644 --- a/test/scm.js +++ b/test/scm.js @@ -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(