Skip to content

Commit 16931b5

Browse files
committed
Merge pull request #32 from JakeGinnivan/NoFastForwardMerge
No fast forward merge
2 parents 5320480 + 1594d9f commit 16931b5

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

js/controlbox.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ define(['d3'], function () {
181181
this.historyView.deleteBranch(name);
182182
break;
183183
default:
184-
if (arg.charAt(0) == '-') {
184+
if (arg.charAt(0) === '-') {
185185
this.error();
186186
} else {
187187
var remainingArgs = [arg].concat(args);
@@ -279,8 +279,18 @@ define(['d3'], function () {
279279
},
280280

281281
merge: function (args) {
282+
var noFF = false;
283+
if (args.length === 2)
284+
{
285+
var mergeSwitch = args.pop();
286+
if (mergeSwitch === '--no-ff') {
287+
noFF = true;
288+
} else {
289+
this.info('This demo only supports the --no-ff switch..');
290+
}
291+
}
282292
var ref = args.shift(),
283-
result = this.historyView.merge(ref);
293+
result = this.historyView.merge(ref, noFF);
284294

285295
if (result === 'Fast-Forward') {
286296
this.info('You have performed a fast-forward merge.');

js/historyview.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ define(['d3'], function () {
9393

9494
branchIndex = branches.indexOf(commit.id);
9595

96+
if (commit.isNoFFBranch === true) {
97+
branchIndex++;
98+
}
99+
if (commit.isNoFFCommit === true) {
100+
branchIndex--;
101+
}
102+
96103
if (parentCY === baseLine) {
97104
var direction = 1;
98105
for (var bi = 0; bi < branchIndex; bi++) {
@@ -939,7 +946,7 @@ define(['d3'], function () {
939946
}
940947
},
941948

942-
merge: function (ref) {
949+
merge: function (ref, noFF) {
943950
var mergeTarget = this.getCommit(ref),
944951
currentCommit = this.getCommit('HEAD');
945952

@@ -951,6 +958,15 @@ define(['d3'], function () {
951958
throw new Error('Already up-to-date.');
952959
} else if (currentCommit.parent2 === mergeTarget.id) {
953960
throw new Error('Already up-to-date.');
961+
} else if (noFF === true) {
962+
var branchStartCommit = this.getCommit(mergeTarget.parent);
963+
while (branchStartCommit.parent !== currentCommit.id) {
964+
branchStartCommit = this.getCommit(branchStartCommit.parent);
965+
}
966+
967+
branchStartCommit.isNoFFBranch = true;
968+
969+
this.commit({parent2: mergeTarget.id, isNoFFCommit: true});
954970
} else if (this.isAncestor(currentCommit, mergeTarget)) {
955971
this.fastForward(mergeTarget);
956972
return 'Fast-Forward';

0 commit comments

Comments
 (0)