fix: unpushed diff compares against merge-base, not upstream tip#729
Merged
Conversation
The 'Unpushed' diff mode's upstream-present path used a two-dot diff (git diff <upstream> HEAD). When the upstream had diverged from HEAD — after a rebase, a force-push, or when the upstream tracks a base branch that has advanced — that surfaced the upstream's independent commits as reversed hunks, i.e. 'changes that aren't mine'. The no-upstream fallback already used three-dot semantics, hence 'sometimes correct, sometimes weird'. Now resolve git merge-base <upstream> HEAD and diff HEAD against it (three-dot equivalent), so the diff shows only what HEAD added. The displayed compareRef/compareLabel still reports the upstream.
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.
Problem
The "Unpushed" diff mode showed changes that aren't yours whenever the branch's upstream had diverged from
HEAD— after a rebase, a force-push, or when the upstream tracks a base branch that has advanced.Root cause:
getTaskDiffmodeunpushedhad two inconsistent paths insrc/bun/git.ts:origin/<base>...HEAD(correct — only your work).git diff <upstream> HEAD, which also surfaces commits the upstream gained independently ofHEADas reversed hunks.That is the "sometimes correct, sometimes weird" behavior.
Fix
The upstream-present path now resolves
git merge-base <upstream> HEADand diffsHEADagainst it (three-dot equivalent), so it shows only whatHEADadded. The displayedcompareRef/compareLabelstill reports the upstream. Falls back to the previous behavior only ifmerge-basefails (unrelated histories).Verification
git-branch-ops.test.tsasserting every diff endpoint is the merge-base SHA, never the bare upstream tip.other-file.txt; fixedgetTaskDiffreturns onlymy-file.txt.