feat:new command stage all merge

This commit is contained in:
Pascal Fong Kye 2020-05-12 18:17:21 +02:00
parent a1ed386162
commit d2b5d323d0
3 changed files with 55 additions and 2 deletions

View file

@ -105,6 +105,12 @@
"category": "Git",
"icon": "$(add)"
},
{
"command": "git.stageAllMerge",
"title": "%command.stageAllMerge%",
"category": "Git",
"icon": "$(add)"
},
{
"command": "git.stageSelectedRanges",
"title": "%command.stageSelectedRanges%",
@ -490,6 +496,10 @@
"command": "git.stageAllUntracked",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
},
{
"command": "git.stageAllMerge",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
},
{
"command": "git.stageSelectedRanges",
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
@ -837,6 +847,11 @@
"group": "5_stage",
"when": "scmProvider == git"
},
{
"command": "git.stageAllMerge",
"group": "5_stage",
"when": "scmProvider == git"
},
{
"command": "git.unstageAll",
"group": "5_stage",
@ -897,12 +912,12 @@
],
"scm/resourceGroup/context": [
{
"command": "git.stageAll",
"command": "git.stageAllMerge",
"when": "scmProvider == git && scmResourceGroup == merge",
"group": "1_modification"
},
{
"command": "git.stageAll",
"command": "git.stageAllMerge",
"when": "scmProvider == git && scmResourceGroup == merge",
"group": "inline"
},

View file

@ -14,6 +14,7 @@
"command.stageAll": "Stage All Changes",
"command.stageAllTracked": "Stage All Tracked Changes",
"command.stageAllUntracked": "Stage All Untracked Changes",
"command.stageAllMerge": "Stage All Merge Changes",
"command.stageSelectedRanges": "Stage Selected Ranges",
"command.revertSelectedRanges": "Revert Selected Ranges",
"command.stageChange": "Stage Change",

View file

@ -1086,6 +1086,43 @@ export class CommandCenter {
await repository.add(uris);
}
@command('git.stageAllMerge', { repository: true })
async stageAllMerge(repository: Repository): Promise<void> {
const resources = repository.mergeGroup.resourceStates.filter(s => s instanceof Resource) as Resource[];
const { merge, unresolved, deletionConflicts } = await categorizeResourceByResolution(resources);
try {
for (const deletionConflict of deletionConflicts) {
await this._stageDeletionConflict(repository, deletionConflict.resourceUri);
}
} catch (err) {
if (/Cancelled/.test(err.message)) {
return;
}
throw err;
}
if (unresolved.length > 0) {
const message = unresolved.length > 1
? localize('confirm stage files with merge conflicts', "Are you sure you want to stage {0} files with merge conflicts?", merge.length)
: localize('confirm stage file with merge conflicts', "Are you sure you want to stage {0} with merge conflicts?", path.basename(merge[0].resourceUri.fsPath));
const yes = localize('yes', "Yes");
const pick = await window.showWarningMessage(message, { modal: true }, yes);
if (pick !== yes) {
return;
}
}
const uris = resources.map(r => r.resourceUri);
if (uris.length > 0) {
await repository.add(uris);
}
}
@command('git.stageChange')
async stageChange(uri: Uri, changes: LineChange[], index: number): Promise<void> {
const textEditor = window.visibleTextEditors.filter(e => e.document.uri.toString() === uri.toString())[0];