fix(github): diff a PR from its base commit, not the local branch - #6
Merged
Conversation
PR mode read baseRefName from `gh pr view` and handed that name to the local ref resolver, so the diff was taken from merge-base(local branch, HEAD). Whenever the local base branch is behind the remote — which is most of the time — every commit the remote gained since then is folded into the PR's diff. On a real 11-file PR with a local master 88 commits behind, diffity reported 325 files and +14524/-3457 instead of +367/-22. baseRefOid is the commit GitHub itself bases the pull request on, and it is always present locally after `gh pr checkout` because it is an ancestor of the head. The base branch name is kept for the description, so the UI still reads "Changes from master". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018PkYQzbsnMihHesafWvXKs
This was referenced Aug 21, 2026
fiddur
marked this pull request as ready for review
August 21, 2026 13:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR mode took
baseRefNamefromgh pr viewand passed that name to the local ref resolver, sothe diff came from
merge-base(local branch, HEAD). Whenever the local base branch is behind theremote — most of the time, for most people — every commit the remote has gained since then is
folded into the pull request's diff.
Measured on NaturalCycles/NCBackend3#14360, an 11-file PR, with a local
master88 commits behind:merge-base(local master, HEAD)baseRefOid=24e3eeab4cThe second row is exactly what GitHub reports, and
24e3eeab4cis thebase.shathe REST API givesfor that PR.
baseRefOidis the commit GitHub bases the PR on, and it is always available locally aftergh pr checkoutsince it is an ancestor of the head — no extra fetch needed.baseRefNameis keptfor the description, so the header still reads "Changes from master" rather than a bare SHA.
parsePrBaseis split out from theghcall so the parsing is unit-tested, including the casewhere the response lacks the oid — that must fail loudly rather than silently fall back to a local
branch.
vitestwired up for@diffity/github, which had no tests. 163 tests pass.Stacked on #5.
🤖 Generated with Claude Code
https://claude.ai/code/session_018PkYQzbsnMihHesafWvXKs