Skip to content

Commit 4ee816d

Browse files
committed
Closes #4739 adds branch/tag solo'ing to graph
- Adds new "Solo Branch" and "Solo Tag" commands to quickly filter the commit graph view to a specific branch or tag
1 parent 08b0c26 commit 4ee816d

File tree

9 files changed

+779
-571
lines changed

9 files changed

+779
-571
lines changed

contributions.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3456,6 +3456,58 @@
34563456
]
34573457
}
34583458
},
3459+
"gitlens.graph.soloBranch": {
3460+
"label": "Solo Branch",
3461+
"commandPalette": true,
3462+
"menus": {
3463+
"webview/context": [
3464+
{
3465+
"when": "webviewItem =~ /gitlens:branch\\b/",
3466+
"group": "8_gitlens_actions",
3467+
"order": 9
3468+
}
3469+
]
3470+
}
3471+
},
3472+
"gitlens.graph.soloBranch:views": {
3473+
"label": "Solo Branch in Commit Graph",
3474+
"commandPalette": true,
3475+
"menus": {
3476+
"view/item/context": [
3477+
{
3478+
"when": "viewItem =~ /gitlens:branch\\b/",
3479+
"group": "8_gitlens_actions",
3480+
"order": 9
3481+
}
3482+
]
3483+
}
3484+
},
3485+
"gitlens.graph.soloTag": {
3486+
"label": "Solo Tag",
3487+
"commandPalette": true,
3488+
"menus": {
3489+
"webview/context": [
3490+
{
3491+
"when": "webviewItem =~ /gitlens:tag\\b/",
3492+
"group": "8_gitlens_actions",
3493+
"order": 9
3494+
}
3495+
]
3496+
}
3497+
},
3498+
"gitlens.graph.soloTag:views": {
3499+
"label": "Solo Tag in Commit Graph",
3500+
"commandPalette": true,
3501+
"menus": {
3502+
"view/item/context": [
3503+
{
3504+
"when": "viewItem =~ /gitlens:tag\\b/",
3505+
"group": "8_gitlens_actions",
3506+
"order": 9
3507+
}
3508+
]
3509+
}
3510+
},
34593511
"gitlens.graph.split": {
34603512
"label": "Split Commit Graph",
34613513
"icon": "$(split-horizontal)",

package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7578,6 +7578,26 @@
75787578
"title": "Inspect Details",
75797579
"icon": "$(eye)"
75807580
},
7581+
{
7582+
"command": "gitlens.graph.soloBranch",
7583+
"title": "Solo Branch",
7584+
"category": "GitLens"
7585+
},
7586+
{
7587+
"command": "gitlens.graph.soloBranch:views",
7588+
"title": "Solo Branch in Commit Graph",
7589+
"category": "GitLens"
7590+
},
7591+
{
7592+
"command": "gitlens.graph.soloTag",
7593+
"title": "Solo Tag",
7594+
"category": "GitLens"
7595+
},
7596+
{
7597+
"command": "gitlens.graph.soloTag:views",
7598+
"title": "Solo Tag in Commit Graph",
7599+
"category": "GitLens"
7600+
},
75817601
{
75827602
"command": "gitlens.graph.split",
75837603
"title": "Split Commit Graph",
@@ -18799,6 +18819,11 @@
1879918819
"when": "viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+starred\\b)/ && listMultiSelection",
1880018820
"group": "8_gitlens_actions@1"
1880118821
},
18822+
{
18823+
"command": "gitlens.graph.soloBranch:views",
18824+
"when": "viewItem =~ /gitlens:branch\\b/",
18825+
"group": "8_gitlens_actions@9"
18826+
},
1880218827
{
1880318828
"command": "gitlens.views.repositories.setShowSectionOff",
1880418829
"when": "viewItem =~ /gitlens:(compare:branch(?=.*?\\b\\+root\\b)|branches|branch(?=.*?\\b\\+commits\\b)|reflog|remotes|stashes|status:upstream|tags|worktrees)\\b/ && view == gitlens.views.repositories && !listMultiSelection",
@@ -20243,6 +20268,11 @@
2024320268
"when": "viewItem =~ /gitlens:tag\\b/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
2024420269
"group": "1_gitlens_actions_3@3"
2024520270
},
20271+
{
20272+
"command": "gitlens.graph.soloTag:views",
20273+
"when": "viewItem =~ /gitlens:tag\\b/",
20274+
"group": "8_gitlens_actions@9"
20275+
},
2024620276
{
2024720277
"command": "gitlens.views.createTag",
2024820278
"when": "viewItem =~ /gitlens:tags\\b/ && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
@@ -24776,6 +24806,11 @@
2477624806
"when": "webviewItem =~ /gitlens:branch\\b(?=.*?\\b\\+starred\\b)/ && !listMultiSelection",
2477724807
"group": "8_gitlens_actions@1"
2477824808
},
24809+
{
24810+
"command": "gitlens.graph.soloBranch",
24811+
"when": "webviewItem =~ /gitlens:branch\\b/",
24812+
"group": "8_gitlens_actions@9"
24813+
},
2477924814
{
2478024815
"command": "gitlens.graph.hideRemote",
2478124816
"when": "webviewItem =~ /gitlens:branch\\b(?=.*?\\b\\+remote\\b)(?!.*?\\b\\+current\\b)/",
@@ -25236,6 +25271,11 @@
2523625271
"when": "webviewItem =~ /gitlens:tag\\b/ && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
2523725272
"group": "1_gitlens_actions_3@4"
2523825273
},
25274+
{
25275+
"command": "gitlens.graph.soloTag",
25276+
"when": "webviewItem =~ /gitlens:tag\\b/",
25277+
"group": "8_gitlens_actions@9"
25278+
},
2523925279
{
2524025280
"command": "gitlens.graph.hideTag",
2524125281
"when": "webviewItem =~ /gitlens:tag\\b/",

src/constants.commands.generated.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ export type ContributedCommands =
206206
| 'gitlens.graph.scrollMarkerTagOn'
207207
| 'gitlens.graph.shareAsCloudPatch'
208208
| 'gitlens.graph.showInDetailsView'
209+
| 'gitlens.graph.soloBranch'
210+
| 'gitlens.graph.soloBranch:views'
211+
| 'gitlens.graph.soloTag'
212+
| 'gitlens.graph.soloTag:views'
209213
| 'gitlens.graph.split'
210214
| 'gitlens.graph.switchToAnotherBranch'
211215
| 'gitlens.graph.switchToBranch'
@@ -905,6 +909,10 @@ export type ContributedPaletteCommands =
905909
| 'gitlens.gitCommands.worktree.delete'
906910
| 'gitlens.gitCommands.worktree.open'
907911
| 'gitlens.gk.switchOrganization'
912+
| 'gitlens.graph.soloBranch'
913+
| 'gitlens.graph.soloBranch:views'
914+
| 'gitlens.graph.soloTag'
915+
| 'gitlens.graph.soloTag:views'
908916
| 'gitlens.graph.split'
909917
| 'gitlens.graph.switchToEditorLayout'
910918
| 'gitlens.graph.switchToPanelLayout'

src/git/models/reference.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface GitBranchReference {
66
sha?: string;
77
readonly remote: boolean;
88
readonly upstream?: { name: string; missing: boolean };
9+
readonly worktree?: { path: string; isDefault: boolean } | boolean;
910
repoPath: string;
1011
}
1112

src/git/utils/reference.utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface GitBranchReferenceOptions {
1717
remote: boolean;
1818
sha?: string;
1919
upstream?: { name: string; missing: boolean };
20+
worktree?: { path: string; isDefault: boolean } | boolean;
2021
}
2122

2223
interface GitCommitReferenceOptions {
@@ -68,6 +69,7 @@ export function createReference(
6869
remote: options.remote,
6970
sha: options.sha,
7071
upstream: options.upstream,
72+
worktree: options.worktree,
7173
};
7274
case 'stash':
7375
return {
@@ -224,9 +226,11 @@ export function getReferenceTypeLabel(ref: GitReference | undefined): 'Branch' |
224226
}
225227
}
226228

227-
export function getReferenceTypeIcon(ref: GitReference | undefined): string {
229+
export function getReferenceTypeIcon(ref: GitReference | undefined, webview?: boolean): string {
228230
switch (ref?.refType) {
229231
case 'branch':
232+
if (ref.remote) return 'cloud';
233+
if (ref.worktree) return webview ? 'gl-worktree' : 'gitlens-worktree';
230234
return 'git-branch';
231235
case 'tag':
232236
return 'tag';

src/views/viewCommands.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import { lazy } from '../system/lazy';
6868
import { basename } from '../system/path';
6969
import { getSettledValue } from '../system/promise';
7070
import { DeepLinkActionType } from '../uris/deepLinks/deepLink';
71+
import type { ShowInCommitGraphCommandArgs } from '../webviews/plus/graph/registration';
7172
import type { LaunchpadItemNode } from './launchpadView';
7273
import type { RepositoryFolderNode } from './nodes/abstract/repositoryFolderNode';
7374
import type { ClipboardType } from './nodes/abstract/viewNode';
@@ -1630,6 +1631,28 @@ export class ViewCommands implements Disposable {
16301631
return executeCommand('gitlens.openFileHistoryInGraph', node.uri);
16311632
}
16321633

1634+
@command('gitlens.graph.soloBranch:views')
1635+
@command('gitlens.graph.soloTag:views')
1636+
@log()
1637+
private async soloReferenceInGraph(node: BranchNode | TagNode) {
1638+
if (!node.is('branch') && !node.is('tag')) return Promise.resolve();
1639+
1640+
const repo = this.container.git.getRepository(node.repoPath);
1641+
if (repo == null) return Promise.resolve();
1642+
1643+
// Show the graph with a ref: search query to filter the graph to this branch
1644+
return void executeCommand<ShowInCommitGraphCommandArgs>('gitlens.showInCommitGraph', {
1645+
repository: repo,
1646+
search: {
1647+
query: `ref:${node.ref.name}`,
1648+
filter: true,
1649+
matchAll: false,
1650+
matchCase: false,
1651+
matchRegex: false,
1652+
},
1653+
});
1654+
}
1655+
16331656
@command('gitlens.views.openChangedFiles')
16341657
@log()
16351658
private async openFiles(

0 commit comments

Comments
 (0)