Skip to content

fix(cleanup): find a squash-merged worktree when the base moved around it (#382) - #383

Merged
baldurpan merged 2 commits into
mainfrom
382-cleanup-misses-a-squash-merged-worktree-when-the
Nov 30, 2026
Merged

baldurpan merged 2 commits into
mainfrom
382-cleanup-misses-a-squash-merged-worktree-when-the

Conversation

@baldurpan

Copy link
Copy Markdown
Contributor

Closes #382

What changed

  • src/lib/git.ts findMergedBase now 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 as merge=ours, which would otherwise make a branch carrying unique work look merged. The git cherry patch-id probe remains as the fallback for a merge that conflicts and for git older than 2.38.
  • src/commands/cleanup.ts adds 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 .git is 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.
  • Tests for both parts, docs/.../commands/cleanup.mdx, skills/worktree/SKILL.md, and a patch changeset.

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:

    • In the issue's shape, where main changed a nearby line before the squash, both merges give the base tree, while git cherry still says +.
    • With a keep-ours driver, the forward merge gives the base tree and the reverse merge does not, so the branch is not called merged.
  • Gate 2: a reviewer subagent returned FAIL on loop 1 with three blocking items:

    • the one-sided merge driver;
    • docs that overclaimed the conflict-fix case;
    • an untested exclusion against the canceled-issue heading.

    All three were fixed. Loop 2 returned PASS WITH NOTES, and its two wording notes were applied.

Release notes checked

  • src/** and skills/**: patch note .changeset/quiet-trees-merge.md (level confirmed).
  • docs/**: owes none.

Left open (non-blocking, from review)

  • A branch whose net diff is empty, such as a commit and its revert, now reads as "merged into " and is removable. The old probe held it back. Nothing at the tip is lost, but the reverted commit's history is. Whether to keep holding those back is the maintainer's call.
  • Each fixture that already ran the merged probe without declaring it still prints "Unexpected subprocess calls" noise in git.test.ts. That predates this change, and the tests pass.

…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

@baldurs-reviewer baldurs-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread src/lib/git.ts Resolved
…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.

@baldurs-reviewer baldurs-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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


Reviewed c0a36c9 (changes since 24af714) for baldurpan · claude-opus-5-5 · 3 files

@baldurpan
baldurpan merged commit 7c61a24 into main Nov 30, 2026
2 checks passed
@baldurpan
baldurpan deleted the 382-cleanup-misses-a-squash-merged-worktree-when-the branch November 30, 2026 17:18
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.

cleanup misses a squash-merged worktree when the base changed lines next to its diff

1 participant