fix: detect squash merges in --merged, add multi-target remove and --on-dirty#58
Merged
guodong-sq merged 1 commit intomainfrom Mar 24, 2026
Merged
Conversation
…on-dirty `wt remove --merged` failed to detect squash-merged branches because `git branch --merged` only checks commit ancestry. Add squash-merge detection using `git commit-tree` + `git cherry` to create a synthetic squash commit and check if it's already applied to the base branch. Also: - Accept multiple worktree/branch arguments (`wt remove a b c`) with skip-on-not-found behavior for invalid targets - Add `--on-dirty=warn|skip|remove` flag (default: warn) to control dirty worktree handling consistently across --merged and explicit paths - Unify removal logic into shared `_do_remove_worktree` helper, fixing a bug where --merged path didn't fix the active symlink - Auto-cd to main repo when cwd is inside a removed worktree (via `__wt_do_remove` wrapper in wt.sh, same pattern as `__wt_do_cd`) - Use `git branch -D` for squash-merged branches in --merged mode since `git branch -d` fails on them - Context-specific --on-dirty tips (skip on decline, remove on accept) - Update shell completions (bash/zsh) with --on-dirty and multi-arg - Update help text with new features and examples - Add 11 new integration tests (26 total, was 16) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7ea597e to
1e63673
Compare
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
--mergedto detect squash merges:git branch --mergedonly checks commit ancestry, so squash-merged branches were invisible. Now usesgit commit-tree+git cherryto detect them.wt remove:wt remove branch1 branch2 branch3removes multiple worktrees in one invocation, skipping invalid targets gracefully.--on-dirty=warn|skip|removeflag: Unified dirty worktree handling across--mergedand explicit paths (default:warnprompts the user)._do_remove_worktreeshared helper, fixing a bug where--mergeddidn't fix the active symlink after removal.--on-dirty=completion with value suggestions, fixed zsh multi-arg.--on-dirtymodes, symlink fixup regression, and branch name resolution.Test plan
wt-removeintegration tests passwt remove --mergedon a repo with squash-merged worktreeswt remove branch1 branch2with mix of valid/invalid targetswt remove --on-dirty=skipwith dirty worktree🤖 Generated with Claude Code