Skip to content

Fix Diff tab base when local branch trails origin - #7115

Closed
d1mka112 wants to merge 1 commit into
get-bb:mainfrom
d1mka112:fix/pr-diff-base
Closed

d1mka112 wants to merge 1 commit into
get-bb:mainfrom
d1mka112:fix/pr-diff-base

Conversation

@d1mka112

@d1mka112 d1mka112 commented Nov 5, 2026

Copy link
Copy Markdown

Human comments

What was wrong

The Git plugin resolves a short merge base name against the local branch first. When that branch trails its remote tracking branch, the Diff tab includes unrelated changes between the two base refs. Reproduced in #7114.

What changed

Short branch names now prefer origin/<branch> when available and fall back to the local branch. An explicit refs/heads/<branch> retains local branch selection. Updated the Git skill and added a regression test covering both paths. No server/daemon wire contract changed.

How you verified

  • Added a stale local base fixture: short main shows only the feature commit; explicit refs/heads/main shows both commits.
  • pnpm exec turbo run test --filter=bb-plugin-bb--git: 35 files, 277 tests passed. Vitest reported a sandbox spawn EPERM during process-sweep teardown after the tests; Turbo reported success.
  • pnpm exec turbo run typecheck --filter=bb-plugin-bb--git: passed.
  • git diff --check: passed.

Fixes #7114

AGENT GENERATED

@github-actions github-actions Bot added the needs-approval PR author is not on the approved contributor list label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the pull request, @d1mka112. It was closed automatically because it does not meet the requirements below yet. This is an automated check, not a review of the change.

Contributor approval. bb reviews pull requests only from approved contributors, and you are not on the list yet. Join the #contributors channel in Discord (https://discord.gg/kvBU6tJhcJ), post a link to your pull request, and explain what it changes and why. A maintainer then adds you to the list and reopens the pull request.

See CONTRIBUTING.md for details.

@github-actions github-actions Bot closed this Nov 5, 2026
ymichael pushed a commit that referenced this pull request Nov 16, 2026
## Human comments

## What was wrong

`resolveMergeBaseBranch` in `plugins/git/host/git.ts` tried the local
branch first for a short name such as `main`, and used `origin/main`
only when no local branch existed. When an unused local `main` trails
`origin/main`, the Diff tab and `bb git diff --target branch_committed`
compared against the stale local ref. Commits that were already on the
remote base then showed as branch changes (#7114).

## What changed

- `plugins/git/host/git.ts`: for a short name, resolve both `<branch>`
and `refs/remotes/origin/<branch>`. When both exist and differ, use
`origin/<branch>` if the local branch is an ancestor of it (`git
merge-base --is-ancestor`). Otherwise, use the local branch. A name that
starts with `refs/` or `origin/` resolves as before.
- `plugins/git/skills/git/SKILL.md`: describes the new resolution order
and `refs/heads/<branch>` to always select the local branch.
- `workspace-reads.test.ts`: a regression test for a local `main` that
trails `origin/main`.

Deviation from the closed #7115, which always preferred
`origin/<branch>`: a local base branch that is ahead of or diverged from
origin still wins. This keeps unpushed base commits in the base, and the
existing test that expects the local `main` (ahead of origin) passes
without changes. The cost is one extra `git rev-parse`, and one
`merge-base --is-ancestor` only when both refs exist and differ.

No wire change, no `HOST_DAEMON_PROTOCOL_VERSION` change, no CLI change.

## How you verified

- Before the fix, the new test fails: `AssertionError: expected 'diff
--git a/base.txt b/base.txt...' not to contain 'base.txt'`.
- After the fix: `pnpm exec turbo run lint lint:type-aware typecheck
test --filter=bb-plugin-bb--git` passes, 11 of 11 tasks, 35 test files,
281 tests. `oxfmt --check` passes on the changed files.

Fixes #7114

> AGENT GENERATED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-approval PR author is not on the approved contributor list

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diff tab prefers stale local base over origin branch

1 participant