diff --git a/package.json b/package.json index b95a8b5..5b21ad3 100644 --- a/package.json +++ b/package.json @@ -4861,6 +4861,11 @@ "icon": "$(empty-window)" }, { + "command": "gitlens.views.revealWorktreeInExplorer", + "title": "Reveal Worktree in File Explorer", + "category": "GitLens" + }, + { "command": "gitlens.views.cherryPick", "title": "Cherry Pick Commit...", "category": "GitLens" @@ -6652,6 +6657,10 @@ "when": "false" }, { + "command": "gitlens.views.revealWorktreeInExplorer", + "when": "false" + }, + { "command": "gitlens.views.createBranch", "when": "false" }, @@ -9542,6 +9551,11 @@ "group": "2_gitlens_quickopen@2" }, { + "command": "gitlens.views.revealWorktreeInExplorer", + "when": "viewItem =~ /gitlens:worktree\\b/", + "group": "3_gitlens@1" + }, + { "command": "gitlens.views.deleteWorktree", "when": "!gitlens:readonly && viewItem =~ /gitlens:worktree\\b(?!.*?\\b\\+(active|main)\\b)/", "group": "6_gitlens_actions@1" diff --git a/src/commands/gitCommands.actions.ts b/src/commands/gitCommands.actions.ts index 9027d49..1ecf3e9 100644 --- a/src/commands/gitCommands.actions.ts +++ b/src/commands/gitCommands.actions.ts @@ -7,7 +7,7 @@ import type { OpenWorkingFileCommandArgs, } from '../commands'; import { FileAnnotationType } from '../configuration'; -import { Commands } from '../constants'; +import { Commands, CoreCommands } from '../constants'; import { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { @@ -26,7 +26,7 @@ import { } from '../git/models'; import { RepositoryPicker } from '../quickpicks/repositoryPicker'; import { ensure } from '../system/array'; -import { executeCommand, executeEditorCommand } from '../system/command'; +import { executeCommand, executeCoreCommand, executeEditorCommand } from '../system/command'; import { findOrOpenEditor, findOrOpenEditors, openWorkspace, OpenWorkspaceLocation } from '../system/utils'; import { ViewsWithRepositoryFolders } from '../views/viewBase'; import { ResetGitCommandArgs } from './git/reset'; @@ -915,5 +915,9 @@ export namespace GitActions { : await Container.instance.repositoriesView.revealWorktree(worktree, options); return node; } + + export async function revealInFileExplorer(worktree: GitWorktree) { + void (await executeCoreCommand(CoreCommands.RevealInFileExplorer, worktree.uri)); + } } } diff --git a/src/constants.ts b/src/constants.ts index eab88e1..becf0af 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -266,6 +266,8 @@ export const enum CoreCommands { NextEditor = 'workbench.action.nextEditor', PreviewHtml = 'vscode.previewHtml', RevealLine = 'revealLine', + RevealInExplorer = 'revealInExplorer', + RevealInFileExplorer = 'revealFileInOS', SetContext = 'setContext', ShowExplorer = 'workbench.view.explorer', ShowReferences = 'editor.action.showReferences', diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index 4a0df22..1340aaf 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -232,6 +232,7 @@ export class ViewCommands { commands.registerCommand('gitlens.views.createWorktree', this.createWorktree, this); commands.registerCommand('gitlens.views.deleteWorktree', this.deleteWorktree, this); commands.registerCommand('gitlens.views.openWorktree', this.openWorktree, this); + commands.registerCommand('gitlens.views.revealWorktreeInExplorer', this.revealWorktreeInExplorer, this); commands.registerCommand( 'gitlens.views.openWorktreeInNewWindow', n => this.openWorktree(n, { location: OpenWorkspaceLocation.NewWindow }), @@ -329,6 +330,13 @@ export class ViewCommands { } @debug() + private revealWorktreeInExplorer(node: WorktreeNode) { + if (!(node instanceof WorktreeNode)) return undefined; + + return GitActions.Worktree.revealInFileExplorer(node.worktree); + } + + @debug() private async deleteWorktree(node: WorktreeNode) { if (!(node instanceof WorktreeNode)) return undefined;