feat: add wt.deletehook config and --deletehook flag#132
Merged
k1LoW merged 3 commits intok1LoW:mainfrom Feb 16, 2026
Merged
Conversation
Add support for running custom commands before worktree deletion, mirroring the existing `wt.hook` creation hook pattern. Hooks run in the worktree directory before it is removed, allowing cleanup tasks such as pushing branch deletions to the remote or tearing down local services. If a hook fails, the deletion is aborted and the worktree is preserved. Hooks do not run when deleting a branch without an associated worktree, since there is no directory to execute in. The `--delete-hook` flag overrides the `wt.delete-hook` git config, consistent with how `--hook` overrides `wt.hook`. Usage: git config --add wt.delete-hook "git push origin --delete \$(git branch --show-current)" git wt -D --delete-hook "echo cleaning up" my-branch
Owner
|
@ryoppippi Thank you for your contribution! GREAT WORK!!! I have one request that I feel bad about asking: could we rename I totally agree that Our existing keys ( 🙏 |
Contributor
Author
|
@k1LoW Thank you for your review!!! i fiexed it!! |
wt.delete-hook config and --delete-hook flagwt.deletehook config and --deletehook flag
Merged
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
Add
wt.delete-hookconfig and--delete-hookCLI flag to run custom commands before worktree deletion, mirroring the existingwt.hookcreation hook pattern.What Changed
internal/git/config.go: AddedconfigKeyDeleteHookconstant,DeleteHooksfield toConfig, and loading logic inLoadConfig()cmd/root.go: Added--delete-hookflag, flag override inloadConfig(), wired hook execution intodeleteWorktrees()before worktree removal, updated help texte2e/config_test.go: AddedTestE2E_DeleteHookswith 8 subtests and updated completion flag listDesign Decisions
git push origin --delete $(git branch --show-current))--delete-hookflag overrideswt.delete-hookconfig, consistent with--hook/wt.hookgit.RunHooks()function — no changes needed tointernal/git/hook.goUsage
Test Plan
go build ./...compiles cleanlygo test ./...— all existing tests pass