Skip to content

Commit 1a9449a

Browse files
committed
Renames "main" worktree to "default"
1 parent cc110f1 commit 1a9449a

File tree

10 files changed

+41
-39
lines changed

10 files changed

+41
-39
lines changed

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13982,12 +13982,12 @@
1398213982
},
1398313983
{
1398413984
"command": "gitlens.views.switchToAnotherBranch",
13985-
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+(current|main)\\b)(?!.*?\\b\\+closed\\b)/",
13985+
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+(current|checkedout)\\b)(?!.*?\\b\\+closed\\b)/",
1398613986
"group": "inline@7"
1398713987
},
1398813988
{
1398913989
"command": "gitlens.views.switchToBranch",
13990-
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|closed|main|worktree)\\b)/",
13990+
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|closed|checkedout|worktree)\\b)/",
1399113991
"group": "inline@7"
1399213992
},
1399313993
{
@@ -14078,17 +14078,17 @@
1407814078
},
1407914079
{
1408014080
"command": "gitlens.views.openInWorktree",
14081-
"when": "!listMultiSelection && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|closed|main|worktree)\\b)/",
14081+
"when": "!listMultiSelection && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|closed|checkedout|worktree)\\b)/",
1408214082
"group": "1_gitlens_action@3"
1408314083
},
1408414084
{
1408514085
"command": "gitlens.views.switchToAnotherBranch",
14086-
"when": "!listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+(current|main)\\b)(?!.*?\\b\\+closed\\b)/",
14086+
"when": "!listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+(current|checkedout)\\b)(?!.*?\\b\\+closed\\b)/",
1408714087
"group": "1_gitlens_action@1"
1408814088
},
1408914089
{
1409014090
"command": "gitlens.views.switchToBranch",
14091-
"when": "!listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|closed|main|worktree)\\b)/",
14091+
"when": "!listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|closed|checkedout|worktree)\\b)/",
1409214092
"group": "1_gitlens_action@1"
1409314093
},
1409414094
{
@@ -14133,12 +14133,12 @@
1413314133
},
1413414134
{
1413514135
"command": "gitlens.views.deleteBranch",
14136-
"when": "!listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|main)\\b)(?!.*?\\b\\+closed\\b)/",
14136+
"when": "!listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|checkedout)\\b)(?!.*?\\b\\+closed\\b)/",
1413714137
"group": "1_gitlens_actions@7"
1413814138
},
1413914139
{
1414014140
"command": "gitlens.views.deleteBranch.multi",
14141-
"when": "listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|main)\\b)(?!.*?\\b\\+closed\\b)/",
14141+
"when": "listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|checkedout)\\b)(?!.*?\\b\\+closed\\b)/",
1414214142
"group": "1_gitlens_actions@7"
1414314143
},
1414414144
{
@@ -15512,12 +15512,12 @@
1551215512
},
1551315513
{
1551415514
"command": "gitlens.views.deleteWorktree",
15515-
"when": "!listMultiSelection && !gitlens:readonly && viewItem =~ /gitlens:worktree\\b(?!.*?\\b\\+(active|main)\\b)/",
15515+
"when": "!listMultiSelection && !gitlens:readonly && viewItem =~ /gitlens:worktree\\b(?!.*?\\b\\+(active|default)\\b)/",
1551615516
"group": "6_gitlens_actions@1"
1551715517
},
1551815518
{
1551915519
"command": "gitlens.views.deleteWorktree.multi",
15520-
"when": "listMultiSelection && !gitlens:readonly && viewItem =~ /gitlens:worktree\\b(?!.*?\\b\\+(active|main)\\b)/",
15520+
"when": "listMultiSelection && !gitlens:readonly && viewItem =~ /gitlens:worktree\\b(?!.*?\\b\\+(active|default)\\b)/",
1552115521
"group": "6_gitlens_actions@1"
1552215522
},
1552315523
{
@@ -15599,17 +15599,17 @@
1559915599
},
1560015600
{
1560115601
"command": "gitlens.graph.openInWorktree",
15602-
"when": "!gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|main|worktree)\\b)/",
15602+
"when": "!gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|checkedout|worktree)\\b)/",
1560315603
"group": "1_gitlens_action@3"
1560415604
},
1560515605
{
1560615606
"command": "gitlens.graph.switchToAnotherBranch",
15607-
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b(?=.*?\\b\\+(current|main)\\b)/",
15607+
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b(?=.*?\\b\\+(current|checkedout)\\b)/",
1560815608
"group": "1_gitlens_action@1"
1560915609
},
1561015610
{
1561115611
"command": "gitlens.graph.switchToBranch",
15612-
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|main|worktree)\\b)/",
15612+
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|checkedout|worktree)\\b)/",
1561315613
"group": "1_gitlens_action@1"
1561415614
},
1561515615
{
@@ -15654,7 +15654,7 @@
1565415654
},
1565515655
{
1565615656
"command": "gitlens.graph.deleteBranch",
15657-
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|main)\\b)/",
15657+
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|checkedout)\\b)/",
1565815658
"group": "1_gitlens_actions@7"
1565915659
},
1566015660
{

src/commands/git/branch.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ export class BranchGitCommand extends QuickCommand {
439439
state.references = [state.references];
440440
}
441441

442-
const worktreesByBranch = await getWorktreesByBranch(state.repo, { includeMainWorktree: true });
442+
const worktreesByBranch = await getWorktreesByBranch(state.repo, { includeDefault: true });
443443

444444
if (
445445
state.counter < 3 ||
@@ -450,8 +450,8 @@ export class BranchGitCommand extends QuickCommand {
450450

451451
const result = yield* pickBranchesStep(state, context, {
452452
filter: prune
453-
? b => !b.current && Boolean(b.upstream?.missing) && !worktreesByBranch.get(b.id)?.main
454-
: b => !b.current && !worktreesByBranch.get(b.id)?.main,
453+
? b => !b.current && Boolean(b.upstream?.missing) && !worktreesByBranch.get(b.id)?.isDefault
454+
: b => !b.current && !worktreesByBranch.get(b.id)?.isDefault,
455455
picked: state.references?.map(r => r.ref),
456456
placeholder: prune
457457
? 'Choose branches with missing upstreams to delete'
@@ -522,7 +522,7 @@ export class BranchGitCommand extends QuickCommand {
522522

523523
for (const ref of ensureArray(state.references)) {
524524
const worktree = worktreesByBranch.get(ref.id!);
525-
if (worktree != null && !worktree.main) {
525+
if (worktree != null && !worktree.isDefault) {
526526
worktrees.push(worktree);
527527
}
528528
}

src/commands/git/switch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export class SwitchGitCommand extends QuickCommand<State> {
209209
state.reference.repoPath,
210210
w => w.branch?.name === state.reference!.name,
211211
);
212-
if (worktree != null && !worktree.main) {
212+
if (worktree != null && !worktree.isDefault) {
213213
if (state.fastForwardTo != null) {
214214
state.repos[0].merge('--ff-only', state.fastForwardTo.ref);
215215
}

src/commands/git/worktree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ export class WorktreeGitCommand extends QuickCommand<State> {
847847
const result = yield* pickWorktreesStep(state, context, {
848848
// Can't delete the main or opened worktree
849849
excludeOpened: true,
850-
filter: wt => !wt.main,
850+
filter: wt => !wt.isDefault,
851851
includeStatus: true,
852852
picked: state.uris?.map(uri => uri.toString()),
853853
placeholder: 'Choose worktrees to delete',

src/env/node/git/localGitProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,7 +2328,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
23282328
this.getCurrentUser(repoPath),
23292329
this.container.git
23302330
.getWorktrees(repoPath)
2331-
.then(w => [w, groupWorktreesByBranch(w, { includeMainWorktree: true })]) satisfies Promise<
2331+
.then(w => [w, groupWorktreesByBranch(w, { includeDefault: true })]) satisfies Promise<
23322332
[GitWorktree[], Map<string, GitWorktree>]
23332333
>,
23342334
]);
@@ -2341,7 +2341,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
23412341

23422342
let branchIdOfMainWorktree: string | undefined;
23432343
if (worktreesByBranch != null) {
2344-
branchIdOfMainWorktree = find(worktreesByBranch, ([, wt]) => wt.main)?.[0];
2344+
branchIdOfMainWorktree = find(worktreesByBranch, ([, wt]) => wt.isDefault)?.[0];
23452345
if (branchIdOfMainWorktree != null) {
23462346
worktreesByBranch.delete(branchIdOfMainWorktree);
23472347
}
@@ -2629,7 +2629,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
26292629
worktreesByBranch?.has(branchId)
26302630
? '+worktree'
26312631
: branchIdOfMainWorktree === branchId
2632-
? '+main'
2632+
? '+checkedout'
26332633
: ''
26342634
}`,
26352635
webviewItemValue: {

src/git/models/worktree.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type { GitStatus } from './status';
2121
export class GitWorktree {
2222
constructor(
2323
private readonly container: Container,
24-
public readonly main: boolean,
24+
public readonly isDefault: boolean,
2525
public readonly type: 'bare' | 'branch' | 'detached',
2626
public readonly repoPath: string,
2727
public readonly uri: Uri,
@@ -339,14 +339,14 @@ export function sortWorktrees(worktrees: GitWorktree[] | WorktreeQuickPickItem[]
339339

340340
export async function getWorktreesByBranch(
341341
repos: Repository | Repository[] | undefined,
342-
options?: { includeMainWorktree?: boolean },
342+
options?: { includeDefault?: boolean },
343343
) {
344344
const worktreesByBranch = new Map<string, GitWorktree>();
345345
if (repos == null) return worktreesByBranch;
346346

347347
async function addWorktrees(repo: Repository) {
348348
groupWorktreesByBranch(await repo.getWorktrees(), {
349-
includeMainWorktree: options?.includeMainWorktree,
349+
includeDefault: options?.includeDefault,
350350
worktreesByBranch: worktreesByBranch,
351351
});
352352
}
@@ -362,13 +362,13 @@ export async function getWorktreesByBranch(
362362

363363
export function groupWorktreesByBranch(
364364
worktrees: GitWorktree[],
365-
options?: { includeMainWorktree?: boolean; worktreesByBranch?: Map<string, GitWorktree> },
365+
options?: { includeDefault?: boolean; worktreesByBranch?: Map<string, GitWorktree> },
366366
) {
367367
const worktreesByBranch = options?.worktreesByBranch ?? new Map<string, GitWorktree>();
368368
if (worktrees == null) return worktreesByBranch;
369369

370370
for (const wt of worktrees) {
371-
if (wt.branch == null || (!options?.includeMainWorktree && wt.main)) continue;
371+
if (wt.branch == null || (!options?.includeDefault && wt.isDefault)) continue;
372372

373373
worktreesByBranch.set(wt.branch.id, wt);
374374
}

src/views/branchesView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class BranchesViewNode extends RepositoriesSubscribeableNode<BranchesView
6868
this.view.message = undefined;
6969

7070
// Get all the worktree branches (and track if they are opened) to pass along downstream, e.g. in the BranchNode to display an indicator
71-
const worktreesByBranch = await getWorktreesByBranch(repositories, { includeMainWorktree: true });
71+
const worktreesByBranch = await getWorktreesByBranch(repositories, { includeDefault: true });
7272
this.updateContext({
7373
worktreesByBranch: worktreesByBranch?.size ? worktreesByBranch : undefined,
7474
});

src/views/nodes/branchNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class BranchNode
139139
@memoize()
140140
get worktree(): GitWorktree | undefined {
141141
const worktree = this.context.worktreesByBranch?.get(this.branch.id);
142-
return worktree?.main ? undefined : worktree;
142+
return worktree?.isDefault ? undefined : worktree;
143143
}
144144

145145
private _children: ViewNode[] | undefined;
@@ -452,8 +452,8 @@ export class BranchNode
452452
}
453453
if (worktree != null) {
454454
contextValue += '+worktree';
455-
} else if (this.context.worktreesByBranch?.get(this.branch.id)?.main) {
456-
contextValue += '+main';
455+
} else if (this.context.worktreesByBranch?.get(this.branch.id)?.isDefault) {
456+
contextValue += '+checkedout';
457457
}
458458
// TODO@axosoft-ramint Temporary workaround, remove when our git commands work on closed repos.
459459
if (this.repo.closed) {

src/views/nodes/worktreeNode.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ export class WorktreeNode extends CacheableChildrenViewNode<'worktree', ViewsWit
200200
tooltip.isTrusted = true;
201201

202202
const indicators =
203-
this.worktree.main || this.worktree.opened
203+
this.worktree.isDefault || this.worktree.opened
204204
? ` \u00a0(${
205-
this.worktree.main
206-
? `_main${this.worktree.opened ? ', active_' : '_'}`
205+
this.worktree.isDefault
206+
? `_default${this.worktree.opened ? ', active_' : '_'}`
207207
: this.worktree.opened
208208
? '_active_'
209209
: ''
@@ -219,15 +219,17 @@ export class WorktreeNode extends CacheableChildrenViewNode<'worktree', ViewsWit
219219
switch (this.worktree.type) {
220220
case 'bare':
221221
icon = new ThemeIcon('folder');
222-
tooltip.appendMarkdown(`${this.worktree.main ? '$(pass) ' : ''}Bare Worktree${indicators}${folder}`);
222+
tooltip.appendMarkdown(
223+
`${this.worktree.isDefault ? '$(pass) ' : ''}Bare Worktree${indicators}${folder}`,
224+
);
223225
break;
224226

225227
case 'branch': {
226228
const { branch } = this.worktree;
227229
this._branch = branch;
228230

229231
tooltip.appendMarkdown(
230-
`${this.worktree.main ? '$(pass) ' : ''}Worktree for $(git-branch) \`${
232+
`${this.worktree.isDefault ? '$(pass) ' : ''}Worktree for $(git-branch) \`${
231233
branch?.getNameWithoutRemote() ?? branch?.name
232234
}\`${indicators}${folder}`,
233235
);
@@ -315,7 +317,7 @@ export class WorktreeNode extends CacheableChildrenViewNode<'worktree', ViewsWit
315317
case 'detached': {
316318
icon = new ThemeIcon('git-commit');
317319
tooltip.appendMarkdown(
318-
`${this.worktree.main ? '$(pass) ' : ''}Detached Worktree at $(git-commit) ${shortenRevision(
320+
`${this.worktree.isDefault ? '$(pass) ' : ''}Detached Worktree at $(git-commit) ${shortenRevision(
319321
this.worktree.sha,
320322
)}${indicators}${folder}`,
321323
);
@@ -348,7 +350,7 @@ export class WorktreeNode extends CacheableChildrenViewNode<'worktree', ViewsWit
348350
const item = new TreeItem(this.worktree.name, TreeItemCollapsibleState.Collapsed);
349351
item.id = this.id;
350352
item.description = description;
351-
item.contextValue = `${ContextValues.Worktree}${this.worktree.main ? '+main' : ''}${
353+
item.contextValue = `${ContextValues.Worktree}${this.worktree.isDefault ? '+default' : ''}${
352354
this.worktree.opened ? '+active' : ''
353355
}`;
354356
item.iconPath =

src/views/viewCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ export class ViewCommands {
597597
if (!node.is('worktree')) return undefined;
598598

599599
const worktrees = nodes?.length ? nodes.map(n => n.worktree) : [node.worktree];
600-
const uris = worktrees.filter(w => !w.main && !w.opened).map(w => w.uri);
600+
const uris = worktrees.filter(w => !w.isDefault && !w.opened).map(w => w.uri);
601601
return WorktreeActions.remove(node.repoPath, uris);
602602
}
603603

0 commit comments

Comments
 (0)