Skip to content

mismatched-author checks a merge commit's identity at pre-merge-commit - #304

Merged
HackingGate merged 1 commit into
mainfrom
merge-commit-identity
Oct 7, 2026
Merged

HackingGate merged 1 commit into
mainfrom
merge-commit-identity

Conversation

@HackingGate

@HackingGate HackingGate commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

A non-fast-forward git merge, and a git pull that merges, records a commit without running pre-commit; git runs pre-merge-commit instead. With mismatched-author at one stage, a merge under an identity passed in -c user.* or GIT_AUTHOR_* / GIT_COMMITTER_* was recorded unchecked.

  • policy/base/mismatched-author.toml: [set] stages and the rule's git.hooks are ["pre-commit", "pre-merge-commit"]; the comment names both moments, and notes that a conflicted merge is concluded by git commit and was already covered.
  • policy/base/sets.lock.json regenerated with cargo run --quiet -- rules --sets --json.
  • docs/REFERENCE.md: the set's row says it installs pre-commit and pre-merge-commit.
  • No engine change: the guard already parses the stage and dispatches the rule there.

Tests:

  • tests/guard_cli.rs: uphold guard --stage pre-merge-commit refuses a bot identity in GIT_AUTHOR_* / GIT_COMMITTER_*, and passes the global one (and says the guard ran).
  • tests/base_sets_cli.rs: a real git merge --no-ff through a pre-merge-commit hook in a repository inheriting the set is refused under a bot -c user.* and under bot GIT_* variables, with HEAD unchanged, and as the global identity records a two-parent commit. Both refusals fail against the one-stage set.
  • every_guard_set_declares_the_stages_its_rules_install and tests/base_set_lock.rs pass.

A consumer that already lists uphold-guard-merge needs no policy change.

Closes #305

Summary by CodeRabbit

  • New Features
    • The author-mismatch check now runs before both regular commits and merge commits, helping prevent merges with unexpected author or committer identities.
  • Documentation
    • Updated the reference guide to reflect that the check applies to both commit stages.

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 21 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7636f3d1-6edd-4d47-bcf4-ecaf857a5ef1
📥 Commits

Reviewing files that changed from the base of the PR and between e738762 and 09a667b.

📒 Files selected for processing (5)
  • docs/REFERENCE.md
  • policy/base/mismatched-author.toml
  • policy/base/sets.lock.json
  • tests/base_sets_cli.rs
  • tests/guard_cli.rs

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0373a076-72d1-45ff-9347-bf64f3aa5582
📥 Commits

Reviewing files that changed from the base of the PR and between b1e8df3 and e738762.

📒 Files selected for processing (5)
  • docs/REFERENCE.md
  • policy/base/mismatched-author.toml
  • policy/base/sets.lock.json
  • tests/base_sets_cli.rs
  • tests/guard_cli.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The mismatched-author set now checks author and committer identities at both pre-commit and pre-merge-commit. The documentation and lock file reflect the added stage. Integration tests cover matching and mismatching identities for direct guard runs and real merges.

Changes

Author identity checks

Layer / File(s) Summary
Enable the merge-commit stage
policy/base/mismatched-author.toml, policy/base/sets.lock.json, docs/REFERENCE.md
The set and rule now include pre-merge-commit alongside pre-commit. Comments and reference documentation describe both stages.
Verify guard behavior during merges
tests/guard_cli.rs, tests/base_sets_cli.rs
Tests check that mismatching bot identities are refused and matching global identities pass. The merge tests also check that refused merges do not change HEAD and that successful merges create a two-parent commit.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to e7387

The merge-commit identity check has no identified merge-blocking issue. Run the reported tests as part of normal validation before merging.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #303 requires mismatched-author to check merge commits at pre-merge-commit, with no new engine path. The policy change adds that stage to both the set ceiling and rule hooks. The lock file a…
Out of Scope Changes check ✅ Passed The policy, lock-file, documentation, and integration-test changes all support issue #303. No unrelated changes are identified in the whole-PR summary.
Docstring Coverage ✅ Passed Docstring coverage is 92.31% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 2 files. (3 skipped: 3 …
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding a pre-merge-commit identity check to the mismatched-author set.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

codecov-commenter commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.10%. Comparing base (b1e8df3) to head (09a667b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #304   +/-   ##
=======================================
  Coverage   94.10%   94.10%           
=======================================
  Files          46       46           
  Lines       21025    21025           
=======================================
  Hits        19786    19786           
  Misses       1239     1239           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

A non-fast-forward `git merge`, and a `git pull` that merges, records a
commit without running `pre-commit`; git runs `pre-merge-commit` instead.
With the set at one stage, a merge under a bot identity passed in
`-c user.*` or `GIT_AUTHOR_*` / `GIT_COMMITTER_*` was recorded and nothing
looked. The set's ceiling and the rule's hooks are now `pre-commit` and
`pre-merge-commit`, and the comment names both moments. A conflicted merge
is concluded by `git commit` and was already covered at `pre-commit`.

No engine change: the guard already parses the stage and dispatches the rule
there, and `git var` in the merge hook resolves the identity the merge
commit records. The set lock is regenerated and REFERENCE.md names the new
stage.

guard_cli holds that `uphold guard --stage pre-merge-commit` refuses a bot
identity in the environment and passes the global one. base_sets_cli runs a
real `git merge --no-ff` through a `pre-merge-commit` hook in a repository
inheriting the set: under a bot `-c user.*` and under bot `GIT_*` variables
it is refused and HEAD does not move, and as the global identity it records
a two-parent commit. The two refusals fail against the one-stage set.

A consumer that already lists `uphold-guard-merge` needs no policy change.

Closes #305
@HackingGate
HackingGate force-pushed the merge-commit-identity branch from e738762 to 09a667b Compare October 7, 2026 03:28
@HackingGate
HackingGate merged commit 11960b9 into main Oct 7, 2026
22 of 23 checks passed
@HackingGate
HackingGate deleted the merge-commit-identity branch October 7, 2026 03:53
HackingGate added a commit that referenced this pull request Oct 7, 2026
No engine change since 1.25.1; one bundled set widens. mismatched-author now
runs at `pre-merge-commit` as well as `pre-commit`. A non-fast-forward
`git merge`, or a `git pull` that merges, records a commit without running
`pre-commit`, so a merge under a bot identity passed in `-c user.*` or
`GIT_AUTHOR_*` / `GIT_COMMITTER_*` was recorded with nothing looking. The
set's ceiling and the rule's hooks are now both stages, and the set lock is
regenerated (#304).

A consumer taking the pin to v1.26.0 that inherits mismatched-author and runs
the `pre-merge-commit` guard (the `uphold-guard-merge` hook, or the lefthook
manifest) is now refused a merge commit recorded under an identity the rule
rejects, where it passed. Such a consumer needs no policy
change; record the merge as the global identity.
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.

Design: prevent-author-mismatch does not check merge commits

2 participants