Skip to content

Commit 7bbbefc

Browse files
committed
Adds view support for explain branch
1 parent fabe2a7 commit 7bbbefc

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

contributions.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@
2525
},
2626
"gitlens.ai.explainBranch": {
2727
"label": "Explain Branch (Preview)...",
28-
"commandPalette": "gitlens:enabled && !gitlens:readonly && !gitlens:untrusted && gitlens:gk:organization:ai:enabled"
28+
"commandPalette": "gitlens:enabled && !gitlens:readonly && !gitlens:untrusted && gitlens:gk:organization:ai:enabled",
29+
"menus": {
30+
"view/item/context": [
31+
{
32+
"when": "viewItem =~ /gitlens:branch\\b/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && gitlens:gk:organization:ai:enabled && config.gitlens.ai.enabled",
33+
"group": "3_gitlens_ai",
34+
"order": 1
35+
}
36+
]
37+
}
2938
},
3039
"gitlens.ai.explainCommit": {
3140
"label": "Explain Commit...",

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16397,6 +16397,11 @@
1639716397
"when": "viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+(tracking|remote)\\b)/ && listMultiSelection",
1639816398
"group": "2_gitlens_quickopen@1"
1639916399
},
16400+
{
16401+
"command": "gitlens.ai.explainBranch",
16402+
"when": "viewItem =~ /gitlens:branch\\b/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && gitlens:gk:organization:ai:enabled && config.gitlens.ai.enabled",
16403+
"group": "3_gitlens_ai@1"
16404+
},
1640016405
{
1640116406
"command": "gitlens.views.openChangedFileDiffsWithMergeBase",
1640216407
"when": "viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)/ && !listMultiSelection",

src/commands/explainBranch.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import { getBestRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
1010
import { command } from '../system/-webview/command';
1111
import { showMarkdownPreview } from '../system/-webview/markdown';
1212
import { Logger } from '../system/logger';
13+
import { getNodeRepoPath } from '../views/nodes/abstract/viewNode';
1314
import { GlCommandBase } from './commandBase';
1415
import { getCommandUri } from './commandBase.utils';
1516
import type { CommandContext } from './commandContext';
17+
import { isCommandContextViewNodeHasBranch } from './commandContext.utils';
1618

1719
export 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

Comments
 (0)