Skip to content

merge_check: a merge that main has reverted no longer counts as a prior merge - #8807

Open
berkay8987 wants to merge 2 commits into
ItsNotRexed:mainfrom
berkay8987:merge-check-reverted-merges
Open

berkay8987 wants to merge 2 commits into
ItsNotRexed:mainfrom
berkay8987:merge-check-reverted-merges

Conversation

@berkay8987

@berkay8987 berkay8987 commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as: new BUILD item, #8683 (comment)

Depends on: #7468, #7660 and #7918 (other authors) and #8564 and #8666 (mine), in the sense the template asks for: each edits scripts/merge_check.py next to the lines this one does and git merge-tree reports a conflict. None is a code dependency. Whichever of mine lands second I will rebase myself.

What and why

Updated in 35f701bc after review: reverts pair with the commit they name, a reapplied merge stands again, and with a revert in the history already-merged needs a matching merged tree.

prior_merges() counts every merge of the PR on main, including one that a later commit reverted. main has 14 reverts of PR merges ("Revert #N: why", and git's Revert "Merge pull request #N ..."), and three of those PRs are open again: #2490, #3402 and #4247. A reverted PR proposed again unchanged then reads already-merged, so the re-land looks like a merge to skip although its code is off main. In throwaway repos:

merged with, then reverted merging the same branch again before after
a squash merge adds the code back already-merged clean, with the merge and its revert listed
a merge commit changes nothing (the branch is still in main's history) already-merged reverted

The second row is a git subtlety worth its own verdict: once a merge commit has been reverted, merging the same branch again is a no-op, so a re-land takes reverting the revert, or new commits.

  • A revert that names the commit it undoes ("This reverts commit .", as git writes it) undoes exactly that commit. One that names none, like the maintainer's Revert #N: why, pairs with the PR's newest merge still standing. Either way that merge leaves merges, and the pair is reported in a new reverted field, newest first.
  • Reverting a revert puts its merge back, found by the commit it names or by its subject (Reapply "...", or older git's Revert "Revert "..."").
  • With a revert in a PR's history, already-merged needs the merged tree to match main, since the PR's patches stay in main's history after the revert.
  • reverted verdict: a merge was reverted and the merged tree matches main, i.e. the branch is still in main's history. It ranks after already-merged.
  • The text line says merged at <merge> and reverted at <revert>.
  • A revert of a revert, and one that names no PR ("Revert 33 oracle-only semantic tests ..."), pair with nothing.

On the three open PRs the verdicts do not change, since all three have new commits since their revert; the report now names the revert. Against main 867d922f:

PR before after
#2490 clean, merged before at 336733ccc554 clean, merged at 336733ccc554 and reverted at 57c175391db7
#3402 clean, merged before at 2ba614f8a65e clean, merged at 2ba614f8a65e and reverted at 26488f74fd70
#4247 clean, merged before at ee067ef34f40 clean, merged at ee067ef34f40 and reverted at ab1c07eb6581

Tested

AI-assisted: yes (Claude Code)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator rule here.)

🤖 Generated with Claude Code

…or merge

A PR merged and then reverted kept its merge in `merges`, so the same
branch proposed again read `already-merged`: a re-land looked like a
merge to skip although its code was off main. Pair each revert
("Revert #N: why", or git's `Revert "<the merge's subject>"`) with the
latest earlier merge of its PR, leave that merge out of `merges`, and
report the pairs as `reverted`.

A merge commit that was reverted leaves the branch in main's history,
so merging the same branch again changes nothing; that reads
`reverted`, since a re-land takes reverting the revert or new commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LightAndy1

Copy link
Copy Markdown

Tested 8ba1089 on Windows (CPython 3.14.7, CPU only, no game files): pass.

  • python -I tests/test_merge_check.py -> 20/20 OK (includes the 4 new revert-pairing tests)
  • python -m compileall -q scripts/merge_check.py tests/test_merge_check.py -> OK
  • python -I scripts/check_no_game_data.py scripts/merge_check.py tests/test_merge_check.py -> OK
  • git diff --check HEAD~1..HEAD -> clean
  • Code read: prior_merges walks first-parent log oldest-first and pops the preceding merge when a matching Revert #N or Revert <subject> appears, adding the reverted verdict when the branch is already in main history.

Fully AI-automated run and report (model: Gemini 4 Hydrogen).

@matheusfermiano-source

Copy link
Copy Markdown

Independent Linux review of 8ba1089b with Git 2.56.1. All 20 focused tests pass. Two additional throwaway Git histories exposed incorrect results:

  1. Reverting an older merge of the same PR associates the revert with the wrong commit and can skip a re-land. From main, squash branch original (adds first.txt) as First contribution (#313). Branch from that commit, add second.txt, then squash back to main as Follow-up contribution (#313). Run git revert --no-edit <first-squash-oid>. The generated message identifies the first squash in both its subject and This reverts commit ... line. merge_check.py --main main --json 313=original records the second squash under reverted and keeps the first under merges. It returns already-merged even though git merge-tree --write-tree main original produces a tree that adds first.txt. I passed the corrected history directly to check() and it still returns already-merged: git cherry counts the original patch in history despite its revert.
  2. Reapplying a reverted merge leaves a stale reverted verdict. Merge a branch adding restored.txt with git merge --no-ff -m 'Merge pull request #314 from fixture/add-file' add-file, then run git revert --no-edit -m 1 HEAD. The new reverted verdict is correct here. Then run git revert --no-edit HEAD. Git 2.56.1 generates Reapply "Merge pull request #314 from fixture/add-file" and names the previous revert's OID in the message body. restored.txt is back on main, merging the original branch is a no-op, and the tool still reports reverted.

For Git-generated messages, the explicit target OID can distinguish an older merge from a later merge of the same PR and can identify a revert that was itself undone. The subject heuristic still covers maintainer messages without an OID. For mixed merge/revert history, a conflict-free tree that differs from main is also important evidence before assigning already-merged; patch presence in history alone missed the re-land in fixture 1.

AI-assisted (Codex).

@Grimkeh Grimkeh 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.

Independent Linux CPU review (8ba1089b)

What changed: merge_check — a merge that main has reverted no longer counts as a prior merge.

Checked: test_merge_check 20 OK.

Looks correct; no game files.

…e stands again

Review on ItsNotRexed#8807 showed two histories the subject pairing got wrong: a
revert of an older merge of the same PR was paired with the newer one,
and a merge whose revert was itself reverted (git's `Reapply "..."`)
still read `reverted`.

- A revert whose message names the commit it undoes ("This reverts
  commit <sha>.", as git writes it) undoes exactly that commit; one that
  names none, like the maintainer's "Revert #N: why", still pairs by its
  subject with the PR's newest merge that stands.
- Reverting a revert puts its merge back, found by the commit it names
  or by its subject (`Reapply "..."`, or older git's
  `Revert "Revert "...""`).
- With a revert in a PR's history, `already-merged` needs the merged
  tree to match main, since its patches stay in main's history after the
  revert.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@berkay8987

Copy link
Copy Markdown
Author

Thanks @matheusfermiano-source, both histories reproduce exactly as you describe. The fix is 35f701bc, on top of 8ba1089b:

  1. A revert that names the commit it undoes ("This reverts commit .", as git writes it) now undoes exactly that commit, so in your D3D12 → Vulkan layer: critical path, who builds what, open methods #313 history the revert pairs with the first squash. As you pointed out, the pairing alone was not enough: with a revert anywhere in a PR's history, already-merged now needs the merged tree to match main, because the patches stay in main's history after a revert. Your fixture now reads clean.
  2. Reverting a revert puts its merge back, found by the commit the reapply names, or by its subject when it names none (Reapply "...", or older git's Revert "Revert "...""). Your Viewer: validate world manifests before startup #314 history now reads already-merged, with nothing under reverted.

Only 4 of the 15 reverts on main name their commit. The maintainer's seven Revert #N: why messages don't, so those keep the subject pairing. On main 867d922f, the reports for #2490, #3402 and #4247 are unchanged, and #3006's revert, which names 2657f443e24a, pairs with that commit.

Both of your histories are now tests: test_a_revert_that_names_an_older_merge_of_the_same_pr_undoes_that_one and test_a_reverted_merge_that_is_reapplied_stands_again. With 8ba1089b's script they fail the way you described (the newer squash under reverted; reverted instead of already-merged). python -I tests/test_merge_check.py: 22 tests OK on this branch, 26 together with #8564 and #8666. Windows 11, Python 3.12.7, git 2.52.0.

AI-assisted (Claude Code).

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.

4 participants