Skip to content

Commit 82bb557

Browse files
committed
#12 Add fast forward option to merge confirmation dialog
1 parent f0e5db1 commit 82bb557

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/dataSource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ export class DataSource {
192192
return this.runGitCommand('branch -m ' + escapeRefName(oldName) + ' ' + escapeRefName(newName));
193193
}
194194

195-
public mergeBranch(branchName: string) {
196-
return this.runGitCommand('merge ' + escapeRefName(branchName));
195+
public mergeBranch(branchName: string, createNewCommit: boolean) {
196+
return this.runGitCommand('merge ' + escapeRefName(branchName) + (createNewCommit ? ' --no-ff' : ''));
197197
}
198198

199199
public cherrypickCommit(commitHash: string, parentIndex: number) {

src/gitGraphView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class GitGraphView {
108108
case 'mergeBranch':
109109
this.sendMessage({
110110
command: 'mergeBranch',
111-
status: await this.dataSource.mergeBranch(msg.branchName)
111+
status: await this.dataSource.mergeBranch(msg.branchName, msg.createNewCommit)
112112
});
113113
return;
114114
case 'renameBranch':

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export interface ResponseLoadCommits {
174174
export interface RequestMergeBranch {
175175
command: 'mergeBranch';
176176
branchName: string;
177+
createNewCommit: boolean;
177178
}
178179
export interface ResponseMergeBranch {
179180
command: 'mergeBranch';

web/main.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@
581581
e.stopPropagation();
582582
let sourceElem = <HTMLElement>(<Element>e.target).closest('.gitRef')!;
583583
let refName = unescapeHtml(sourceElem.dataset.name!), menu;
584-
if (sourceElem.className === 'gitRef tag') {
584+
if (sourceElem.classList.contains('tag')) {
585585
menu = [{
586586
title: 'Delete Tag',
587587
onClick: () => {
@@ -594,17 +594,17 @@
594594
menu = [{
595595
title: 'Checkout Branch',
596596
onClick: () => {
597-
if (sourceElem.className === 'gitRef head') {
597+
if (sourceElem.classList.contains('head')) {
598598
sendMessage({ command: 'checkoutBranch', branchName: refName, remoteBranch: null });
599-
} else if (sourceElem.className === 'gitRef remote') {
599+
} else if (sourceElem.classList.contains('remote')) {
600600
let refNameComps = refName.split('/');
601601
showInputDialog('Enter the name of the new branch you would like to create when checking out <b><i>' + escapeHtml(sourceElem.dataset.name!) + '</i></b>:', refNameComps[refNameComps.length - 1], 'Checkout Branch', (newBranch) => {
602602
sendMessage({ command: 'checkoutBranch', branchName: newBranch, remoteBranch: refName });
603603
}, null);
604604
}
605605
}
606606
}];
607-
if (sourceElem.className === 'gitRef head') {
607+
if (sourceElem.classList.contains('head')) {
608608
menu.push(
609609
{
610610
title: 'Rename Branch',
@@ -616,7 +616,7 @@
616616
}, {
617617
title: 'Delete Branch',
618618
onClick: () => {
619-
showCheckboxDialog('Are you sure you want to delete the branch <b><i>' + escapeHtml(refName) + '</i></b>?', 'Force Delete', 'Delete Branch', (forceDelete) => {
619+
showCheckboxDialog('Are you sure you want to delete the branch <b><i>' + escapeHtml(refName) + '</i></b>?', 'Force Delete', false, 'Delete Branch', (forceDelete) => {
620620
sendMessage({ command: 'deleteBranch', branchName: refName, forceDelete: forceDelete });
621621
}, null);
622622
}
@@ -626,8 +626,8 @@
626626
menu.push({
627627
title: 'Merge into current branch',
628628
onClick: () => {
629-
showConfirmationDialog('Are you sure you want to merge branch <b><i>' + escapeHtml(refName) + '</i></b> into the current branch?', () => {
630-
sendMessage({ command: 'mergeBranch', branchName: refName });
629+
showCheckboxDialog('Are you sure you want to merge branch <b><i>' + escapeHtml(refName) + '</i></b> into the current branch?', 'Create a new commit even if fast-forward is possible', true, 'Yes, merge', (createNewCommit) => {
630+
sendMessage({ command: 'mergeBranch', branchName: refName, createNewCommit: createNewCommit });
631631
}, null);
632632
}
633633
});
@@ -992,8 +992,8 @@
992992
}
993993
});
994994
}
995-
function showCheckboxDialog(message: string, checkboxLabel: string, actionName: string, actioned: (value: boolean) => void, sourceElem: HTMLElement | null) {
996-
showDialog(message + '<br><label><input id="dialogInput" type="checkbox"/>' + checkboxLabel + '</label>', actionName, 'Cancel', () => {
995+
function showCheckboxDialog(message: string, checkboxLabel: string, checkboxValue: boolean, actionName: string, actioned: (value: boolean) => void, sourceElem: HTMLElement | null) {
996+
showDialog(message + '<br><label><input id="dialogInput" type="checkbox"' + (checkboxValue ? ' checked' : '') + '/>' + checkboxLabel + '</label>', actionName, 'Cancel', () => {
997997
let value = (<HTMLInputElement>document.getElementById('dialogInput')).checked;
998998
hideDialog();
999999
actioned(value);

0 commit comments

Comments
 (0)