Skip to content

fix(git-checkout): recover in narrowed-refspec (single-branch) workspaces#268

Merged
fdaviddpt merged 1 commit into
masterfrom
fix/267-git-checkout-narrowed-refspec
Jun 21, 2026
Merged

fix(git-checkout): recover in narrowed-refspec (single-branch) workspaces#268
fdaviddpt merged 1 commit into
masterfrom
fix/267-git-checkout-narrowed-refspec

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Problem

git-checkout:<branch> fails with ref '<branch>' not found even after fetch in workspaces whose remote.origin.fetch is narrowed to a single branch (e.g. +refs/heads/master:refs/remotes/origin/master). The auto-fetch fallback runs git fetch --all --prune, which only updates FETCH_HEAD — it never creates refs/remotes/origin/<branch> — so the retry git checkout <branch> still fails.

Hit in DVSI Kevin-style single-branch automation worktrees.

Fix

When the retry still hits a pathspec error, fall back to the manual workaround:

git fetch origin <ref>
git checkout -B <ref> FETCH_HEAD

-B is safe here: this block only runs after the first plain git checkout <ref> already failed, so a pre-existing local branch (which would have made that succeed) is impossible — -B only ever creates the branch.

Audit

git-diverge and git-merge do not share the bug — neither auto-fetches nor assumes origin/* tracking refs; both verify a local ref and tell the user to fetch.

Tests

Added test_narrowed_refspec_recovers_via_single_ref_fetch. 5/5 pass.

Closes #267

@fdaviddpt

Copy link
Copy Markdown
Contributor Author

Rebased onto current master and dropped the bundled #241 byte-cap commits — those were already merged separately, so this PR now contains only the #267 git-checkout fix (checkout.py +13, test +35). Also chained the narrowed-refspec fallback after the #277 remote-only-branch path that landed in master since this branch was cut, so both recovery cases are handled: #277 creates a tracking branch when a remote ref exists, #267 fetches + resets to FETCH_HEAD when none does. 5/5 checkout tests pass.

@fdaviddpt fdaviddpt closed this Jun 21, 2026
@fdaviddpt fdaviddpt reopened this Jun 21, 2026
`git fetch --all` in a single-branch workspace only updates FETCH_HEAD —
it never creates refs/remotes/origin/<branch>, so the retry checkout still
fails. Fall back to an explicit `git fetch origin <ref>` + `git checkout -B
<ref> FETCH_HEAD`.

Closes #267

Co-Authored-By: Max <noreply>
@fdaviddpt fdaviddpt force-pushed the fix/267-git-checkout-narrowed-refspec branch from fae8270 to eb2b69c Compare June 21, 2026 15:16
@fdaviddpt fdaviddpt merged commit 05280a1 into master Jun 21, 2026
12 checks passed
@fdaviddpt fdaviddpt deleted the fix/267-git-checkout-narrowed-refspec branch June 21, 2026 15:19
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.

git-checkout fails on repos with a narrowed fetch refspec (single-branch workspaces)

1 participant