Skip to content

fix(diff): review merge commits against their first parent - #450

Merged
lizhengfeng101 merged 1 commit into
alibaba:mainfrom
hobostay:fix/merge-commit-diff
Jul 22, 2026
Merged

lizhengfeng101 merged 1 commit into
alibaba:mainfrom
hobostay:fix/merge-commit-diff

Conversation

@hobostay

Copy link
Copy Markdown
Contributor

Description

ocr review --commit <merge-commit> silently reviews nothing and exits 0 with "No supported files changed", even when the merge commit contains conflict resolutions — precisely the content that most needs review.

Root cause: ModeCommit uses plain git show <commit> (internal/diff/git.go), which renders merge commits as a combined diff (diff --cc sections with @@@ hunks and two-column prefixes). ParseDiffText only recognizes diff --git a/... b/... sections, so every combined section is dropped and the parse yields zero diffs. (Worse, a combined section following a regular one would be absorbed into the previous file's diff text.)

Reproduced with real git: on a merge commit with a conflict resolution, the provider returns [] (0 diffs) today.

Fix

Pass --diff-merges=first-parent to the git show call so a merge commit is diffed against its first parent in regular unified format — the same "what did this change introduce" semantics --commit has for normal commits. Non-merge commits are unaffected (verified: root commits still diff against the empty tree, regular commits unchanged). The flag requires git ≥ 2.31; the project already requires git ≥ 2.41.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

How Has This Been Tested?

  • make test passes locally (go test -race -count=1 ./...)
  • New regression test TestCommitDiffMergeCommitReviewsFirstParentDiff builds a real repo with a conflicting merge, then asserts the provider returns exactly one diff containing the conflict resolution. Fails on main (expected exactly 1 diff for the merge commit, got 0: []), passes with the fix.
  • Manual testing: git show with the exact provider flags on merge and root commits, before/after.

Checklist

  • My code follows the project's coding style (gofmt -s, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (not applicable — behavior now matches user expectation)
  • I have signed the CLA (will sign via the CLA bot)

Related Issues

None filed.

Plain `git show` renders a merge commit as a combined diff ("diff --cc"
sections with @@@ hunks), which ParseDiffText does not handle: every
section is silently dropped, so `ocr review --commit <merge>` exits 0
with "No supported files changed" even when the merge contains conflict
resolutions — precisely the content that most needs review. Worse, a
combined section following a regular one is absorbed into the previous
file's diff text.

Pass --diff-merges=first-parent to the ModeCommit git show call so a
merge commit is diffed against its first parent in regular unified
format. Non-merge commits are unaffected (verified: root commits still
diff against the empty tree). The flag requires git >= 2.31; the project
already requires git >= 2.41.
@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: No comments generated. Looks good to me.

@css521 css521 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 3fe3027 into alibaba:main Jul 22, 2026
7 checks passed
@Wsp030914 Wsp030914 mentioned this pull request Aug 21, 2026
9 of 14 tasks
Githab-capibara added a commit to Githab-capibara/open-code-review that referenced this pull request Sep 17, 2026
Plain `git show` renders a merge commit as a combined diff ("diff --cc"
sections with @@@ hunks), which ParseDiffText does not handle: every
section is silently dropped, so `ocr review --commit <merge>` exits 0
with "No supported files changed" even when the merge contains conflict
resolutions — precisely the content that most needs review. Worse, a
combined section following a regular one is absorbed into the previous
file's diff text.

Pass --diff-merges=first-parent to the ModeCommit git show call so a
merge commit is diffed against its first parent in regular unified
format. Non-merge commits are unaffected (verified: root commits still
diff against the empty tree). The flag requires git >= 2.31; the project
already requires git >= 2.41.
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