Skip to content

Commit d2b5d32

Browse files
author
Pascal Fong Kye
committed
feat:new command stage all merge
1 parent a1ed386 commit d2b5d32

3 files changed

Lines changed: 55 additions & 2 deletions

File tree

extensions/git/package.json

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
"category": "Git",
106106
"icon": "$(add)"
107107
},
108+
{
109+
"command": "git.stageAllMerge",
110+
"title": "%command.stageAllMerge%",
111+
"category": "Git",
112+
"icon": "$(add)"
113+
},
108114
{
109115
"command": "git.stageSelectedRanges",
110116
"title": "%command.stageSelectedRanges%",
@@ -490,6 +496,10 @@
490496
"command": "git.stageAllUntracked",
491497
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
492498
},
499+
{
500+
"command": "git.stageAllMerge",
501+
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
502+
},
493503
{
494504
"command": "git.stageSelectedRanges",
495505
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
@@ -837,6 +847,11 @@
837847
"group": "5_stage",
838848
"when": "scmProvider == git"
839849
},
850+
{
851+
"command": "git.stageAllMerge",
852+
"group": "5_stage",
853+
"when": "scmProvider == git"
854+
},
840855
{
841856
"command": "git.unstageAll",
842857
"group": "5_stage",
@@ -897,12 +912,12 @@
897912
],
898913
"scm/resourceGroup/context": [
899914
{
900-
"command": "git.stageAll",
915+
"command": "git.stageAllMerge",
901916
"when": "scmProvider == git && scmResourceGroup == merge",
902917
"group": "1_modification"
903918
},
904919
{
905-
"command": "git.stageAll",
920+
"command": "git.stageAllMerge",
906921
"when": "scmProvider == git && scmResourceGroup == merge",
907922
"group": "inline"
908923
},

extensions/git/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"command.stageAll": "Stage All Changes",
1515
"command.stageAllTracked": "Stage All Tracked Changes",
1616
"command.stageAllUntracked": "Stage All Untracked Changes",
17+
"command.stageAllMerge": "Stage All Merge Changes",
1718
"command.stageSelectedRanges": "Stage Selected Ranges",
1819
"command.revertSelectedRanges": "Revert Selected Ranges",
1920
"command.stageChange": "Stage Change",

extensions/git/src/commands.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,43 @@ export class CommandCenter {
10861086
await repository.add(uris);
10871087
}
10881088

1089+
@command('git.stageAllMerge', { repository: true })
1090+
async stageAllMerge(repository: Repository): Promise<void> {
1091+
const resources = repository.mergeGroup.resourceStates.filter(s => s instanceof Resource) as Resource[];
1092+
const { merge, unresolved, deletionConflicts } = await categorizeResourceByResolution(resources);
1093+
1094+
try {
1095+
for (const deletionConflict of deletionConflicts) {
1096+
await this._stageDeletionConflict(repository, deletionConflict.resourceUri);
1097+
}
1098+
} catch (err) {
1099+
if (/Cancelled/.test(err.message)) {
1100+
return;
1101+
}
1102+
1103+
throw err;
1104+
}
1105+
1106+
if (unresolved.length > 0) {
1107+
const message = unresolved.length > 1
1108+
? localize('confirm stage files with merge conflicts', "Are you sure you want to stage {0} files with merge conflicts?", merge.length)
1109+
: localize('confirm stage file with merge conflicts', "Are you sure you want to stage {0} with merge conflicts?", path.basename(merge[0].resourceUri.fsPath));
1110+
1111+
const yes = localize('yes', "Yes");
1112+
const pick = await window.showWarningMessage(message, { modal: true }, yes);
1113+
1114+
if (pick !== yes) {
1115+
return;
1116+
}
1117+
}
1118+
1119+
const uris = resources.map(r => r.resourceUri);
1120+
1121+
if (uris.length > 0) {
1122+
await repository.add(uris);
1123+
}
1124+
}
1125+
10891126
@command('git.stageChange')
10901127
async stageChange(uri: Uri, changes: LineChange[], index: number): Promise<void> {
10911128
const textEditor = window.visibleTextEditors.filter(e => e.document.uri.toString() === uri.toString())[0];

0 commit comments

Comments
 (0)