feat: add preRemoveCmd lifecycle hook#50
Merged
jackiotyu merged 2 commits intojackiotyu:mainfrom Apr 14, 2026
Merged
Conversation
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).
Owner
|
@danielrose7 Hi, thanks for the PR—nice work! It's just missing some translations. Could you please add those? I'll merge it right after you're done. |
jackiotyu
reviewed
Apr 14, 2026
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>
Contributor
Author
|
@jackiotyu Added translations for all three new
These mirror the existing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
git-worktree-manager.preRemoveCmdsetting that mirrors the existingpostCreateCmd, but runs before a worktree is removed. If the command fails or is cancelled, removal is aborted.Motivation
When several worktrees run at once, they'd clash in the database. We give each worktree its own Postgres schema to keep them separate. Dropping the worktree without first dropping its schema leaves junk behind. A pre-remove hook lets a cleanup script run before the folder is deleted, and cancels the removal if cleanup fails.
Behavior
git-worktree-manager.preRemoveCmd(string, default"")cwd = worktreePath)postCreateCmd:$BASE_PATH— main repo path$WORKTREE_PATH— worktree path being removedAlert.showErrorMessagepath andgit worktree removeis not called — no partial state.postCreateWorktree.ts(sameexec+AbortController+ progress wrapper) for consistency.Files changed
src/core/util/preRemoveWorktree.ts— new (mirrorspostCreateWorktree.ts)src/core/command/removeWorktreeCmd.ts— invokes hook beforeremoveWorktree()src/core/config/setting.ts— typed config accessorpackage.json— config schema entrypackage.nls.json,package.nls.zh-cn.json,package.nls.zh-tw.json,package.nls.ja.json— description strings (happy to have native speakers polish zh/ja — I matched the existing style)README.md,README.zh-CN.md— docs entry next topostCreateCmdDesign notes
postRemoveCmdis intentionally not added. Once the worktree directory is gone, a post-remove hook has no naturalcwdand its variables refer to a deleted path. Happy to add it later withcwd = mainFolderif there's demand.Test plan
pnpm run check-typespassespnpm run lintpassespreRemoveCmdunset, removal behaves exactly as beforepreRemoveCmd = "echo hi > /tmp/pre.log", file is created withcwd= worktree and removal proceedspreRemoveCmd = "exit 1", removal is aborted and error is shown$WORKTREE_PATH/$BASE_PATHsubstitute correctly