Skip to content

Commit c8c369c

Browse files
committed
Adds Open in "View" command to branch cards
1 parent 27f6837 commit c8c369c

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

docs/telemetry-events.md

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/constants.commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type InternalHomeWebviewCommands =
5454
| 'gitlens.home.switchToBranch'
5555
| 'gitlens.home.fetch'
5656
| 'gitlens.home.openInGraph'
57+
| 'gitlens.openInView.branch:home'
5758
| 'gitlens.home.createBranch'
5859
| 'gitlens.home.mergeIntoCurrent'
5960
| 'gitlens.home.rebaseCurrentOnto'

src/webviews/apps/plus/home/components/branch-card.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ export abstract class GlBranchCardBase extends GlElement {
475475
}
476476

477477
get isWorktree(): boolean {
478-
return this.branch.worktree != null;
478+
return this.branch.worktree != null && !this.branch.worktree.isDefault;
479479
}
480480

481481
get cardIndicator(): GlCard['indicator'] {
@@ -951,7 +951,7 @@ export class GlBranchCard extends GlBranchCardBase {
951951
protected getCollapsedActions(): TemplateResult[] {
952952
const actions = [];
953953

954-
if (this.branch.worktree) {
954+
if (this.isWorktree) {
955955
actions.push(
956956
html`<action-item
957957
label="Open Worktree"
@@ -974,6 +974,22 @@ export class GlBranchCard extends GlBranchCardBase {
974974
);
975975
}
976976

977+
actions.push(
978+
html`<action-item
979+
label="Open in Commit Graph"
980+
icon="gl-graph"
981+
href=${createCommandLink('gitlens.home.openInGraph', {
982+
...this.branchRef,
983+
type: 'branch',
984+
} satisfies OpenInGraphParams)}
985+
></action-item>`,
986+
html`<action-item
987+
label=${this.isWorktree ? 'Open in Worktrees View' : 'Open in Branches View'}
988+
icon="arrow-right"
989+
href=${this.createCommandLink('gitlens.openInView.branch:home')}
990+
></action-item>`,
991+
);
992+
977993
return actions;
978994
}
979995

@@ -982,7 +998,7 @@ export class GlBranchCard extends GlBranchCardBase {
982998

983999
const aiEnabled = this._homeState.orgSettings.ai && this._homeState.aiEnabled;
9841000

985-
if (this.branch.worktree) {
1001+
if (this.isWorktree) {
9861002
actions.push(
9871003
html`<action-item
9881004
label="Open Worktree"
@@ -1070,6 +1086,11 @@ export class GlBranchCard extends GlBranchCardBase {
10701086
type: 'branch',
10711087
} satisfies OpenInGraphParams)}
10721088
></action-item>`,
1089+
html`<action-item
1090+
label=${this.isWorktree ? 'Open in Worktrees View' : 'Open in Branches View'}
1091+
icon="arrow-right"
1092+
href=${this.createCommandLink('gitlens.openInView.branch:home')}
1093+
></action-item>`,
10731094
);
10741095

10751096
return actions;

src/webviews/home/homeWebview.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import {
2020
import type { HomeTelemetryContext, Source } from '../../constants.telemetry';
2121
import type { Container } from '../../container';
2222
import { executeGitCommand } from '../../git/actions';
23+
import { revealBranch } from '../../git/actions/branch';
2324
import { openComparisonChanges } from '../../git/actions/commit';
2425
import { abortPausedOperation, continuePausedOperation, skipPausedOperation } from '../../git/actions/pausedOperation';
2526
import * as RepoActions from '../../git/actions/repository';
27+
import { revealWorktree } from '../../git/actions/worktree';
2628
import type { BranchContributionsOverview } from '../../git/gitProvider';
2729
import type { GitBranch } from '../../git/models/branch';
2830
import type { GitFileChangeShape } from '../../git/models/fileChange';
@@ -363,6 +365,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
363365
registerCommand('gitlens.home.openInGraph', this.openInGraph, this),
364366
registerCommand('gitlens.visualizeHistory.repo:home', this.openInTimeline, this),
365367
registerCommand('gitlens.visualizeHistory.branch:home', this.openInTimeline, this),
368+
registerCommand('gitlens.openInView.branch:home', this.openInView, this),
366369
registerCommand('gitlens.home.createBranch', this.createBranch, this),
367370
registerCommand('gitlens.home.mergeIntoCurrent', this.mergeIntoCurrent, this),
368371
registerCommand('gitlens.home.rebaseCurrentOnto', this.rebaseCurrentOnto, this),
@@ -527,6 +530,22 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
527530
}
528531
}
529532

533+
@log<HomeWebviewProvider['openInView']>({
534+
args: { 0: p => `repoPath=${p?.repoPath}, branchId=${p?.branchId}` },
535+
})
536+
private async openInView(params: BranchRef) {
537+
const { repo, branch } = await this.getRepoInfoFromRef(params);
538+
if (repo == null || branch == null) return;
539+
540+
// Show in the Worktrees or Branches view depending
541+
const worktree = await branch.getWorktree();
542+
if (worktree != null && !worktree.isDefault) {
543+
await revealWorktree(worktree, { select: true, focus: true, expand: true });
544+
} else {
545+
await revealBranch(branch, { select: true, focus: true, expand: true });
546+
}
547+
}
548+
530549
@log()
531550
private createBranch() {
532551
this.container.telemetry.sendEvent('home/createBranch');

0 commit comments

Comments
 (0)