Add support for Stash (Include Untracked)

This commit is contained in:
Raoul D'Cunha 2017-09-20 17:06:52 +12:00
parent f7962f0682
commit 21aac84936
5 changed files with 41 additions and 7 deletions

View file

@ -256,6 +256,11 @@
"title": "%command.ignore%",
"category": "Git"
},
{
"command": "git.stashIncludeUntracked",
"title": "%command.stashIncludeUntracked%",
"category": "Git"
},
{
"command": "git.stash",
"title": "%command.stash%",
@ -544,6 +549,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",

View file

@ -38,6 +38,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",

View file

@ -1236,6 +1236,21 @@ export class CommandCenter {
await repository.ignore(uris);
}
@command('git.stashIncludeUntracked', { repository: true })
async stashIncludeUntracked(repository: Repository): Promise<void> {
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<void> {
if (repository.workingTreeGroup.resourceStates.length === 0) {
@ -1243,10 +1258,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;
@ -1255,6 +1267,13 @@ export class CommandCenter {
await repository.createStash(message);
}
private async getStashMessage(): Promise<string | undefined> {
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<void> {
const stashes = await repository.getStashes();

View file

@ -842,10 +842,14 @@ export class Repository {
}
}
async createStash(message?: string): Promise<void> {
async createStash(message?: string, includeUntracked?: boolean): Promise<void> {
try {
const args = ['stash', 'save'];
if (includeUntracked) {
args.push('-u');
}
if (message) {
args.push('--', message);
}

View file

@ -593,8 +593,8 @@ export class Repository implements Disposable {
return await this.repository.getStashes();
}
async createStash(message?: string): Promise<void> {
return await this.run(Operation.Stash, () => this.repository.createStash(message));
async createStash(message?: string, includeUntracked?: boolean): Promise<void> {
return await this.run(Operation.Stash, () => this.repository.createStash(message, includeUntracked));
}
async popStash(index?: number): Promise<void> {