Skip to content

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

Open
fdaviddpt wants to merge 3 commits into
masterfrom
fix/267-git-checkout-narrowed-refspec
Open

fix(git-checkout): recover in narrowed-refspec (single-branch) workspaces#268
fdaviddpt wants to merge 3 commits 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 added 3 commits May 29, 2026 16:00
A large :N context on a file of long (minified) lines could dump hundreds
of KB in one op, blowing the caller's context budget (~340KB observed).

Add _cap_context_window: cap output at 16KB (configurable via
builtin-ops.<op>.max_bytes / SUPERTOOL_<OP>_MAX_BYTES), truncate at a line
boundary, append a footer pointing at the narrower tools (smaller :N,
between:). Applied to around: (single-file + dir-aggregate) and the
op_grep context branch (grep_around: and grep:-with-context).

6 TDD tests (red proven by neutralizing the cap). Docs: configuration.md
table, operations/search.md cap section, .supertool[.example].json entries.

Co-Authored-By: Max <noreply>
…docs

- Remove the per-file cap from _around_one_file; cap only at op_around's
  single-file and dir-aggregate returns. Fixes double-capping (per-file +
  aggregate both 16KB) and interleaved truncation footers in dir fan-out.
- _cap_context_window: nl >= 0 (was > 0) so a newline at offset 0 still
  trims; consistent byte-accounting for the dropped count.
- Tests: +dir-aggregate cap (single footer), +single-giant-line no-newline.
- Docs: note grep:PATTERN:PATH:LIMIT:CONTEXT shares the grep_around cap;
  align .supertool.json descriptions.

Co-Authored-By: Max <noreply>
`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>
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