diff --git a/extensions/git/package.json b/extensions/git/package.json index efc3449df2933e11cd0acc63523c69c0bd194610..f082cd1078ee15fcfa0693c5159b20b7a7aeffbb 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -401,6 +401,11 @@ "command": "git.stashApplyLatest", "title": "%command.stashApplyLatest%", "category": "Git" + }, + { + "command": "git.stashDrop", + "title": "%command.stashDrop%", + "category": "Git" } ], "menus": { @@ -660,6 +665,10 @@ { "command": "git.stashApplyLatest", "when": "config.git.enabled && gitOpenRepositoryCount != 0" + }, + { + "command": "git.stashDrop", + "when": "config.get.enabled && gitOpenRepositoryCount != 0" } ], "scm/title": [ @@ -813,6 +822,11 @@ "group": "6_stash", "when": "scmProvider == git" }, + { + "command": "git.stashDrop", + "group": "6_stash", + "when": "scmProvider == git" + }, { "command": "git.showOutput", "group": "7_repository", diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 58ffebc967ec220e5710c488ed0646c7b19e3d66..b4afd65ec2da49667648292cba355b93af949e6f 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -64,6 +64,7 @@ "command.stashPopLatest": "Pop Latest Stash", "command.stashApply": "Apply Stash...", "command.stashApplyLatest": "Apply Latest Stash", + "command.stashDrop": "Drop Stash...", "config.enabled": "Whether git is enabled.", "config.path": "Path and filename of the git executable, e.g. `C:\\Program Files\\Git\\bin\\git.exe` (Windows).", "config.autoRepositoryDetection": "Configures when repositories should be automatically detected.", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 93932ab02edad6ac6e57f23f8d8f5944436bdd47..5bc5ab75a7cd00129dc903209aad458fc53ce061 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -2241,6 +2241,18 @@ export class CommandCenter { await repository.applyStash(); } + @command('git.stashDrop', { repository: true }) + async stashDrop(repository: Repository): Promise { + const placeHolder = localize('pick stash to drop', "Pick a stash to drop"); + const stash = await this.pickStash(repository, placeHolder); + + if (!stash) { + return; + } + + await repository.dropStash(stash.index); + } + 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 24fe7964c148927a2547e613f0677a6870f028d7..bfd64db7622e27e84937bc89006045cdb25f99fd 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -1597,6 +1597,24 @@ export class Repository { } } + async dropStash(index: number): Promise { + const args = ['stash', 'drop']; + + if (typeof index === 'number') { + args.push(`stash@{${index}}`); + + try { + await this.run(args); + } + } catch (err) { + if (/No stash found/.test(err.stderr || '')) { + err.gitErrorCode = GitErrorCodes.NoStashFound; + } + + throw err; + } + } + getStatus(limit = 5000): Promise<{ status: IFileStatus[]; didHitLimit: boolean; }> { return new Promise<{ status: IFileStatus[]; didHitLimit: boolean; }>((c, e) => { const parser = new GitStatusParser(); diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index f7ed10fd34d5eeb845cbbff19044cf82f120d0a0..82ca6fe0fd4169948ee958bd84543f76816b0d2f 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -1254,6 +1254,10 @@ export class Repository implements Disposable { return await this.run(Operation.Stash, () => this.repository.popStash(index)); } + async dropStash(index?: number): Promise { + return await this.run(Operation.Stash, () => this.repository.dropStash(index)); + } + async applyStash(index?: number): Promise { return await this.run(Operation.Stash, () => this.repository.applyStash(index)); }