diff --git a/extensions/git/package.json b/extensions/git/package.json index 8df645db341..0e6d3d3ebcd 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -289,6 +289,11 @@ "title": "%command.ignore%", "category": "Git" }, + { + "command": "git.stashIncludeUntracked", + "title": "%command.stashIncludeUntracked%", + "category": "Git" + }, { "command": "git.stash", "title": "%command.stash%", @@ -598,6 +603,11 @@ "group": "4_stage", "when": "config.git.enabled && scmProvider == git" }, + { + "command": "git.stashIncludeUntracked", + "group": "5_stash", + "when": "config.git.enabled && scmProvider == git" + }, { "command": "git.stash", "group": "5_stash", diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 86f45c9f3d5..fee56d9e05e 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -42,6 +42,7 @@ "command.publish": "Publish Branch", "command.showOutput": "Show Git Output", "command.ignore": "Add File to .gitignore", + "command.stashIncludeUntracked": "Stash (Include Untracked)", "command.stash": "Stash", "command.stashPop": "Pop Stash...", "command.stashPopLatest": "Pop Latest Stash", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 475b4d25f3c..bccd75f91e5 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1432,6 +1432,21 @@ export class CommandCenter { await this.runByRepository(resources, async (repository, resources) => repository.ignore(resources)); } + @command('git.stashIncludeUntracked', { repository: true }) + async stashIncludeUntracked(repository: Repository): Promise { + if (repository.workingTreeGroup.resourceStates.length === 0) { + window.showInformationMessage(localize('no changes stash', "There are no changes to stash.")); + return; + } + + const message = await this.getStashMessage(); + + if (typeof message === 'undefined') { + return; + } + await repository.createStash(message, true); + } + @command('git.stash', { repository: true }) async stash(repository: Repository): Promise { if (repository.workingTreeGroup.resourceStates.length === 0) { @@ -1439,10 +1454,7 @@ export class CommandCenter { return; } - const message = await window.showInputBox({ - prompt: localize('provide stash message', "Optionally provide a stash message"), - placeHolder: localize('stash message', "Stash message") - }); + const message = await this.getStashMessage(); if (typeof message === 'undefined') { return; @@ -1451,6 +1463,13 @@ export class CommandCenter { await repository.createStash(message); } + private async getStashMessage(): Promise { + return await window.showInputBox({ + prompt: localize('provide stash message', "Optionally provide a stash message"), + placeHolder: localize('stash message', "Stash message") + }); + } + @command('git.stashPop', { repository: true }) async stashPop(repository: Repository): Promise { const stashes = await repository.getStashes(); diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 2a3dd05d9e6..6d38fd4b7ed 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -947,10 +947,14 @@ export class Repository { } } - async createStash(message?: string): Promise { + async createStash(message?: string, includeUntracked?: boolean): Promise { try { const args = ['stash', 'save']; + if (includeUntracked) { + args.push('-u'); + } + if (message) { args.push('--', message); } diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 15735e90b9d..5c98023431c 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -716,8 +716,8 @@ export class Repository implements Disposable { return await this.repository.getStashes(); } - async createStash(message?: string): Promise { - return await this.run(Operation.Stash, () => this.repository.createStash(message)); + async createStash(message?: string, includeUntracked?: boolean): Promise { + return await this.run(Operation.Stash, () => this.repository.createStash(message, includeUntracked)); } async popStash(index?: number): Promise {