handle case when merge is a noop
This commit is contained in:
parent
462c3d3a6c
commit
2fecb4d945
|
@ -1,6 +1,7 @@
|
|||
var crypto = require("crypto");
|
||||
var Logger = require('../../logger');
|
||||
var log = new Logger.Log();
|
||||
//var log = new Logger.Log();
|
||||
var log = new Logger.Log(1);
|
||||
|
||||
|
||||
var commits = {};
|
||||
|
@ -30,6 +31,15 @@ function isfastforwardable(current, other) {
|
|||
log.debug(currentCommit.id, otherCommit.id);
|
||||
return currentCommit.id == otherCommit.id;
|
||||
}
|
||||
|
||||
function isReachableFrom(current, other) {
|
||||
var currentCommit = commits[branches[current]];
|
||||
var currentSeq = currentCommit.seq;
|
||||
var otherCommit = commits[branches[other]];
|
||||
var otherSeq = otherCommit.seq;
|
||||
if (currentSeq > otherSeq) return isfastforwardable(other, current);
|
||||
return false;
|
||||
}
|
||||
exports.setDirection = function(dir) {
|
||||
direction = dir;
|
||||
}
|
||||
|
@ -49,9 +59,13 @@ exports.branch = function(name) {
|
|||
log.debug("in createBranch");
|
||||
}
|
||||
|
||||
exports.merge = function(sourceBranch) {
|
||||
if (isfastforwardable(curBranch, sourceBranch)){
|
||||
branches[curBranch] = branches[sourceBranch];
|
||||
exports.merge = function(otherBranch) {
|
||||
if (isReachableFrom(curBranch, otherBranch)) {
|
||||
log.debug("Already merged");
|
||||
return;
|
||||
}
|
||||
if (isfastforwardable(curBranch, otherBranch)){
|
||||
branches[curBranch] = branches[otherBranch];
|
||||
head = commits[branches[curBranch]];
|
||||
}
|
||||
log.debug(branches);
|
||||
|
|
|
@ -114,4 +114,22 @@ describe('when parsing a gitGraph',function() {
|
|||
expect(parser.yy.getHead().id).toEqual(parser.yy.getBranches()["newbranch"]);
|
||||
});
|
||||
|
||||
it('it should handle cases when merge is a noop', function () {
|
||||
var str = 'gitGraph:\n' +
|
||||
'commit\n' +
|
||||
'branch newbranch\n' +
|
||||
'checkout newbranch\n' +
|
||||
'commit\n' +
|
||||
'commit\n' +
|
||||
'merge master\n';
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
var commits = parser.yy.getCommits();
|
||||
console.log(commits);
|
||||
expect(Object.keys(commits).length).toBe(3);
|
||||
expect(parser.yy.getCurrentBranch()).toBe("newbranch");
|
||||
expect(parser.yy.getBranches()["newbranch"]).not.toEqual(parser.yy.getBranches()["master"]);
|
||||
expect(parser.yy.getHead().id).toEqual(parser.yy.getBranches()["newbranch"]);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue