Repository navigation
Conversation
A branch landed by Bitbucket's "Rebase, fast-forward" or GitHub's "Rebase and merge" arrives on the default branch as new commits. Once the default branch edits the same lines again, every existing check misses it: it is not an ancestor, `merge-tree` conflicts, and no single target commit holds the branch's combined diff, so `PatchIdMatch` fails too. `wt step prune` and `wt remove` then keep such branches indefinitely, and `wt list` shows them as `✗` rather than `⊂`, although `git cherry` reports every commit as already upstream. Add a seventh check, `CommitsMatch` (`commits_match` in JSON), evaluated in the same patch-id fallback, after `PatchIdMatch`. A branch counts as integrated when every commit in `merge_base..branch` has a distinct target commit in `merge_base..target` with the same `patch-id --verbatim`: - Patch-id equality is the only evidence, matched as a multiset, so each target commit vouches for one branch commit. - A commit without a patch-id fails the check: an empty commit, or a merge, whose conflict resolution no patch-id covers. - The merge-tree gate is unchanged: a clean merge that would change the target still means "not integrated". - The branch's commits ride the target-side `diff-tree --stdin | patch-id` pipe that already runs, under the existing 500-commit cap; the extra cost is one `rev-list` over the branch's own commits. `MergeProbeResult` gains a required field, so cached entries written before it read as misses and old negatives are recomputed once.
… identity The per-commit patch-id check only ran within the 500-commit cap, so a rebase-merged branch whose merge point has since fallen further behind the default branch stayed undetected. A rebase, a cherry-pick and a forge's rebase merge all keep the author name, email and time. So past the cap, diff only the target commits that share an author identity with a branch commit, at most 500 of them: - A header-only `rev-list --format=%H %at %ae` walk replaces the `rev-list --count` pre-flight. Its length is the count, and it stops listing at 10,000 commits, past which both checks give up. - When some branch commit's identity is absent from the target, the branch is rejected without diffing anything: the common case for a stale branch that was never merged. - The identity only selects candidates. Patch-ids still decide, so an amended commit that kept its author time is not a match. - Within the cap nothing changes: every target commit is diffed, which the squash check needs and which also finds rebase merges that reset author times. On this repository's history, the header walk costs 18 ms against 18 ms for `--count` 299 commits back, 70 against 50 ms 2,000 back, and 120 against 81 ms 5,000 back; the branch-side walk adds about 10 ms.
worktrunk-bot
left a comment
Collaborator
There was a problem hiding this comment.
Holding this for a maintainer decision. CommitsMatch widens which branches wt remove and wt step prune delete without -D. The repo's review policy reserves that call for @max-sixty, so this is a comment, not an approval.
One trade-off to weigh: suppose main lands a branch's commits, reverts one of them, and later edits lines another one touched. Merge-tree then conflicts, every commit still has a twin, and the branch is deleted. The reverted content survives only in main's history. The squash check already accepts the same shape (squash, revert, re-edit), so this extends that trade-off to rebase merges rather than adding a new one.
This branch has not been deployed
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.
Problem
With a rebase-merge workflow (GitHub "Rebase and merge", Bitbucket "Rebase, fast-forward"), a multi-commit branch lands on the default branch as new commits. Once the default branch edits the same lines again, none of the six integration checks match:
git merge-treeconflicts, soMergeAddsNothingcan't apply,PatchIdMatch(squash detection) fails.git cherry main <branch>prints only-lines, yetwt step pruneandwt removekeep the branch, andwt listshows✗instead of⊂. On a Bitbucket-hosted monorepo that rebase-merges every PR, worktrees of merged branches pile up: seven such branches there (2–6 commits each, 105–935 commits behind the default branch) are kept, although every one of their commits has apatch-id --verbatimtwin on the default branch.I found no existing issue or PR for rebase-merged multi-commit branches. #4437 reworks the squash scan past the cap and is orthogonal to this; whichever lands second rebases.
Change
A seventh check,
commits_match(IntegrationReason::CommitsMatch), evaluated inside the existing patch-id fallback, so only branches whosemerge-treeconflicts reach it. A branch counts as integrated when every commit inmerge-base..branchhas a distinct commit inmerge-base..targetwith the samepatch-id --verbatim.Safety argument — this loosens the check that lets
wt remove/wt step prunedelete a branch without-D, so it needs a maintainer's call under the data-loss review policy:+X, −X, +Xagainst target+X, −Xis kept.diff-tree --stdinemits no patch for a merge, whose conflict resolution no patch-id covers).diff-tree | patch-idpipe, sodiff.*config can't skew the ids (same guarantee as fix(integration): make squash-merge detection immune to diff.* git config #2821 / fix(git): run diffs through plumbing so user git config can't change what wt reads #4146).PatchIdMatchkeeps precedence, so a one-commit branch reports exactly what it reports today.The tests pin each refusal: partial landing, a commit added after the merge, repeated patches, a merge on the branch, an empty commit, amended content with the same author identity, and a revert without later edits. I mutation-checked them: replacing the multiset with a set, accepting a commit without a patch-id, ranking
CommitsMatchabovePatchIdMatch, adding#[serde(default)]to the new cache field, treating author identity as evidence, and an off-by-one at the walk cap each fail a test.Cost
The two commits can land separately.
1.
feat(integration)— the per-commit check under the existing 500-commit cap. The branch's own commits ride the target-sidediff-tree --stdin | patch-idpipe that already runs, so the only new process is onerev-listover the branch's own commits. No new full-range diff.2.
perf(integration)— past the cap, select candidates by author identity. Rebase, cherry-pick and forge rebase merges keep the author name, email and date. A header-onlyrev-list --format=%H %at %aewalk replaces therev-list --countpre-flight, and past 500 commits only target commits sharing a branch commit's author identity are diffed (at most 500). A never-merged stale branch is rejected with no diffing at all. The walk stops at 10,000 commits (the range cap #4100 and #4437 chose). The identity only selects candidates; patch-ids still decide.Timings of those git commands on this repository's own history (Linux, median of 7 runs, no commit-graph):
rev-list --count(before)Under the cap, appending a three-commit branch to the existing target pipe took it from 1547 ms to 1562 ms. The worst case, a never-merged conflicting branch 500–10,000 commits behind, goes from one
--countto the header walk plus the branch walk: about 1.6×, +30–50 ms. Because candidates past the cap are chosen by author identity rather than by path, the stale lockfile-bump case discussed on #4437 diffs nothing unless one of its commits actually landed.MergeProbeResultgains a required field, so cached probe entries written before it read as misses and old negatives are recomputed once (pinned by a cache test).Docs
wt remove --helplists the seventh condition and the reworded cap sentence;wt list --helpand the JSON schema gaincommits_match. Mirrors and help snapshots are regenerated.Out of scope: amended commits whose patch changed (matching on subject or author would delete unique content), and non-default targets (#4637).