Skip to content

Commit 96f7001

Browse files
committed
Closes #4048 adds worktree display settings
1 parent 63b0fc4 commit 96f7001

File tree

11 files changed

+269
-14
lines changed

11 files changed

+269
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1212
- Adds Anthropic Claude 3.7 Sonnet model for GitLens' AI features ([#4101](https://github.com/gitkraken/vscode-gitlens/issues/4101))
1313
- Adds Google Gemini 2.0 Flash-Lite model for GitLens' AI features ([#4104](https://github.com/gitkraken/vscode-gitlens/issues/4104))
1414
- Adds integration with Bitbucket Cloud by showing enriched links to PRs and issues [#4045](https://github.com/gitkraken/vscode-gitlens/issues/4045)
15+
- Adds ability to control how worktrees are displayed in the views
16+
- Adds a `gitlens.views.worktrees.worktrees.viewAs` setting to specify whether to show worktrees by name, path, or relative path
17+
- Adds a `gitlens.views.worktrees.branches.layout` setting to specify whether to show branch worktrees as a list or tree, similar to branches
1518

1619
### Changed
1720

contributions.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11649,6 +11649,46 @@
1164911649
]
1165011650
}
1165111651
},
11652+
"gitlens.views.worktrees.setLayoutToList": {
11653+
"label": "View as List",
11654+
"icon": "$(list-tree)",
11655+
"menus": {
11656+
"gitlens/views/grouped/more": [
11657+
{
11658+
"when": "gitlens:views:scm:grouped:view == worktrees && view == gitlens.views.scm.grouped && config.gitlens.views.worktrees.branches.layout == tree",
11659+
"group": "3_gitlens",
11660+
"order": 0
11661+
}
11662+
],
11663+
"view/title": [
11664+
{
11665+
"when": "view == gitlens.views.worktrees && config.gitlens.views.worktrees.branches.layout == tree",
11666+
"group": "navigation",
11667+
"order": 50
11668+
}
11669+
]
11670+
}
11671+
},
11672+
"gitlens.views.worktrees.setLayoutToTree": {
11673+
"label": "View as Tree",
11674+
"icon": "$(list-flat)",
11675+
"menus": {
11676+
"gitlens/views/grouped/more": [
11677+
{
11678+
"when": "gitlens:views:scm:grouped:view == worktrees && view == gitlens.views.scm.grouped && config.gitlens.views.worktrees.branches.layout == list",
11679+
"group": "3_gitlens",
11680+
"order": 0
11681+
}
11682+
],
11683+
"view/title": [
11684+
{
11685+
"when": "view == gitlens.views.worktrees && config.gitlens.views.worktrees.branches.layout == list",
11686+
"group": "navigation",
11687+
"order": 50
11688+
}
11689+
]
11690+
}
11691+
},
1165211692
"gitlens.views.worktrees.setShowAvatarsOff": {
1165311693
"label": "Hide Avatars",
1165411694
"menus": {

package.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,6 +2261,23 @@
22612261
"scope": "window",
22622262
"order": 100
22632263
},
2264+
"gitlens.views.repositories.worktrees.viewAs": {
2265+
"type": "string",
2266+
"default": "name",
2267+
"enum": [
2268+
"name",
2269+
"path",
2270+
"relativePath"
2271+
],
2272+
"enumDescriptions": [
2273+
"Displays worktree name",
2274+
"Displays worktree path",
2275+
"Displays worktree relative path"
2276+
],
2277+
"markdownDescription": "Specifies how the _Repositories_ view will display worktrees",
2278+
"scope": "window",
2279+
"order": 75
2280+
},
22642281
"gitlens.views.repositories.enabled": {
22652282
"deprecationMessage": "Deprecated. This setting is no longer used",
22662283
"markdownDeprecationMessage": "Deprecated. This setting is no longer used"
@@ -2867,6 +2884,38 @@
28672884
"scope": "window",
28682885
"order": 32
28692886
},
2887+
"gitlens.views.worktrees.worktrees.viewAs": {
2888+
"type": "string",
2889+
"default": "name",
2890+
"enum": [
2891+
"name",
2892+
"path",
2893+
"relativePath"
2894+
],
2895+
"enumDescriptions": [
2896+
"Displays worktree name",
2897+
"Displays worktree path",
2898+
"Displays worktree relative path"
2899+
],
2900+
"markdownDescription": "Specifies how the _Worktrees_ view will display worktrees",
2901+
"scope": "window",
2902+
"order": 33
2903+
},
2904+
"gitlens.views.worktrees.branches.layout": {
2905+
"type": "string",
2906+
"default": "tree",
2907+
"enum": [
2908+
"list",
2909+
"tree"
2910+
],
2911+
"enumDescriptions": [
2912+
"Displays worktree branches as a list",
2913+
"Displays worktree branches as a tree when branch names contain slashes `/`"
2914+
],
2915+
"markdownDescription": "Specifies how the _Worktrees_ view will display worktree branches",
2916+
"scope": "window",
2917+
"order": 35
2918+
},
28702919
"gitlens.views.worktrees.files.layout": {
28712920
"type": "string",
28722921
"default": "auto",
@@ -3356,6 +3405,23 @@
33563405
"scope": "window",
33573406
"order": 70
33583407
},
3408+
"gitlens.views.workspaces.worktrees.viewAs": {
3409+
"type": "string",
3410+
"default": "name",
3411+
"enum": [
3412+
"name",
3413+
"path",
3414+
"relativePath"
3415+
],
3416+
"enumDescriptions": [
3417+
"Displays worktree name",
3418+
"Displays worktree path",
3419+
"Displays worktree relative path"
3420+
],
3421+
"markdownDescription": "Specifies how the _Cloud Workspaces_ view will display worktrees",
3422+
"scope": "window",
3423+
"order": 75
3424+
},
33593425
"gitlens.views.workspaces.files.layout": {
33603426
"type": "string",
33613427
"default": "auto",
@@ -9511,6 +9577,16 @@
95119577
"title": "View Files as Tree",
95129578
"icon": "$(list-flat)"
95139579
},
9580+
{
9581+
"command": "gitlens.views.worktrees.setLayoutToList",
9582+
"title": "View as List",
9583+
"icon": "$(list-tree)"
9584+
},
9585+
{
9586+
"command": "gitlens.views.worktrees.setLayoutToTree",
9587+
"title": "View as Tree",
9588+
"icon": "$(list-flat)"
9589+
},
95149590
{
95159591
"command": "gitlens.views.worktrees.setShowAvatarsOff",
95169592
"title": "Hide Avatars"
@@ -12919,6 +12995,14 @@
1291912995
"command": "gitlens.views.worktrees.setFilesLayoutToTree",
1292012996
"when": "false"
1292112997
},
12998+
{
12999+
"command": "gitlens.views.worktrees.setLayoutToList",
13000+
"when": "false"
13001+
},
13002+
{
13003+
"command": "gitlens.views.worktrees.setLayoutToTree",
13004+
"when": "false"
13005+
},
1292213006
{
1292313007
"command": "gitlens.views.worktrees.setShowAvatarsOff",
1292413008
"when": "false"
@@ -14880,6 +14964,16 @@
1488014964
"when": "gitlens:views:scm:grouped:view == tags && view == gitlens.views.scm.grouped",
1488114965
"group": "9_gitlens@1"
1488214966
},
14967+
{
14968+
"command": "gitlens.views.worktrees.setLayoutToList",
14969+
"when": "gitlens:views:scm:grouped:view == worktrees && view == gitlens.views.scm.grouped && config.gitlens.views.worktrees.branches.layout == tree",
14970+
"group": "3_gitlens@0"
14971+
},
14972+
{
14973+
"command": "gitlens.views.worktrees.setLayoutToTree",
14974+
"when": "gitlens:views:scm:grouped:view == worktrees && view == gitlens.views.scm.grouped && config.gitlens.views.worktrees.branches.layout == list",
14975+
"group": "3_gitlens@0"
14976+
},
1488314977
{
1488414978
"command": "gitlens.views.worktrees.setFilesLayoutToAuto",
1488514979
"when": "gitlens:views:scm:grouped:view == worktrees && view == gitlens.views.scm.grouped && config.gitlens.views.worktrees.files.layout == tree",
@@ -18363,6 +18457,16 @@
1836318457
"when": "view == gitlens.views.worktrees",
1836418458
"group": "navigation@10"
1836518459
},
18460+
{
18461+
"command": "gitlens.views.worktrees.setLayoutToList",
18462+
"when": "view == gitlens.views.worktrees && config.gitlens.views.worktrees.branches.layout == tree",
18463+
"group": "navigation@50"
18464+
},
18465+
{
18466+
"command": "gitlens.views.worktrees.setLayoutToTree",
18467+
"when": "view == gitlens.views.worktrees && config.gitlens.views.worktrees.branches.layout == list",
18468+
"group": "navigation@50"
18469+
},
1836618470
{
1836718471
"command": "gitlens.views.worktrees.refresh",
1836818472
"when": "view == gitlens.views.worktrees",

src/config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,9 @@ export interface RepositoriesViewConfig {
902902
readonly showTags: boolean;
903903
readonly showUpstreamStatus: boolean;
904904
readonly showWorktrees: boolean;
905+
readonly worktrees: {
906+
readonly viewAs: ViewWorktreesViewAs;
907+
};
905908
}
906909

907910
export interface SearchAndCompareViewConfig {
@@ -927,8 +930,13 @@ export interface TagsViewConfig {
927930
readonly reveal: boolean;
928931
}
929932

933+
export type ViewWorktreesViewAs = 'name' | 'path' | 'relativePath';
934+
930935
export interface WorktreesViewConfig {
931936
readonly avatars: boolean;
937+
readonly branches: {
938+
readonly layout: ViewBranchesLayout;
939+
};
932940
readonly files: ViewsFilesConfig;
933941
readonly pullRequests: {
934942
readonly enabled: boolean;
@@ -938,6 +946,9 @@ export interface WorktreesViewConfig {
938946
readonly reveal: boolean;
939947
readonly showBranchComparison: false | Extract<ViewShowBranchComparison, 'branch'>;
940948
readonly showStashes: boolean;
949+
readonly worktrees: {
950+
readonly viewAs: ViewWorktreesViewAs;
951+
};
941952
}
942953

943954
export interface WorkspacesViewConfig {
@@ -965,6 +976,9 @@ export interface WorkspacesViewConfig {
965976
readonly showTags: boolean;
966977
readonly showUpstreamStatus: boolean;
967978
readonly showWorktrees: boolean;
979+
readonly worktrees: {
980+
readonly viewAs: ViewWorktreesViewAs;
981+
};
968982
}
969983

970984
export interface ViewsFilesConfig {

src/constants.commands.generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ export type ContributedCommands =
566566
| 'gitlens.views.worktrees.setFilesLayoutToAuto'
567567
| 'gitlens.views.worktrees.setFilesLayoutToList'
568568
| 'gitlens.views.worktrees.setFilesLayoutToTree'
569+
| 'gitlens.views.worktrees.setLayoutToList'
570+
| 'gitlens.views.worktrees.setLayoutToTree'
569571
| 'gitlens.views.worktrees.setShowAvatarsOff'
570572
| 'gitlens.views.worktrees.setShowAvatarsOn'
571573
| 'gitlens.views.worktrees.setShowBranchComparisonOff'

src/git/utils/-webview/sorting.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ export function sortWorktrees(
321321

322322
return (
323323
(a.opened ? -1 : 1) - (b.opened ? -1 : 1) ||
324+
(a.isDefault ? -1 : 1) - (b.isDefault ? -1 : 1) ||
324325
(a.hasChanges === null ? 0 : a.hasChanges ? -1 : 1) -
325326
(b.hasChanges === null ? 0 : b.hasChanges ? -1 : 1) ||
326327
(a.date == null ? -1 : a.date.getTime()) - (b.date == null ? -1 : b.date.getTime()) ||
@@ -334,6 +335,7 @@ export function sortWorktrees(
334335

335336
return (
336337
(a.opened ? -1 : 1) - (b.opened ? -1 : 1) ||
338+
(a.isDefault ? -1 : 1) - (b.isDefault ? -1 : 1) ||
337339
(a.hasChanges === null ? 0 : a.hasChanges ? -1 : 1) -
338340
(b.hasChanges === null ? 0 : b.hasChanges ? -1 : 1) ||
339341
(a.name === 'main' ? -1 : 1) - (b.name === 'main' ? -1 : 1) ||
@@ -349,6 +351,7 @@ export function sortWorktrees(
349351

350352
return (
351353
(a.opened ? -1 : 1) - (b.opened ? -1 : 1) ||
354+
(a.isDefault ? -1 : 1) - (b.isDefault ? -1 : 1) ||
352355
(a.hasChanges === null ? 0 : a.hasChanges ? -1 : 1) -
353356
(b.hasChanges === null ? 0 : b.hasChanges ? -1 : 1) ||
354357
(a.name === 'main' ? -1 : 1) - (b.name === 'main' ? -1 : 1) ||
@@ -365,6 +368,7 @@ export function sortWorktrees(
365368

366369
return (
367370
(a.opened ? -1 : 1) - (b.opened ? -1 : 1) ||
371+
(a.isDefault ? -1 : 1) - (b.isDefault ? -1 : 1) ||
368372
(b.date == null ? -1 : b.date.getTime()) - (a.date == null ? -1 : a.date.getTime()) ||
369373
(a.hasChanges === null ? 0 : a.hasChanges ? -1 : 1) -
370374
(b.hasChanges === null ? 0 : b.hasChanges ? -1 : 1) ||

src/views/nodes/branchOrTagFolderNode.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import type { View } from '../viewBase';
55
import { ContextValues, getViewNodeId, ViewNode } from './abstract/viewNode';
66
import type { BranchNode } from './branchNode';
77
import type { TagNode } from './tagNode';
8+
import type { WorktreeNode } from './worktreeNode';
89

910
export class BranchOrTagFolderNode extends ViewNode<'branch-tag-folder'> {
1011
constructor(
1112
view: View,
1213
protected override readonly parent: ViewNode,
13-
public readonly folderType: 'branch' | 'remote-branch' | 'tag',
14-
public readonly root: HierarchicalItem<BranchNode | TagNode>,
14+
public readonly folderType: 'branch' | 'remote-branch' | 'tag' | 'worktree',
15+
public readonly root: HierarchicalItem<BranchNode | TagNode | WorktreeNode>,
1516
public readonly repoPath: string,
1617
public readonly folderName: string,
1718
public readonly relativePath: string | undefined,
@@ -33,12 +34,16 @@ export class BranchOrTagFolderNode extends ViewNode<'branch-tag-folder'> {
3334
getChildren(): ViewNode[] {
3435
if (this.root.descendants === undefined || this.root.children === undefined) return [];
3536

36-
const children: (BranchOrTagFolderNode | BranchNode | TagNode)[] = [];
37+
const children: (BranchOrTagFolderNode | BranchNode | TagNode | WorktreeNode)[] = [];
3738

3839
for (const folder of this.root.children.values()) {
3940
if (folder.value === undefined) {
40-
// If the folder contains the current branch, expand it by default
41-
const expand = folder.descendants?.some(n => n.is('branch') && (n.current || n.worktree?.opened));
41+
// If the folder contains the current branch or an active worktree, expand it by default
42+
const expand = folder.descendants?.some(
43+
n =>
44+
(n.is('branch') && (n.current || n.worktree?.opened)) ||
45+
(n.is('worktree') && n.worktree?.opened),
46+
);
4247
children.push(
4348
new BranchOrTagFolderNode(
4449
this.view,

src/views/nodes/branchesNode.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export class BranchesNode extends CacheableChildrenViewNode<'branches', ViewsWit
9191
}
9292

9393
if (branchNodes.length === 0) return [new MessageNode(this.view, this, 'No branches could be found.')];
94-
if (this.view.config.branches.layout === 'list') return branchNodes;
94+
if (this.view.config.branches.layout === 'list') {
95+
this.children = branchNodes;
96+
return branchNodes;
97+
}
9598

9699
const hierarchy = makeHierarchical(
97100
branchNodes,

0 commit comments

Comments
 (0)