Repository navigation
fix(cleanup): find a squash-merged worktree when the base moved around it (#382) - #383
Conversation
…d it (#382) The merged check asked `git cherry` whether the branch's cumulative patch was in the base, and a patch-id includes the context lines around each change. Another pull request touching a line near the branch's diff before the squash landed made a fully merged branch answer `+`, so cleanup kept it. It now asks whether merging the branch into the base, both ways round, leaves the base's tree unchanged. The reverse merge guards against a one-sided merge driver. The cherry probe stays as the fallback for a merge that conflicts and for git older than 2.38. A worktree still held back because its commits were not found in the base, with no live remote, is now named under a fifth heading instead of being skipped without a word. Closes #382
There was a problem hiding this comment.
code-reviewer: minor issues
The change asks whether a branch is already merged by running git merge-tree --write-tree in both directions and checking that each result is the base's tree, falling back to the git cherry patch-id probe. It also adds a fifth cleanup heading that names worktrees with no live remote whose commits were not found in the base. The merge-tree check and the new heading are correct, and the heading's exclusions line up with the other four sets and are tested. My main reservation is that the cherry fallback also runs after the merge-tree check has cleanly answered "this would change the base", which is wider than the description and the docs say.
Reviewed 24af714 for baldurpan · claude-opus-5-5 · 7 files
…382) A clean merge that does not come back with the base's tree has found content the base lacks. git cherry was still consulted then, and a branch squash-merged and then reverted on the base read as merged. The merge check now answers merged, differs or unknown, and only unknown falls back to the patch comparison. Also drops a cleanup.mdx sentence that named the same set twice.
There was a problem hiding this comment.
code-reviewer follow-up: looks good
Since the last review, findMergedBase asks git cherry only when the in-memory merge gave no answer: a conflict, a git too old for --write-tree, or a reverse merge that could not be taken. A clean merge that differs, in either direction, is now a confident no. The tests and the cleanup page were updated to match, and the duplicated sentence on the cleanup page is gone. I traced each exit of compareMergeResult (including the empty-output, rejected rev-parse and pre-2.38 paths) and found nothing further; the change looks ready.
Earlier comments
- Fixed; yours to resolve: Risk: Cherry fallback also overrides a clean "merge changes the base" answer, wider than documented
- Fixed; yours to resolve: Suggestion: Rewritten sentence now says the same thing twice
Reviewed c0a36c9 (changes since 24af714) for baldurpan · claude-opus-5-5 · 3 files
Closes #382
What changed
src/lib/git.tsfindMergedBasenow asks first whether merging the branch into the base changes anything:git merge-tree --write-tree <base> <rev>has to produce<base>^{tree}, and so does the reverse merge<rev> <base>. The reverse catches a one-sided merge driver such asmerge=ours, which would otherwise make a branch carrying unique work look merged. Thegit cherrypatch-id probe remains as the fallback for a merge that conflicts and for git older than 2.38.src/commands/cleanup.tsadds a fifth hold-back heading:Skipped N worktree branch(es) with unpushed commits not found in <base>. A worktree lands there when it has no live remote, is ahead of its base, wasn't found merged, and isn't claimed by another heading. A record whose.gitis missing (remove, list and cleanup fail when a worktree directory has lost its .git file #368) is included. Before this, such a worktree was skipped without a word.docs/.../commands/cleanup.mdx,skills/worktree/SKILL.md, and apatchchangeset.Verification
Gate 1 (
context/verify.md):pnpm check,pnpm typecheck,pnpm --filter docs typecheck,pnpm build,pnpm docs:build,worker:bundle-check,pnpm docs:audit-dist,pnpm test(4155 passed),pnpm docs:test(1861 passed). All exit 0.Real git (2.56.1), outside the suite:
git cherrystill says+.Gate 2: a reviewer subagent returned FAIL on loop 1 with three blocking items:
All three were fixed. Loop 2 returned PASS WITH NOTES, and its two wording notes were applied.
Release notes checked
src/**andskills/**: patch note.changeset/quiet-trees-merge.md(level confirmed).docs/**: owes none.Left open (non-blocking, from review)
git.test.ts. That predates this change, and the tests pass.