Adds Apply Changes command to custom view files

Adds Stash Changes command to SCM view items
This commit is contained in:
Eric Amodio
2017-09-03 12:58:05 -04:00
parent 35b16a78ba
commit d31eb25451
5 changed files with 1212 additions and 1137 deletions

View File

@@ -1,6 +1,7 @@
'use strict';
import { InputBoxOptions, window } from 'vscode';
import { InputBoxOptions, Uri, window } from 'vscode';
import { GitService } from '../gitService';
import { CommandContext } from '../commands';
import { Command, Commands } from './common';
import { Logger } from '../logger';
import { CommandQuickPickItem } from '../quickPicks';
@@ -8,6 +9,7 @@ import { CommandQuickPickItem } from '../quickPicks';
export interface StashSaveCommandArgs {
message?: string;
unstagedOnly?: boolean;
uris?: Uri[];
goBackCommand?: CommandQuickPickItem;
}
@@ -18,6 +20,22 @@ export class StashSaveCommand extends Command {
super(Commands.StashSave);
}
protected async preExecute(context: CommandContext, args: StashSaveCommandArgs = {}): Promise<any> {
if (context.type === 'scm-states') {
args = { ...args };
args.uris = context.scmResourceStates.map(s => s.resourceUri);
return this.execute(args);
}
if (context.type === 'scm-groups') {
args = { ...args };
args.uris = context.scmResourceGroups.reduce<Uri[]>((a, b) => a.concat(b.resourceStates.map(s => s.resourceUri)), []);
return this.execute(args);
}
return this.execute(args);
}
async execute(args: StashSaveCommandArgs = { unstagedOnly: false }) {
if (!this.git.repoPath) return undefined;
@@ -35,7 +53,7 @@ export class StashSaveCommand extends Command {
if (args.message === undefined) return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute();
}
return await this.git.stashSave(this.git.repoPath, args.message, args.unstagedOnly);
return await this.git.stashSave(this.git.repoPath, args.message, args.uris);
}
catch (ex) {
Logger.error(ex, 'StashSaveCommand');