Skip to content

fix(github): diff a PR from its base commit, not the local branch - #6

Merged
fiddur merged 1 commit into
developfrom
pr-base-oid
Aug 21, 2026
Merged

fix(github): diff a PR from its base commit, not the local branch#6
fiddur merged 1 commit into
developfrom
pr-base-oid

Conversation

@fiddur

@fiddur fiddur commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

PR mode took baseRefName from gh pr view and passed that name to the local ref resolver, so
the diff came from merge-base(local branch, HEAD). Whenever the local base branch is behind the
remote — 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 master 88 commits behind:

Base Result
merge-base(local master, HEAD) 325 files, +14524/−3457
baseRefOid = 24e3eeab4c 11 files, +367/−22

The second row is exactly what GitHub reports, and 24e3eeab4c is the base.sha the REST API gives
for that PR.

baseRefOid is the commit GitHub bases the PR on, and it is always available locally after
gh pr checkout since it is an ancestor of the head — no extra fetch needed. baseRefName is kept
for the description, so the header still reads "Changes from master" rather than a bare SHA.

parsePrBase is split out from the gh call so the parsing is unit-tested, including the case
where the response lacks the oid — that must fail loudly rather than silently fall back to a local
branch. vitest wired up for @diffity/github, which had no tests. 163 tests pass.

Stacked on #5.

🤖 Generated with Claude Code

https://claude.ai/code/session_018PkYQzbsnMihHesafWvXKs

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
@fiddur
fiddur changed the base branch from bind-loopback to develop August 21, 2026 13:34
@fiddur
fiddur marked this pull request as ready for review August 21, 2026 13:34
@fiddur
fiddur merged commit 0565852 into develop Aug 21, 2026
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.

1 participant