@@ -44,7 +44,7 @@ export class GitTerminalLinkProvider implements Disposable, TerminalLinkProvider
4444 async provideTerminalLinks ( context : TerminalLinkContext , token : CancellationToken ) : Promise < GitTerminalLink [ ] > {
4545 if ( context . line . trim ( ) . length === 0 ) return [ ] ;
4646
47- const repoPath = this . container . git . highlander ?. path ;
47+ const repoPath = await this . getTerminalRepositoryPath ( context ) ;
4848 if ( ! repoPath ) return [ ] ;
4949
5050 const showDetailsView = configuration . get ( 'terminalLinks.showDetailsView' ) ;
@@ -100,6 +100,25 @@ export class GitTerminalLinkProvider implements Disposable, TerminalLinkProvider
100100 continue ;
101101 }
102102
103+ if ( shaRegex . test ( ref ) ) {
104+ const link : GitTerminalLink < ShowQuickCommitCommandArgs | InspectCommandArgs > = {
105+ startIndex : match . index ,
106+ length : ref . length ,
107+ tooltip : 'Show Commit' ,
108+ command : showDetailsView
109+ ? createTerminalLinkCommand < InspectCommandArgs > ( 'gitlens.showInDetailsView' , {
110+ ref : createReference ( ref , repoPath , { refType : 'revision' } ) ,
111+ } )
112+ : createTerminalLinkCommand < ShowQuickCommitCommandArgs > ( 'gitlens.showQuickCommitDetails' , {
113+ repoPath : repoPath ,
114+ sha : ref ,
115+ } ) ,
116+ } ;
117+ links . push ( link ) ;
118+
119+ continue ;
120+ }
121+
103122 const svc = this . container . git . getRepositoryService ( repoPath ) ;
104123 // TODO@eamodio handle paging
105124 branchResults ??= await svc . branches . getBranches ( undefined , toAbortSignal ( token ) ) . catch ( ( ) => undefined ) ;
@@ -142,47 +161,41 @@ export class GitTerminalLinkProvider implements Disposable, TerminalLinkProvider
142161 continue ;
143162 }
144163
145- if ( ! shaRegex . test ( ref ) ) {
146- if ( rangeRegex . test ( ref ) ) {
147- const link : GitTerminalLink < GitWizardCommandArgs > = {
148- startIndex : match . index ,
149- length : ref . length ,
150- tooltip : 'Show Commits' ,
151- command : createTerminalLinkCommand < GitWizardCommandArgs > ( 'gitlens.gitCommands' , {
152- command : 'log' ,
153- state : {
154- repo : repoPath ,
155- reference : createReference ( ref , repoPath , { refType : 'revision' } ) ,
156- } ,
157- } ) ,
158- } ;
159- links . push ( link ) ;
160- }
161-
162- continue ;
163- }
164-
165- if ( await svc . refs . isValidReference ( ref , undefined , toAbortSignal ( token ) ) . catch ( ( ) => false ) ) {
166- const link : GitTerminalLink < ShowQuickCommitCommandArgs | InspectCommandArgs > = {
164+ if ( rangeRegex . test ( ref ) ) {
165+ const link : GitTerminalLink < GitWizardCommandArgs > = {
167166 startIndex : match . index ,
168167 length : ref . length ,
169- tooltip : 'Show Commit' ,
170- command : showDetailsView
171- ? createTerminalLinkCommand < InspectCommandArgs > ( 'gitlens.showInDetailsView' , {
172- ref : createReference ( ref , repoPath , { refType : 'revision' } ) ,
173- } )
174- : createTerminalLinkCommand < ShowQuickCommitCommandArgs > ( 'gitlens.showQuickCommitDetails' , {
175- repoPath : repoPath ,
176- sha : ref ,
177- } ) ,
168+ tooltip : 'Show Commits' ,
169+ command : createTerminalLinkCommand < GitWizardCommandArgs > ( 'gitlens.gitCommands' , {
170+ command : 'log' ,
171+ state : {
172+ repo : repoPath ,
173+ reference : createReference ( ref , repoPath , { refType : 'revision' } ) ,
174+ } ,
175+ } ) ,
178176 } ;
179177 links . push ( link ) ;
180178 }
179+
180+ continue ;
181181 } while ( true ) ;
182182
183183 return links ;
184184 }
185185
186+ private async getTerminalRepositoryPath ( context : TerminalLinkContext ) : Promise < string | undefined > {
187+ const repo = this . container . git . highlander ;
188+ if ( repo != null ) return repo . path ;
189+
190+ const cwd = context . terminal . shellIntegration ?. cwd ;
191+ if ( cwd != null ) {
192+ return ( await this . container . git . getOrOpenRepository ( cwd , { detectNested : true } ) . catch ( ( ) => undefined ) )
193+ ?. path ;
194+ }
195+
196+ return this . container . git . getBestRepositoryOrFirst ( ) ?. path ;
197+ }
198+
186199 handleTerminalLink ( link : GitTerminalLink ) : void {
187200 void commands . executeCommand ( link . command . command , link . command . args ) ;
188201 }
0 commit comments