Skip to content

Comments

feat: add wt.deletehook config and --deletehook flag#132

Merged
k1LoW merged 3 commits intok1LoW:mainfrom
ryoppippi:feat/add-delete-hook
Feb 16, 2026
Merged

feat: add wt.deletehook config and --deletehook flag#132
k1LoW merged 3 commits intok1LoW:mainfrom
ryoppippi:feat/add-delete-hook

Conversation

@ryoppippi
Copy link
Contributor

Summary

Add wt.delete-hook config and --delete-hook CLI flag to run custom commands before worktree deletion, mirroring the existing wt.hook creation hook pattern.

What Changed

  • internal/git/config.go: Added configKeyDeleteHook constant, DeleteHooks field to Config, and loading logic in LoadConfig()
  • cmd/root.go: Added --delete-hook flag, flag override in loadConfig(), wired hook execution into deleteWorktrees() before worktree removal, updated help text
  • e2e/config_test.go: Added TestE2E_DeleteHooks with 8 subtests and updated completion flag list

Design Decisions

  • Hooks run before worktree removal so the directory still exists and commands can execute inside it (e.g., git push origin --delete $(git branch --show-current))
  • 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 (no directory to execute in)
  • --delete-hook flag overrides wt.delete-hook config, consistent with --hook / wt.hook
  • Reuses the existing git.RunHooks() function — no changes needed to internal/git/hook.go

Usage

# Persistent via git config
git config --add wt.delete-hook "git push origin --delete $(git branch --show-current)"

# One-off via flag
git wt -D --delete-hook "echo cleaning up" my-branch

Test Plan

  • go build ./... compiles cleanly
  • go test ./... — all existing tests pass
  • 8 new e2e subtests pass: flag, config, multiple hooks, branch-only skip, flag-overrides-config, failure-prevents-deletion, working directory verification, stderr output

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
@k1LoW
Copy link
Owner

k1LoW commented Feb 12, 2026

@ryoppippi Thank you for your contribution! GREAT WORK!!!

I have one request that I feel bad about asking: could we rename wt.delete-hook to wt.deletehook (and --delete-hook to --deletehook )?

I totally agree that delete-hook is more readable, and I honestly wish we could keep it. However, git's official https://github.com/git/git/blob/master/Documentation/CodingGuidelines discourages hyphens in config variable names (the part after the dot).

Our existing keys (wt.basedir, wt.copyignored, wt.nocopy, etc.) also follow the no-hyphen convention, so I'd like to keep things consistent even at the cost of readability.

🙏

@k1LoW k1LoW added enhancement New feature or request tagpr:minor labels Feb 12, 2026
…deletehook`

Follow git's official CodingGuidelines which discourage hyphens in
config variable names (the part after the dot). This keeps the naming
consistent with existing keys: wt.basedir, wt.copyignored, wt.nocopy,
wt.hook, etc.

Requested by @k1LoW in PR k1LoW#132 review.
@ryoppippi
Copy link
Contributor Author

@k1LoW Thank you for your review!!! i fiexed it!!

@k1LoW k1LoW changed the title feat: add wt.delete-hook config and --delete-hook flag feat: add wt.deletehook config and --deletehook flag Feb 16, 2026
Copy link
Owner

@k1LoW k1LoW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!

@k1LoW k1LoW merged commit 8e7ca50 into k1LoW:main Feb 16, 2026
3 checks passed
@github-actions github-actions bot mentioned this pull request Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tagpr:minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants