Skip to content

Commit dbf8155

Browse files
danielrose7claude
andauthored
feat(hooks): add preRemoveCmd lifecycle hook (#50)
* feat(hooks): add preRemoveCmd lifecycle hook Mirrors the postCreateCmd pattern but runs before worktree removal. The command executes inside the worktree directory and supports the same $BASE_PATH / $WORKTREE_PATH variables. If it fails or is cancelled, removal is aborted so users can react to cleanup errors (for example, tearing down a per-worktree database). * feat(l10n): add translations for preRemoveCmd strings Add zh-cn, zh-tw, and ja translations for the three new vscode.l10n.t() strings in preRemoveWorktree.ts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2f135fd commit dbf8155

13 files changed

Lines changed: 113 additions & 4 deletions

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ Customize Git Worktree Manager to fit your workflow:
103103
(for example, installing dependencies or running setup scripts).
104104
**Example:** `"pnpm install"` or `"echo 'Worktree ready'"`
105105

106+
- **`git-worktree-manager.preRemoveCmd`**
107+
Run a command automatically before a worktree is removed
108+
(for example, tearing down side effects such as a per-worktree database
109+
schema or stopping services).
110+
Runs inside the worktree directory. If the command fails or is cancelled,
111+
the removal is aborted.
112+
**Example:** `"pnpm run worktree:teardown-db"`
113+
106114
- **`terminal.external.windowsExec`**
107115
Set the external terminal on Windows
108116
(e.g. `"C:\\Program Files\\Git\\bin\\bash.exe"` for Git Bash).

README.zh-CN.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ Git Worktree Manager 将 worktree 管理能力直接集成到 VS Code 中,
102102
(例如安装依赖或运行初始化脚本)。
103103
**示例:** `"pnpm install"``"echo 'Worktree 已就绪'"`
104104

105+
- **`git-worktree-manager.preRemoveCmd`**
106+
在删除 worktree 前自动执行的命令
107+
(例如清理 worktree 产生的副作用,如每个 worktree 专属的数据库 schema,或停止服务)。
108+
命令在 worktree 目录内执行。若命令失败或被取消,则中止删除。
109+
**示例:** `"pnpm run worktree:teardown-db"`
110+
105111
- **`terminal.external.windowsExec`**
106112
设置 Windows 系统下的外部终端
107113
(例如 Git Bash: `"C:\\Program Files\\Git\\bin\\bash.exe"`)。

l10n/bundle.l10n.ja.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,8 @@
150150
"Delete": "削除",
151151
"Prune": "整理",
152152
"Remove": "削除",
153-
"Running post-create command...": "post-create コマンドを実行中..."
153+
"Running post-create command...": "post-create コマンドを実行中...",
154+
"Running pre-remove command...": "pre-remove コマンドを実行中...",
155+
"Pre-remove command was cancelled": "pre-remove コマンドがキャンセルされました",
156+
"Pre-remove command failed: {0}": "pre-remove コマンドが失敗しました:{0}"
154157
}

l10n/bundle.l10n.zh-cn.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,8 @@
150150
"Delete": "删除",
151151
"Prune": "清理",
152152
"Remove": "移除",
153-
"Running post-create command...": "正在运行 post-create 命令..."
153+
"Running post-create command...": "正在运行 post-create 命令...",
154+
"Running pre-remove command...": "正在运行 pre-remove 命令...",
155+
"Pre-remove command was cancelled": "pre-remove 命令已取消",
156+
"Pre-remove command failed: {0}": "pre-remove 命令失败:{0}"
154157
}

l10n/bundle.l10n.zh-tw.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,8 @@
150150
"Delete": "刪除",
151151
"Prune": "清理",
152152
"Remove": "移除",
153-
"Running post-create command...": "正在運行 post-create 命令..."
153+
"Running post-create command...": "正在運行 post-create 命令...",
154+
"Running pre-remove command...": "正在運行 pre-remove 命令...",
155+
"Pre-remove command was cancelled": "pre-remove 命令已取消",
156+
"Pre-remove command failed: {0}": "pre-remove 命令失敗:{0}"
154157
}

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,9 +960,15 @@
960960
"default": "",
961961
"markdownDescription": "%config.postCreateCmd.description%"
962962
},
963-
"git-worktree-manager.terminalNameTemplate": {
963+
"git-worktree-manager.preRemoveCmd": {
964964
"order": 14,
965965
"type": "string",
966+
"default": "",
967+
"markdownDescription": "%config.preRemoveCmd.description%"
968+
},
969+
"git-worktree-manager.terminalNameTemplate": {
970+
"order": 15,
971+
"type": "string",
966972
"default": "$LABEL ⇄ $FULL_PATH",
967973
"markdownDescription": "%config.terminalNameTemplate.description%"
968974
}

package.nls.ja.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"config.worktreeSubdirectoryTemplate.description": "ワークツリーサブディレクトリ名のテンプレートです。使用可能な変数:\n\n- `$BASE_NAME`(リポジトリフォルダ名)\n- `$INDEX`(増分番号)。\n- `$REF_NAME` (参照名、ブランチ名やタグ名など)\n\n使用できない文字:/ \\ : * ? \" < > |",
105105
"config.worktreeSubdirectoryTemplate.patternErrorMessage": "テンプレートに次の文字は使用できません:/ \\ : * ? \" < > |",
106106
"config.postCreateCmd.description": "ワークツリー作成後に実行するコマンド。デフォルトでは、新しいワークツリーのディレクトリ内で実行されます。コマンドで使用できる変数:\n\n- `$BASE_PATH`:ワークツリーの完全パス\n- `$WORKTREE_PATH`:ワークツリーの完全パス\n- `$BASE_NAME`:ワークツリーのフォルダ名\n\n例:\n`git submodule update --init --recursive`",
107+
"config.preRemoveCmd.description": "ワークツリー削除前に実行するコマンド。ワークツリーのディレクトリ内で実行されます。コマンドが失敗またはキャンセルされた場合、削除は中止されます。コマンドで使用できる変数:\n\n- `$BASE_PATH`:メインリポジトリの完全パス\n- `$WORKTREE_PATH`:削除対象ワークツリーの完全パス\n\n例:\n`pnpm run worktree:teardown-db`",
107108
"config.worktreeDescriptionTemplate.description": "ワークツリーの説明テンプレートです。使用可能な変数:\n\n- `$FULL_PATH`:ワークツリーの完全パス\n- `$BASE_NAME`:ワークツリーのフォルダ名\n- `$RELATIVE_PATH`:相対パス(メインリポジトリのルートからの相対パス)",
108109
"config.terminalNameTemplate.description": "内蔵ターミナルの名称テンプレートです。使用可能な変数:\n\n- `$FULL_PATH`:フォルダの完全パス\n- `$BASE_NAME`:フォルダ名\n- `$LABEL`:表示名、フォルダ名またはワークツリーの表示名"
109110
}

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"config.worktreeSubdirectoryTemplate.description": "Template for worktree subdirectory names. Available variables:\n\n- `$BASE_NAME` (repo folder name)\n- `$INDEX` (incrementing number).\n- `$REF_NAME` (reference name, such as branch name, tag name)\n\nCannot contain characters: / \\ : * ? \" < > |",
105105
"config.worktreeSubdirectoryTemplate.patternErrorMessage": "Template cannot contain characters: / \\ : * ? \" < > |",
106106
"config.postCreateCmd.description": "Command to execute after creating a worktree. The default execution path is the directory of the newly created worktree. You can use the following variables in the command:\n\n- `$BASE_PATH`: The full path of the worktree.\n- `$WORKTREE_PATH`: The full path of the worktree.\n\nExample:\n`git submodule update --init --recursive`",
107+
"config.preRemoveCmd.description": "Command to execute before removing a worktree. Runs inside the worktree directory. If the command fails or is cancelled, removal is aborted. You can use the following variables in the command:\n\n- `$BASE_PATH`: The full path of the main repository.\n- `$WORKTREE_PATH`: The full path of the worktree being removed.\n\nExample:\n`pnpm run worktree:teardown-db`",
107108
"config.worktreeDescriptionTemplate.description": "Template for the worktree description. Available variables:\n\n- `$FULL_PATH`: The full path of the worktree.\n- `$BASE_NAME`: The folder name of the worktree.\n- `$RELATIVE_PATH`: The relative path (relative to the main repo directory).",
108109
"config.terminalNameTemplate.description": "Template for the terminal name. Available variables:\n\n- `$FULL_PATH`: The full path of the folder.\n- `$BASE_NAME`: The folder name.\n- `$LABEL`: The display name, the folder name or the worktree display name."
109110
}

package.nls.zh-cn.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"config.worktreeSubdirectoryTemplate.description": "Worktree 子目录名称的模板。可用的变量:\n\n- `$BASE_NAME`(仓库文件夹名称)\n- `$INDEX`(递增数字)。\n- `$REF_NAME` (引用名称,如分支名、标签名)\n\n不能包含字符:/ \\ : * ? \" < > |",
105105
"config.worktreeSubdirectoryTemplate.patternErrorMessage": "模板不能包含以下字符:/ \\ : * ? \" < > |",
106106
"config.postCreateCmd.description": "创建 Worktree 后执行的命令,默认执行路径是新创建的 Worktree 的目录内。你可以在命令中使用以下变量:\n\n- `$BASE_PATH`:仓库的完整路径。\n- `$WORKTREE_PATH`:Worktree 的完整路径。\n\n示例:\n`git submodule update --init --recursive`",
107+
"config.preRemoveCmd.description": "删除 Worktree 前执行的命令,在 Worktree 目录内执行。如果命令执行失败或被取消,则中止删除操作。你可以在命令中使用以下变量:\n\n- `$BASE_PATH`:主仓库的完整路径。\n- `$WORKTREE_PATH`:即将被删除的 Worktree 的完整路径。\n\n示例:\n`pnpm run worktree:teardown-db`",
107108
"config.worktreeDescriptionTemplate.description": "Worktree 描述的模板。可用的变量:\n\n- `$FULL_PATH`:Worktree 的完整路径。\n- `$BASE_NAME`:Worktree 的文件夹名称。\n- `$RELATIVE_PATH`:相对路径(相对于主仓库目录)。",
108109
"config.terminalNameTemplate.description": "打开内置终端时显示的名称模板。可用的变量:\n\n- `$FULL_PATH`:文件夹的完整路径。\n- `$BASE_NAME`:文件夹名称。\n- `$LABEL`:展示的名称、文件夹名称或者 Worktree 展示的名称"
109110
}

package.nls.zh-tw.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"config.worktreeSubdirectoryTemplate.description": "Worktree 子目錄名稱的模板。可用的變數:\n\n- `$BASE_NAME`(倉庫資料夾名稱)\n- `$INDEX`(遞增數字)。\n- `$REF_NAME` (引用名稱,如分支名、標籤名)\n\n不能包含字元:/ \\ : * ? \" < > |",
105105
"config.worktreeSubdirectoryTemplate.patternErrorMessage": "範本不能包含以下字元:/ \\ : * ? \" < > |",
106106
"config.postCreateCmd.description": "建立 Worktree 後執行的命令。預設執行路徑是新建立的 Worktree 的目錄內。你可以在命令中使用以下變數:\n\n- `$BASE_PATH`:Worktree 的完整路徑。\n- `$WORKTREE_PATH`:Worktree 的完整路徑。\n\n範例:\n`git submodule update --init --recursive`",
107+
"config.preRemoveCmd.description": "移除 Worktree 前執行的命令,在 Worktree 目錄內執行。若命令執行失敗或被取消,則中止移除。你可以在命令中使用以下變數:\n\n- `$BASE_PATH`:主倉庫的完整路徑。\n- `$WORKTREE_PATH`:即將被移除的 Worktree 的完整路徑。\n\n範例:\n`pnpm run worktree:teardown-db`",
107108
"config.worktreeDescriptionTemplate.description": "Worktree 描述的模板。可用的變數:\n\n- `$FULL_PATH`:Worktree 的完整路徑。\n- `$BASE_NAME`:Worktree 的資料夾名稱。\n- `$RELATIVE_PATH`:相對路徑(相對於主倉庫目錄)。",
108109
"config.terminalNameTemplate.description": "開啟內建終端機時顯示的名稱模板。可用的變數:\n\n- `$FULL_PATH`:資料夾的完整路徑。\n- `$BASE_NAME`:資料夾名稱。\n- `$LABEL`:展示的名稱、資料夾名稱或者 Worktree 展示的名稱"
109110
}

0 commit comments

Comments
 (0)