fix: filter already-merged commits from PR range context#1521
fix: filter already-merged commits from PR range context#1521zerone0x wants to merge 1 commit intopingdotgg:mainfrom
Conversation
When generating PR title and body, `readRangeContext` uses `git log --oneline baseBranch..HEAD` to collect commit summaries. On long-lived branches where previous PRs were squash-merged into the base branch, this range includes old commits whose patch content already exists upstream. The LLM then generates titles reflecting stale work. Adding `--cherry-pick --right-only` to the git log command tells git to skip commits whose patch-id matches a commit already reachable from the base branch. This ensures only genuinely new commits feed into PR content generation, so each PR gets a fresh title based on its own changes. Fixes pingdotgg#1487 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Closing duplicate — #1519 is the primary fix for this issue. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| "GitCore.readRangeContext.log", | ||
| cwd, | ||
| ["log", "--oneline", range], | ||
| ["log", "--oneline", "--cherry-pick", "--right-only", range], |
There was a problem hiding this comment.
--cherry-pick --right-only requires triple-dot range notation
High Severity
The --cherry-pick and --right-only flags are silently ignored because the range variable uses double-dot notation (baseBranch..HEAD). These flags require triple-dot symmetric difference notation (baseBranch...HEAD) to work — Git needs to see commits from both sides simultaneously to identify patch-id equivalents. With double-dot, the intended filtering of already-merged commits simply doesn't happen. The git log command needs its own triple-dot range, separate from the git diff commands which correctly use double-dot.


Summary
Fixes #1487
When generating PR title and body,
readRangeContextusesgit log --oneline baseBranch..HEADto collect the commit summary that feeds into the LLM prompt. On long-lived branches where previous PRs were squash-merged (or merge-committed) into the base branch, this range includes all old commits whose SHAs differ from what landed on the base — even though their patch content is already upstream. The LLM then generates a title dominated by stale commit messages from previously merged PRs.Root cause:
git log main..HEADlists commits reachable from HEAD but not frommainby commit identity (SHA). After a squash-merge, the original commits on the feature branch have different SHAs than the squash commit onmain, so they all appear in the log — even though the actual code changes are already inmain.Fix: Add
--cherry-pick --right-onlyflags to thegit logcommand inreadRangeContext. These flags tell git to compare patch-ids (content hashes of each commit's diff) and skip any commit on the right side (HEAD) whose patch already exists on the left side (base branch). This filters out commits from previously merged PRs, ensuring only genuinely new commits feed into PR content generation.This is a single-line change with no network overhead (unlike fetching the base branch), works entirely locally, and gracefully handles all merge strategies (squash, merge commit, rebase).
Changed file:
apps/server/src/git/Layers/GitCore.ts—readRangeContextmethodTest plan
readRangeContexttest still passes (it creates fresh commits not present on the base, so--cherry-pickwon't filter them)🤖 Generated with Claude Code
Note
Low Risk
Low risk: a small change to the
git loginvocation used for PR context generation; it only affects which commits appear in the summary, not repository state or data writes.Overview
Updates
GitCore.readRangeContextto callgit logwith--cherry-pick --right-onlyfor thebase..HEADrange, filtering out commits whose patch content already exists on the base branch.This reduces stale/previously-merged commit messages from being included in the commit summary used to generate PR titles/bodies, while leaving diff stat/patch collection unchanged.
Written by Cursor Bugbot for commit 5f2aaf0. This will update automatically on new commits. Configure here.
Note
Filter already-merged commits from
readRangeContextPR range summaryAdds
--cherry-pickand--right-onlyflags to thegit logcall inreadRangeContext(GitCore.ts). This limits the commit summary to the right side of the range and excludes commits whose patches already exist on the other side (e.g. cherry-picks). Behavioral Change: the set of commits appearing in the PR range summary may change for branches that share cherry-picked commits with their base.Macroscope summarized 5f2aaf0.