Skip to content

Commit c937d1d

Browse files
Open worktree in current or new window command (microsoft#257139)
* open worktree in window * open worktree refinements
1 parent dd45ba7 commit c937d1d

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

extensions/git/package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@
117117
"category": "Git",
118118
"enablement": "!operationInProgress"
119119
},
120+
{
121+
"command": "git.openWorktree",
122+
"title": "%command.openWorktree%",
123+
"category": "Git",
124+
"enablement": "!operationInProgress"
125+
},
126+
{
127+
"command": "git.openWorktreeInNewWindow",
128+
"title": "%command.openWorktreeInNewWindow%",
129+
"category": "Git",
130+
"enablement": "!operationInProgress"
131+
},
120132
{
121133
"command": "git.refresh",
122134
"title": "%command.refresh%",
@@ -1035,6 +1047,14 @@
10351047
"command": "git.closeOtherRepositories",
10361048
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount > 1"
10371049
},
1050+
{
1051+
"command": "git.openWorktree",
1052+
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount > 1"
1053+
},
1054+
{
1055+
"command": "git.openWorktreeInNewWindow",
1056+
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount > 1"
1057+
},
10381058
{
10391059
"command": "git.refresh",
10401060
"when": "config.git.enabled && !git.missing && gitOpenRepositoryCount != 0"
@@ -1667,6 +1687,16 @@
16671687
"command": "git.closeOtherRepositories",
16681688
"group": "navigation@2",
16691689
"when": "scmProvider == git && gitOpenRepositoryCount > 1"
1690+
},
1691+
{
1692+
"command": "git.openWorktree",
1693+
"group": "worktree@1",
1694+
"when": "scmProvider == git && gitOpenRepositoryCount > 1"
1695+
},
1696+
{
1697+
"command": "git.openWorktreeInNewWindow",
1698+
"group": "worktree@2",
1699+
"when": "scmProvider == git && gitOpenRepositoryCount > 1"
16701700
}
16711701
],
16721702
"scm/resourceGroup/context": [
@@ -2575,6 +2605,16 @@
25752605
}
25762606
],
25772607
"git.worktrees": [
2608+
{
2609+
"when": "scmProviderContext == worktree",
2610+
"command": "git.openWorktree",
2611+
"group": "openWorktrees@1"
2612+
},
2613+
{
2614+
"when": "scmProviderContext == worktree",
2615+
"command": "git.openWorktreeInNewWindow",
2616+
"group": "openWorktrees@2"
2617+
},
25782618
{
25792619
"when": "scmProviderContext == repository",
25802620
"command": "git.createWorktree",

extensions/git/package.nls.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"command.reopenClosedRepositories": "Reopen Closed Repositories...",
1111
"command.close": "Close Repository",
1212
"command.closeOtherRepositories": "Close Other Repositories",
13+
"command.openWorktree": "Open Worktree in Current Window",
14+
"command.openWorktreeInNewWindow": "Open Worktree in New Window",
1315
"command.refresh": "Refresh",
1416
"command.openChange": "Open Changes",
1517
"command.openAllChanges": "Open All Changes",

extensions/git/src/commands.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3481,6 +3481,27 @@ export class CommandCenter {
34813481
}
34823482
}
34833483

3484+
@command('git.openWorktree', { repository: true })
3485+
async openWorktreeInCurrentWindow(repository: Repository, ...args: SourceControl[]): Promise<void> {
3486+
// If multiple repositories are selected, no action is taken
3487+
if (args.length > 0) {
3488+
return;
3489+
}
3490+
3491+
const uri = Uri.file(repository.root);
3492+
await commands.executeCommand('vscode.openFolder', uri, { forceReuseWindow: true });
3493+
}
3494+
3495+
@command('git.openWorktreeInNewWindow', { repository: true })
3496+
async openWorktreeInNewWindow(repository: Repository, ...args: SourceControl[]): Promise<void> {
3497+
// If multiple repositories are selected, no action is taken
3498+
if (args.length > 0) {
3499+
return;
3500+
}
3501+
3502+
const uri = Uri.file(repository.root);
3503+
await commands.executeCommand('vscode.openFolder', uri, { forceNewWindow: true });
3504+
}
34843505

34853506
@command('git.graph.deleteTag', { repository: true })
34863507
async deleteTag2(repository: Repository, historyItem?: SourceControlHistoryItem, historyItemRefId?: string): Promise<void> {

0 commit comments

Comments
 (0)