Skip to content

fix: unpushed diff compares against merge-base, not upstream tip#729

Merged
ittaiz merged 1 commit into
mainfrom
fix/dev3-unpushed-diff-merge-base
Jun 26, 2026
Merged

fix: unpushed diff compares against merge-base, not upstream tip#729
ittaiz merged 1 commit into
mainfrom
fix/dev3-unpushed-diff-merge-base

Conversation

@ittaiz

@ittaiz ittaiz commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

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: getTaskDiff mode unpushed had two inconsistent paths in src/bun/git.ts:

  • No upstream → three-dot origin/<base>...HEAD (correct — only your work).
  • Upstream presenttwo-dot git diff <upstream> HEAD, which also surfaces commits the upstream gained independently of HEAD as reversed hunks.

That is the "sometimes correct, sometimes weird" behavior.

Fix

The upstream-present path now resolves git merge-base <upstream> HEAD and diffs HEAD against it (three-dot equivalent), so it shows only what HEAD added. The displayed compareRef/compareLabel still reports the upstream. Falls back to the previous behavior only if merge-base fails (unrelated histories).

Verification

  • New regression test in git-branch-ops.test.ts asserting every diff endpoint is the merge-base SHA, never the bare upstream tip.
  • Verified end-to-end against a real git repo with a diverged upstream: old two-dot leaked other-file.txt; fixed getTaskDiff returns only my-file.txt.
  • Full suite green (1583 mainview + 1483 bun), lint clean.

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.
@ittaiz ittaiz enabled auto-merge (squash) June 26, 2026 03:47
@ittaiz ittaiz merged commit 23f91c1 into main Jun 26, 2026
4 checks passed
@ittaiz ittaiz deleted the fix/dev3-unpushed-diff-merge-base branch June 26, 2026 03:48
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