Merge pull request #565 from eatdrinksleepcode/revision-range

More robust support for revision ranges
This commit is contained in:
Peter Cottle 2019-04-21 12:57:44 -07:00 committed by GitHub
commit 06e0f29acf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 240 additions and 47 deletions

View file

@ -1,3 +1,5 @@
var Q = require('q');
var HeadlessGit = require('../src/js/git/headless').HeadlessGit;
var TreeCompare = require('../src/js/graph/treeCompare.js');
@ -95,6 +97,27 @@ var expectLevelSolved = function(levelBlob) {
expectLevelAsync(headless, levelBlob);
};
var runCommand = function(command, resultHandler) {
var headless = new HeadlessGit();
var deferred = Q.defer();
var msg = null;
deferred.promise.then(function(commands) {
msg = commands[commands.length - 1].get('error').get('msg');
});
runs(function() {
headless.sendCommand(command, deferred);
});
waitsFor(function() {
if(null == msg) {
return false;
}
resultHandler(msg);
return true;
}, 'commands should be finished', 500);
};
var TIME = 150;
// useful for throwing garbage and then expecting one commit
var ONE_COMMIT_TREE = '{"branches":{"master":{"target":"C2","id":"master"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"},"C2":{"parents":["C1"],"id":"C2"}},"HEAD":{"target":"master","id":"HEAD"}}';
@ -105,6 +128,7 @@ module.exports = {
TIME: TIME,
expectTreeAsync: expectTreeAsync,
expectLevelSolved: expectLevelSolved,
ONE_COMMIT_TREE: ONE_COMMIT_TREE
ONE_COMMIT_TREE: ONE_COMMIT_TREE,
runCommand: runCommand
};

View file

@ -1,5 +1,6 @@
var base = require('./base');
var expectTreeAsync = base.expectTreeAsync;
var runCommand = base.runCommand;
describe('Git', function() {
it('Commits', function() {
@ -282,4 +283,104 @@ describe('Git', function() {
);
});
describe('RevList', function() {
it('requires at least 1 argument', function() {
runCommand('git rev-list', function(commandMsg) {
expect(commandMsg).toContain('at least 1');
});
});
describe('supports', function() {
var SETUP = 'git co -b left C0; gc; git merge master; git co -b right C0; gc; git merge master; git co -b all left; git merge right; ';
it('single included revision', function() {
runCommand(SETUP + 'git rev-list all', function(commandMsg) {
expect(commandMsg).toBe('C6\nC5\nC4\nC3\nC2\nC1\nC0\n');
});
});
it('single excluded revision', function() {
runCommand(SETUP + 'git rev-list all ^right', function(commandMsg) {
expect(commandMsg).toBe('C6\nC3\nC2\n');
});
});
it('multiple included revisions', function() {
runCommand(SETUP + 'git rev-list right left', function(commandMsg) {
expect(commandMsg).toBe('C5\nC4\nC3\nC2\nC1\nC0\n');
});
});
it('multiple excluded revisions', function() {
runCommand(SETUP + 'git rev-list all ^right ^left', function(commandMsg) {
expect(commandMsg).toBe('C6\n');
});
});
});
});
describe('Log supports', function() {
var SETUP = 'git co -b left C0; gc; git merge master; git co -b right C0; gc; git merge master; git co -b all left; git merge right; ';
it('implied HEAD', function() {
runCommand(SETUP + '; git co right; git log', function(commandMsg) {
expect(commandMsg).toContain('Commit: C0\n');
expect(commandMsg).toContain('Commit: C1\n');
expect(commandMsg).not.toContain('Commit: C2\n');
expect(commandMsg).not.toContain('Commit: C3\n');
expect(commandMsg).toContain('Commit: C4\n');
expect(commandMsg).toContain('Commit: C5\n');
expect(commandMsg).not.toContain('Commit: C6\n');
});
});
it('single included revision', function() {
runCommand(SETUP + 'git log right', function(commandMsg) {
expect(commandMsg).toContain('Commit: C0\n');
expect(commandMsg).toContain('Commit: C1\n');
expect(commandMsg).not.toContain('Commit: C2\n');
expect(commandMsg).not.toContain('Commit: C3\n');
expect(commandMsg).toContain('Commit: C4\n');
expect(commandMsg).toContain('Commit: C5\n');
expect(commandMsg).not.toContain('Commit: C6\n');
});
});
it('single excluded revision', function() {
runCommand(SETUP + 'git log all ^right', function(commandMsg) {
expect(commandMsg).not.toContain('Commit: C0\n');
expect(commandMsg).not.toContain('Commit: C1\n');
expect(commandMsg).toContain('Commit: C2\n');
expect(commandMsg).toContain('Commit: C3\n');
expect(commandMsg).not.toContain('Commit: C4\n');
expect(commandMsg).not.toContain('Commit: C5\n');
expect(commandMsg).toContain('Commit: C6\n');
});
});
it('multiple included revisions', function() {
runCommand(SETUP + 'git log right left', function(commandMsg) {
expect(commandMsg).toContain('Commit: C0\n');
expect(commandMsg).toContain('Commit: C1\n');
expect(commandMsg).toContain('Commit: C2\n');
expect(commandMsg).toContain('Commit: C3\n');
expect(commandMsg).toContain('Commit: C4\n');
expect(commandMsg).toContain('Commit: C5\n');
expect(commandMsg).not.toContain('Commit: C6\n');
});
});
it('multiple excluded revisions', function() {
runCommand(SETUP + 'git log all ^right ^left', function(commandMsg) {
expect(commandMsg).not.toContain('Commit: C0\n');
expect(commandMsg).not.toContain('Commit: C1\n');
expect(commandMsg).not.toContain('Commit: C2\n');
expect(commandMsg).not.toContain('Commit: C3\n');
expect(commandMsg).not.toContain('Commit: C4\n');
expect(commandMsg).not.toContain('Commit: C5\n');
expect(commandMsg).toContain('Commit: C6\n');
});
});
});
});