Skip to content

Commit

Permalink
Merge pull request onlywei#32 from JakeGinnivan/NoFastForwardMerge
Browse files Browse the repository at this point in the history
No fast forward merge
  • Loading branch information
onlywei committed Mar 30, 2015
2 parents 5320480 + 1594d9f commit 16931b5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
14 changes: 12 additions & 2 deletions js/controlbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ define(['d3'], function () {
this.historyView.deleteBranch(name);
break;
default:
if (arg.charAt(0) == '-') {
if (arg.charAt(0) === '-') {
this.error();
} else {
var remainingArgs = [arg].concat(args);
Expand Down Expand Up @@ -279,8 +279,18 @@ define(['d3'], function () {
},

merge: function (args) {
var noFF = false;
if (args.length === 2)
{
var mergeSwitch = args.pop();
if (mergeSwitch === '--no-ff') {
noFF = true;
} else {
this.info('This demo only supports the --no-ff switch..');
}
}
var ref = args.shift(),
result = this.historyView.merge(ref);
result = this.historyView.merge(ref, noFF);

if (result === 'Fast-Forward') {
this.info('You have performed a fast-forward merge.');
Expand Down
18 changes: 17 additions & 1 deletion js/historyview.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ define(['d3'], function () {

branchIndex = branches.indexOf(commit.id);

if (commit.isNoFFBranch === true) {
branchIndex++;
}
if (commit.isNoFFCommit === true) {
branchIndex--;
}

if (parentCY === baseLine) {
var direction = 1;
for (var bi = 0; bi < branchIndex; bi++) {
Expand Down Expand Up @@ -939,7 +946,7 @@ define(['d3'], function () {
}
},

merge: function (ref) {
merge: function (ref, noFF) {
var mergeTarget = this.getCommit(ref),
currentCommit = this.getCommit('HEAD');

Expand All @@ -951,6 +958,15 @@ define(['d3'], function () {
throw new Error('Already up-to-date.');
} else if (currentCommit.parent2 === mergeTarget.id) {
throw new Error('Already up-to-date.');
} else if (noFF === true) {
var branchStartCommit = this.getCommit(mergeTarget.parent);
while (branchStartCommit.parent !== currentCommit.id) {
branchStartCommit = this.getCommit(branchStartCommit.parent);
}

branchStartCommit.isNoFFBranch = true;

this.commit({parent2: mergeTarget.id, isNoFFCommit: true});
} else if (this.isAncestor(currentCommit, mergeTarget)) {
this.fastForward(mergeTarget);
return 'Fast-Forward';
Expand Down

0 comments on commit 16931b5

Please sign in to comment.