Skip to content

Take a project checkout's branches from origin when its clone lacks them - #5885

Closed
alexandre-vl wants to merge 1 commit into
get-bb:mainfrom
alexandre-vl:fix/project-checkout-fresh-clone-branches
Closed

alexandre-vl wants to merge 1 commit into
get-bb:mainfrom
alexandre-vl:fix/project-checkout-fresh-clone-branches

Conversation

@alexandre-vl

Copy link
Copy Markdown
Contributor

Human comments

cc @SawyerHood: this builds on #5856, which you merged, for the fresh-clone half (#5851).

What was wrong

A clone bb makes onto a machine holds only the default branch locally (project.ts#L101), and for a machine with no checkout yet the picker lists origin's branches without origin/ (app.tsx#L351-L357). The checkout host passed that name to git. On main (81b48d3) a thread there fails to start:

git switch -C bb/reply-with-exactly-ready-and-nothing-else-thr_yv6tnchgtp dev failed: fatal: invalid reference: dev
Cannot checkout missing branch release

What changed

  • The host looks a branch up locally, then as origin/<name>, as the default-base lookup already does (git.ts#L478-L497).
  • A new branch starts from origin/<base> when no local branch has that name. It tracks nothing, as the worktree host makes one (worktree.ts#L559). Otherwise it would take origin/dev as its upstream.
  • The host reports the ref it started from as baseBranch, as the worktree host does (host.ts#L115), and the provider records that ref as the merge base instead of the name it was given. dev does not resolve in that clone, so a recorded dev would leave the thread's diff empty. The rest of Preserve new checkout branch comparison bases #5856 is unchanged: an existing branch clears the merge base, an attach without a switch keeps it, and a restore re-reports it.
  • An existing branch that only origin has is switched to with git switch --track origin/<name>, so the switch does not depend on checkout.guess.
  • baseBranch is a new field on the plugin's own host RPC. The daemon runs the host artifact the server sends (plugin-host-manager.ts#L428-L440), so the server and the host change together.

How you verified

  • New integration test project-checkout-fresh-clone.test.ts, in a plain clone, through the server, the daemon and the bundled plugin:

    • A thread on a new branch from dev commits thread.txt. Its diff reads A\tthread.txt and its merge base is origin/dev.
    • A thread on release ends up on release, tracking origin/release.
    • At 81b48d3 both fail with the errors above.
  • Each change, reverted alone, fails a test:

    Reverted Fails
    records the given name, not the host's ref integration test: expected '' to be 'A\tthread.txt\n'; server test
    host reports no ref integration test: expected '' to be 'A\tthread.txt\n'; 2 host tests
    new branch from the bare name integration test: fatal: invalid reference: dev; host test
    existing branch looked up locally only integration test: Cannot checkout missing branch release; host test
    --track dropped host test, under checkout.guess=false
    --no-track dropped host test: the new branch's upstream is origin/dev
  • These pass:

    • turbo run typecheck lint --filter='...[origin/main]' (8 tasks)
    • the plugin's tests (47)
    • the smoke, multi-thread and environments integration suites (40)
    • oxfmt on the changed files

Supersedes #5855.

Fixes #5851

AGENT GENERATED

A clone bb makes holds only the default branch locally, and the picker names
origin's branches without `origin/`. The host passed that name to git, so a new
branch from `dev` failed with `fatal: invalid reference: dev`, and an existing
`release` with `Cannot checkout missing branch release`.

The host now looks a branch up locally, then as `origin/<name>`. A new branch
starts from that ref and tracks nothing, as the worktree host makes one. The
host reports the ref as the branch's base, and the provider records it as the
merge base: `dev` does not resolve in that clone, and a recorded `dev` hides
the thread's commits from its diff. An existing branch only origin has is
switched to with `--track`.
@github-actions

Copy link
Copy Markdown
Contributor

Thanks @alexandre-vl for the PR. This repo approves new contributors before it reviews their PRs, so this PR now closes on its own. That is expected. Join the #contributors channel in Discord (https://discord.gg/kvBU6tJhcJ), post a link to this PR, and explain what it changes and why. A maintainer then adds you to the allow list and can reopen the PR.

@github-actions github-actions Bot closed this Oct 20, 2026
@alexandre-vl
alexandre-vl deleted the fix/project-checkout-fresh-clone-branches branch October 20, 2026 20:21
ymichael pushed a commit that referenced this pull request Oct 20, 2026
… the clone lacks them (#5855)

## Human comments

Thanks @ymichael for rebuilding this on `main`.

## What was wrong

A project bb clones onto a machine holds only the remote's default
branch, and the picker lists origin's branches there without `origin/`.
The host passed the bare name to git. On `main` at 81b48d3, after #5856,
a new branch from `dev` fails with `fatal: invalid reference: dev`, and
an existing `release` with `Cannot checkout missing branch release`.

## What changed

- The host looks a branch up locally, then as `origin/<name>`
(`locateBranch`, on the shared `hasRef`).
- An existing branch that only origin holds is switched to with `git
switch --track origin/<name>`, so the switch does not depend on
`checkout.guess`.
- A new branch starts from `origin/<base>` when no local branch has it.
The host reports that ref, and the provider records it as the merge base
in place of the requested name. `dev` does not resolve in that clone, so
a recorded `dev` would leave the thread's diff empty. #5856's other
cases are unchanged.
- A new branch tracks nothing, as the worktree host's `worktree add
--no-track -B` makes one. Otherwise a branch made from `origin/dev`
would take it as its upstream.

## How you verified

At ebe71b6:

- `project-checkout-branches.test.ts` runs in a plain clone. A new
branch from `dev` records `origin/dev`, and `release` ends up tracking
`origin/release`. Both fail on `main` with the errors above.
- #5885's test, run here, has the thread commit in that clone: its diff
reads `A\tthread.txt`.
- These pass:
  - the plugin's tests (46)
- the smoke, multi-thread and environments integration suites, with
#5885's two tests added (43)
- #5885 makes the same fix and lists which test fails when each part is
reverted alone.

Fixes #5851

> AGENT GENERATED

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Oct 20, 2026
…ck (#5907)

## Human comments

## What was wrong

#5855 fixed fresh-clone branch resolution, but its integration test only
checked an empty initial diff. That could not prove committed thread
changes remain visible. The README also still described the selected
name as the recorded base rather than the resolved ref.

## What changed

Bring over the remaining test and documentation coverage from #5885:
- Extend the fresh-clone integration test to commit thread.txt and
assert that the diff contains exactly that file.
- Extend the existing provider contract test table to verify that
selecting dev records the host-resolved origin/dev.
- Document local-first branch lookup, origin fallback, tracking
behavior, and the resolved diff base.

No production code or wire contracts change.

## How you verified

- Turbo plugin server tests: 27 passed.
- Turbo project-checkout integration tests: 3 passed.
- Turbo lint/typecheck for the plugin and integration packages completed
successfully.
- Temporarily changed the server to record the requested dev instead of
origin/dev: the provider test failed and the integration test failed
with an empty diff instead of A\tthread.txt\n. Restored production code
byte for byte and reran both suites successfully.
- Formatted all three changed files and ran git diff --check.

Follow-up to #5855; carries over coverage and documentation from #5885.

> AGENT GENERATED
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.

Project checkout on a fresh clone fails for any branch but the default: "fatal: invalid reference: dev"

1 participant