Skip to content

fix: detect squash merges in --merged, add multi-target remove and --on-dirty#58

Merged
guodong-sq merged 1 commit intomainfrom
guodong/fix-merged-and-multi-remove
Mar 24, 2026
Merged

fix: detect squash merges in --merged, add multi-target remove and --on-dirty#58
guodong-sq merged 1 commit intomainfrom
guodong/fix-merged-and-multi-remove

Conversation

@guodong-sq
Copy link
Collaborator

@guodong-sq guodong-sq commented Mar 24, 2026

Summary

  • Fix --merged to detect squash merges: git branch --merged only checks commit ancestry, so squash-merged branches were invisible. Now uses git commit-tree + git cherry to detect them.
  • Multi-target wt remove: wt remove branch1 branch2 branch3 removes multiple worktrees in one invocation, skipping invalid targets gracefully.
  • --on-dirty=warn|skip|remove flag: Unified dirty worktree handling across --merged and explicit paths (default: warn prompts the user).
  • Unified removal logic: Extracted _do_remove_worktree shared helper, fixing a bug where --merged didn't fix the active symlink after removal.
  • Shell completions: Added --on-dirty= completion with value suggestions, fixed zsh multi-arg.
  • Help text: Updated with new features and examples.
  • 11 new integration tests (26 total, was 16) covering squash-merge detection, multi-target, --on-dirty modes, symlink fixup regression, and branch name resolution.

Test plan

  • All 26 wt-remove integration tests pass
  • Full suite green (314/314 tests)
  • Manual: wt remove --merged on a repo with squash-merged worktrees
  • Manual: wt remove branch1 branch2 with mix of valid/invalid targets
  • Manual: wt remove --on-dirty=skip with dirty worktree

🤖 Generated with Claude Code

…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>
@guodong-sq guodong-sq force-pushed the guodong/fix-merged-and-multi-remove branch from 7ea597e to 1e63673 Compare March 24, 2026 04:24
@guodong-sq guodong-sq merged commit a805e70 into main Mar 24, 2026
5 checks passed
@guodong-sq guodong-sq deleted the guodong/fix-merged-and-multi-remove branch March 24, 2026 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant