Skip to content

merge_check: account for changes made in new merge commits - #9688

Closed
ZUKETEBO wants to merge 2 commits into
ProjectLeonida:mainfrom
ZUKETEBO:fix/merge-check-merge-only-changes
Closed

ZUKETEBO wants to merge 2 commits into
ProjectLeonida:mainfrom
ZUKETEBO:fix/merge-check-merge-only-changes

Conversation

@ZUKETEBO

Copy link
Copy Markdown

Claimed in the coordination issue.

What changed

A previously merged PR can have a new merge commit whose parents are both on main, but whose result includes a new change. In that case, git cherry returns no commits and the check reports already-merged even though git merge-tree would add that change.

Keep the existing fast paths. When a prior merge and matching patch counts would lead to already-merged despite a changed merge tree, check for merge commits reachable from the PR head but absent from main. If any exist, let the normal duplicate/conflict/clean checks decide.

Testing

  • Windows 11, Python 3.14.2, Git for Windows 2.56.0: all 17 test_merge_check.py tests passed. The new test checked both a content-neutral merge and a merge with a change of its own. The latter returned already-merged before the fix and clean after it.
  • Python compilation, git diff --check, and the repository's game-data check passed for the changed files.
  • A separate synthetic add/add conflict involving a change made only in a new merge commit returned conflict, even though git cherry was empty.
  • Full CPU semantic suite: 447 files and 5,957 tests. The two failing files (test_image_atomics_guard, test_image_store_d16) also fail on unmodified main at 6312c057.

This PR is based directly on main. #8807 and #8666 edit the same verdict path for different cases, so the merge order may require rebasing.

AI-assisted (Codex). CPU-only validation, no GPU or game data.

Added a test to ensure changes made only in a new merge commit are not already merged.
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

A neutral merge changes the verdict for a replay of a reverted patch. At a5ee69f the same proposed tree changes from already-merged (exit 1) to clean (exit 0). Merging it would restore three lines that main explicitly reverted.

Run this from the repository root with py -3.14 -I -. It uses the PR's temporary-repository fixture.

import runpy
g = runpy.run_path("tests/test_merge_check.py")
c = g["MergeCheckTest"]()
c.setUp()
try:
    root = c.git("rev-parse", "main")
    c.pr_branch("original",root,g["PARAGRAPH"])
    c.merge(11,"original")
    c.git("revert","--no-edit","original")
    c.git("checkout","-qb","side",root)
    c.write("docs/other.md","Independent change.\n")
    c.commit("side")
    c.git("checkout","-q","main")
    c.merge(12,"side")
    c.pr_branch("copy",root,g["PARAGRAPH"])
    c.git("checkout","-q","copy")
    before = c.git("merge-tree","--write-tree","main","copy")
    print("before", c.run_check("11=copy"))
    c.git("merge","--no-ff","-m","sync with side","side")
    print("after", c.run_check("11=copy"))
    assert before == c.git("merge-tree","--write-tree","main","copy")
    print(c.git("diff","--stat","main",c.git("merge-tree","--write-tree","main","copy")))
finally:
    c.doCleanups()

Both calls report one patch, already on main. The tree ID comparison passes. The base checker at 867d922 still returns already-merged after the neutral merge. Please add this paired case alongside the test for a merge that adds its own edit. A merge commit in the PR history is insufficient evidence that the merge introduces a new edit.

AI-assisted.

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

Reviewed and ran the focused merge_check suite: all 17 tests passed, including the new merge-only change regression.

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