diff --git a/package.json b/package.json index 09224c9..f5ea35e 100644 --- a/package.json +++ b/package.json @@ -3245,6 +3245,12 @@ "when": "viewItem =~ /gitlens:file\\b.*:staged\\b/", "group": "1_gitlens@1" }, + { + "command": "gitlens.stashSave", + "when": "viewItem =~ /gitlens:file\\b.*:(un)?staged\\b/", + "group": "1_gitlens@2" + }, + { "command": "gitlens.explorers.openChanges", "when": "viewItem =~ /gitlens:file\\b/", "group": "2_gitlens@1" diff --git a/src/commands/stashApply.ts b/src/commands/stashApply.ts index bda0f77..5b468d8 100644 --- a/src/commands/stashApply.ts +++ b/src/commands/stashApply.ts @@ -5,9 +5,9 @@ import { Container } from '../container'; import { GitStashCommit } from '../git/gitService'; import { Logger } from '../logger'; import { Messages } from '../messages'; -import { CommandQuickPickItem, RepositoriesQuickPick, StashListQuickPick } from '../quickpicks'; +import { CommandQuickPickItem, StashListQuickPick } from '../quickpicks'; import { Strings } from '../system'; -import { Command, CommandContext, Commands, isCommandViewContextWithCommit } from './common'; +import { Command, CommandContext, Commands, getRepoPathOrPrompt, isCommandViewContextWithCommit } from './common'; export interface StashApplyCommandArgs { confirm?: boolean; @@ -39,30 +39,12 @@ export class StashApplyCommand extends Command { args = { ...args }; if (args.stashItem === undefined || args.stashItem.stashName === undefined) { - let goBackToRepositoriesCommand: CommandQuickPickItem | undefined; - - let repoPath = await Container.git.getActiveRepoPath(); - if (!repoPath) { - const pick = await RepositoriesQuickPick.show( - `Apply stashed changes from which repository${GlyphChars.Ellipsis}`, - args.goBackCommand - ); - if (pick instanceof CommandQuickPickItem) return pick.execute(); - if (pick === undefined) { - return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute(); - } - - goBackToRepositoriesCommand = new CommandQuickPickItem( - { - label: `go back ${GlyphChars.ArrowBack}`, - description: `${Strings.pad(GlyphChars.Dash, 2, 3)} to pick another repository` - }, - Commands.StashApply, - [args] - ); - - repoPath = pick.repoPath; - } + const repoPath = await getRepoPathOrPrompt( + undefined, + `Apply stashed changes from which repository${GlyphChars.Ellipsis}`, + args.goBackCommand + ); + if (!repoPath) return undefined; const progressCancellation = StashListQuickPick.showProgress('apply'); @@ -85,7 +67,7 @@ export class StashApplyCommand extends Command { stash, 'apply', progressCancellation, - goBackToRepositoriesCommand || args.goBackCommand, + args.goBackCommand, currentCommand ); if (pick instanceof CommandQuickPickItem) return pick.execute(); diff --git a/src/commands/stashSave.ts b/src/commands/stashSave.ts index e0b2340..3fb126b 100644 --- a/src/commands/stashSave.ts +++ b/src/commands/stashSave.ts @@ -2,10 +2,12 @@ import { InputBoxOptions, Uri, window } from 'vscode'; import { GlyphChars } from '../constants'; import { Container } from '../container'; +import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; import { Messages } from '../messages'; -import { CommandQuickPickItem, RepositoriesQuickPick } from '../quickpicks'; -import { Command, CommandContext, Commands } from './common'; +import { CommandQuickPickItem } from '../quickpicks'; +import { StatusFileNode } from '../views/nodes'; +import { Command, CommandContext, Commands, getRepoPathOrPrompt } from './common'; export interface StashSaveCommandArgs { message?: string; @@ -20,36 +22,35 @@ export class StashSaveCommand extends Command { } protected async preExecute(context: CommandContext, args: StashSaveCommandArgs = {}): Promise { - if (context.type === 'scm-states') { + if (context.type === 'view') { + args = { ...args }; + if (context.node instanceof StatusFileNode) { + args.uris = [GitUri.fromFile(context.node.file, context.node.repoPath)]; + } + } + else if (context.type === 'scm-states') { args = { ...args }; args.uris = context.scmResourceStates.map(s => s.resourceUri); - return this.execute(args); } - - if (context.type === 'scm-groups') { + else if (context.type === 'scm-groups') { args = { ...args }; args.uris = context.scmResourceGroups.reduce( (a, b) => a.concat(b.resourceStates.map(s => s.resourceUri)), [] ); - return this.execute(args); } return this.execute(args); } async execute(args: StashSaveCommandArgs = {}) { - let repoPath = await Container.git.getHighlanderRepoPath(); - if (!repoPath) { - const pick = await RepositoriesQuickPick.show( - `Stash changes for which repository${GlyphChars.Ellipsis}`, - args.goBackCommand - ); - if (pick instanceof CommandQuickPickItem) return pick.execute(); - if (pick === undefined) return args.goBackCommand === undefined ? undefined : args.goBackCommand.execute(); - - repoPath = pick.repoPath; - } + const uri = args.uris !== undefined && args.uris.length !== 0 ? args.uris[0] : undefined; + const repoPath = await getRepoPathOrPrompt( + uri, + `Stash changes for which repository${GlyphChars.Ellipsis}`, + args.goBackCommand + ); + if (!repoPath) return undefined; try { if (args.message == null) { diff --git a/src/git/git.ts b/src/git/git.ts index 0e5969e..84cd1dd 100644 --- a/src/git/git.ts +++ b/src/git/git.ts @@ -745,8 +745,7 @@ export class Git { if (message) { params.push('-m', message); } - params.splice(params.length, 0, '--', ...pathspecs); - return git({ cwd: repoPath }, ...params); + return git({ cwd: repoPath }, ...params, '--', ...pathspecs); } static stash_save(repoPath: string, message?: string) {