@@ -53,35 +53,14 @@ export class ExplainWipCommand extends GlCommandBase {
5353 async execute ( editor ?: TextEditor , uri ?: Uri , args ?: ExplainWipCommandArgs ) : Promise < void > {
5454 args = { ...args } ;
5555
56- let repository ;
57- if ( args ?. repoPath != null ) {
58- if ( args . worktreePath ) {
59- // TODO use await this.container.git.diff(args.worktreePath) instead, this will be more performant
60- repository = await this . container . git . getOrOpenRepository ( args . worktreePath , { closeOnOpen : true } ) ;
61- } else {
62- repository = this . container . git . getRepository ( args . repoPath ) ;
63- }
64- } else {
65- uri = getCommandUri ( uri , editor ) ;
66- const gitUri = uri != null ? await GitUri . fromUri ( uri ) : undefined ;
67- repository = await getBestRepositoryOrShowPicker (
68- gitUri ,
69- editor ,
70- 'Explain Working Changes' ,
71- 'Choose which repository to explain working changes from' ,
72- ) ;
56+ // Get the diff of working changes
57+ const diffService = await this . getDiff ( editor , uri , args ) ;
58+ if ( diffService ?. getDiff === undefined ) {
59+ void showGenericErrorMessage ( 'Unable to get diff service' ) ;
60+ return ;
7361 }
7462
75- if ( repository == null ) return ;
76-
7763 try {
78- // Get the diff of working changes
79- const diffService = repository . git . diff ( ) ;
80- if ( diffService ?. getDiff === undefined ) {
81- void showGenericErrorMessage ( 'Unable to get diff service' ) ;
82- return ;
83- }
84-
8564 // If args?.staged is undefined, should we get all changes (staged and unstaged)?
8665 let stagedLabel ;
8766 let to ;
@@ -105,7 +84,7 @@ export class ExplainWipCommand extends GlCommandBase {
10584
10685 if ( args ?. worktreePath ) {
10786 // Get the worktree name if available
108- const worktrees = await repository . git . worktrees ( ) ?. getWorktrees ( ) ;
87+ const worktrees = await this . container . git . worktrees ( args . worktreePath ) ?. getWorktrees ( ) ;
10988 const worktree = worktrees ?. find ( w => w . path === args . worktreePath ) ;
11089
11190 if ( worktree ) {
@@ -150,4 +129,26 @@ export class ExplainWipCommand extends GlCommandBase {
150129 void showGenericErrorMessage ( 'Unable to explain working changes' ) ;
151130 }
152131 }
132+
133+ private async getDiff ( editor ?: TextEditor , uri ?: Uri , args ?: ExplainWipCommandArgs ) {
134+ let diffService ;
135+ if ( args ?. worktreePath ) {
136+ diffService = this . container . git . diff ( args . worktreePath ) ;
137+ } else if ( args ?. repoPath ) {
138+ diffService = this . container . git . diff ( args . repoPath ) ;
139+ } else {
140+ uri = getCommandUri ( uri , editor ) ;
141+ const gitUri = uri != null ? await GitUri . fromUri ( uri ) : undefined ;
142+ const repository = await getBestRepositoryOrShowPicker (
143+ gitUri ,
144+ editor ,
145+ 'Explain Working Changes' ,
146+ 'Choose which repository to explain working changes from' ,
147+ ) ;
148+
149+ diffService = repository ?. git . diff ( ) ;
150+ }
151+
152+ return diffService ;
153+ }
153154}
0 commit comments