@@ -10,9 +10,11 @@ import { getBestRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
1010import { command } from '../system/-webview/command' ;
1111import { showMarkdownPreview } from '../system/-webview/markdown' ;
1212import { Logger } from '../system/logger' ;
13+ import { getNodeRepoPath } from '../views/nodes/abstract/viewNode' ;
1314import { GlCommandBase } from './commandBase' ;
1415import { getCommandUri } from './commandBase.utils' ;
1516import type { CommandContext } from './commandContext' ;
17+ import { isCommandContextViewNodeHasBranch } from './commandContext.utils' ;
1618
1719export interface ExplainBranchCommandArgs {
1820 repoPath ?: string | Uri ;
@@ -27,23 +29,35 @@ export class ExplainBranchCommand extends GlCommandBase {
2729 }
2830
2931 protected override preExecute ( context : CommandContext , args ?: ExplainBranchCommandArgs ) : Promise < void > {
32+ if ( isCommandContextViewNodeHasBranch ( context ) ) {
33+ args = { ...args } ;
34+ args . repoPath = args . repoPath ?? getNodeRepoPath ( context . node ) ;
35+ args . ref = args . ref ?? context . node . branch . ref ;
36+ args . source = args . source ?? { source : 'view' , type : 'branch' } ;
37+ }
38+
3039 return this . execute ( context . editor , context . uri , args ) ;
3140 }
3241
3342 async execute ( editor ?: TextEditor , uri ?: Uri , args ?: ExplainBranchCommandArgs ) : Promise < void > {
34- //// Clarifying the repository
35- uri = getCommandUri ( uri , editor ) ;
36- const gitUri = uri != null ? await GitUri . fromUri ( uri ) : undefined ;
37- const repository = await getBestRepositoryOrShowPicker (
38- gitUri ,
39- editor ,
40- 'Explain Branch' ,
41- 'Choose which repository to explain a branch from' ,
42- ) ;
43- if ( repository == null ) return ;
44-
4543 args = { ...args } ;
4644
45+ let repository ;
46+ if ( args ?. repoPath != null ) {
47+ repository = this . container . git . getRepository ( args . repoPath ) ;
48+ } else {
49+ uri = getCommandUri ( uri , editor ) ;
50+ const gitUri = uri != null ? await GitUri . fromUri ( uri ) : undefined ;
51+ repository = await getBestRepositoryOrShowPicker (
52+ gitUri ,
53+ editor ,
54+ 'Explain Branch' ,
55+ 'Choose which repository to explain a branch from' ,
56+ ) ;
57+ }
58+
59+ if ( repository == null ) return ;
60+
4761 try {
4862 //// Clarifying the head branch
4963 if ( args . ref == null ) {
0 commit comments