diff --git a/extensions/git/package.json b/extensions/git/package.json index da96c49e3a7..f5608879a1b 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -501,6 +501,11 @@ "title": "%command.stashDrop%", "category": "Git" }, + { + "command": "git.stashDropAll", + "title": "%command.stashDropAll%", + "category": "Git" + }, { "command": "git.timeline.openDiff", "title": "%command.timelineOpenDiff%", @@ -914,6 +919,10 @@ "command": "git.stashDrop", "when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0" }, + { + "command": "git.stashDropAll", + "when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0" + }, { "command": "git.timeline.openDiff", "when": "false" @@ -1651,6 +1660,10 @@ { "command": "git.stashDrop", "group": "stash@7" + }, + { + "command": "git.stashDropAll", + "group": "stash@8" } ], "git.tags": [ diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 481b1cb09c0..7d94943f947 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -87,6 +87,7 @@ "command.stashApply": "Apply Stash...", "command.stashApplyLatest": "Apply Latest Stash", "command.stashDrop": "Drop Stash...", + "command.stashDropAll": "Drop All Stashes...", "command.timelineOpenDiff": "Open Changes", "command.timelineCopyCommitId": "Copy Commit ID", "command.timelineCopyCommitMessage": "Copy Commit Message", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 3629e2d89cf..458a31fcb35 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -2604,6 +2604,29 @@ export class CommandCenter { await repository.dropStash(stash.index); } + @command('git.stashDropAll', { repository: true }) + async stashDropAll(repository: Repository): Promise { + const stashes = await repository.getStashes(); + + if (stashes.length === 0) { + window.showInformationMessage(localize('no stashes', "There are no stashes in the repository.")); + return; + } + + // request confirmation for the operation + const yes = localize('yes', "Yes"); + const question = stashes.length === 1 ? + localize('drop one stash', "Are you sure you want to drop ALL stashes? There is 1 stash that will be subject to pruning, and MAY BE IMPOSSIBLE TO RECOVER.") : + localize('drop all stashes', "Are you sure you want to drop ALL stashes? There are {0} stashes that will be subject to pruning, and MAY BE IMPOSSIBLE TO RECOVER.", stashes.length); + + const result = await window.showWarningMessage(question, yes); + if (result !== yes) { + return; + } + + await repository.dropStash(); + } + private async pickStash(repository: Repository, placeHolder: string): Promise { const stashes = await repository.getStashes(); diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index eb546c026a0..b3b7f1c68de 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -1794,10 +1794,13 @@ export class Repository { } async dropStash(index?: number): Promise { - const args = ['stash', 'drop']; + const args = ['stash']; if (typeof index === 'number') { + args.push('drop'); args.push(`stash@{${index}}`); + } else { + args.push('clear'); } try {