@@ -5,12 +5,12 @@ import { Command, CommandContext, Commands, isCommandViewContextWithCommit } fro
55import { GlyphChars } from '../constants' ;
66import { GitService , GitStashCommit } from '../gitService' ;
77import { Logger } from '../logger' ;
8- import { CommandQuickPickItem , CommitQuickPickItem , StashListQuickPick } from '../quickPicks' ;
8+ import { CommandQuickPickItem , RepositoriesQuickPick , StashListQuickPick } from '../quickPicks' ;
99
1010export interface StashApplyCommandArgs {
1111 confirm ?: boolean ;
1212 deleteAfter ?: boolean ;
13- stashItem ?: { stashName : string , message : string } ;
13+ stashItem ?: { stashName : string , message : string , repoPath : string } ;
1414
1515 goBackCommand ?: CommandQuickPickItem ;
1616}
@@ -26,28 +26,43 @@ export class StashApplyCommand extends Command {
2626 protected async preExecute ( context : CommandContext , args : StashApplyCommandArgs = { confirm : true , deleteAfter : false } ) {
2727 if ( isCommandViewContextWithCommit < GitStashCommit > ( context ) ) {
2828 args = { ...args } ;
29- args . stashItem = { stashName : context . node . commit . stashName , message : context . node . commit . message } ;
29+ args . stashItem = context . node . commit ;
3030 return this . execute ( args ) ;
3131 }
3232
3333 return this . execute ( args ) ;
3434 }
3535
3636 async execute ( args : StashApplyCommandArgs = { confirm : true , deleteAfter : false } ) {
37- if ( ! this . git . repoPath ) return undefined ;
38-
3937 args = { ...args } ;
4038 if ( args . stashItem === undefined || args . stashItem . stashName === undefined ) {
41- const stash = await this . git . getStashList ( this . git . repoPath ) ;
39+ let goBackToRepositoriesCommand : CommandQuickPickItem | undefined ;
40+
41+ let repoPath = await this . git . getActiveRepoPath ( ) ;
42+ if ( ! repoPath ) {
43+ const pick = await RepositoriesQuickPick . show ( this . git , `Apply stashed changes from which repository${ GlyphChars . Ellipsis } ` , args . goBackCommand ) ;
44+ if ( pick instanceof CommandQuickPickItem ) return pick . execute ( ) ;
45+ if ( pick === undefined ) return args . goBackCommand === undefined ? undefined : args . goBackCommand . execute ( ) ;
46+
47+ goBackToRepositoriesCommand = new CommandQuickPickItem ( {
48+ label : `go back ${ GlyphChars . ArrowBack } ` ,
49+ description : `${ Strings . pad ( GlyphChars . Dash , 2 , 3 ) } to pick another repository`
50+ } , Commands . StashApply , [ args ] ) ;
51+
52+ repoPath = pick . repoPath ;
53+ }
54+
55+ const stash = await this . git . getStashList ( repoPath ) ;
4256 if ( stash === undefined ) return window . showInformationMessage ( `There are no stashed changes` ) ;
4357
4458 const currentCommand = new CommandQuickPickItem ( {
4559 label : `go back ${ GlyphChars . ArrowBack } ` ,
4660 description : `${ Strings . pad ( GlyphChars . Dash , 2 , 3 ) } to apply stashed changes`
4761 } , Commands . StashApply , [ args ] ) ;
4862
49- const pick = await StashListQuickPick . show ( this . git , stash , 'apply' , args . goBackCommand , currentCommand ) ;
50- if ( pick === undefined || ! ( pick instanceof CommitQuickPickItem ) ) return args . goBackCommand === undefined ? undefined : args . goBackCommand . execute ( ) ;
63+ const pick = await StashListQuickPick . show ( this . git , stash , 'apply' , goBackToRepositoriesCommand || args . goBackCommand , currentCommand ) ;
64+ if ( pick instanceof CommandQuickPickItem ) return pick . execute ( ) ;
65+ if ( pick === undefined ) return args . goBackCommand === undefined ? undefined : args . goBackCommand . execute ( ) ;
5166
5267 args . goBackCommand = currentCommand ;
5368 args . stashItem = pick . commit as GitStashCommit ;
@@ -62,7 +77,7 @@ export class StashApplyCommand extends Command {
6277 args . deleteAfter = result . title !== 'Yes' ;
6378 }
6479
65- return await this . git . stashApply ( this . git . repoPath , args . stashItem . stashName , args . deleteAfter ) ;
80+ return await this . git . stashApply ( args . stashItem . repoPath , args . stashItem . stashName , args . deleteAfter ) ;
6681 }
6782 catch ( ex ) {
6883 Logger . error ( ex , 'StashApplyCommand' ) ;
0 commit comments