Repository navigation
feat(workspace): add clone.branches to clone only the checked-out ref - #1809
Open
knechtionscoding wants to merge 1 commit into
Open
knechtionscoding wants to merge 1 commit into
knechtionscoding wants to merge 1 commit into
Conversation
knechtionscoding
had a problem deploying
to
ok-to-test
October 8, 2026 11:00 — with
GitHub Actions
Error
knechtionscoding
force-pushed
the
hans/workspace-single-branch
branch
from
October 8, 2026 11:15
e2cf9c5 to
28c582c
Compare
knechtionscoding
had a problem deploying
to
ok-to-test
October 8, 2026 11:15 — with
GitHub Actions
Error
knechtionscoding
marked this pull request as ready for review
October 8, 2026 11:34
There was a problem hiding this comment.
All reported issues were addressed across 11 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
Workspaces are cloned with `--depth 1 --no-single-branch`, which downloads the tip of every branch. On repositories with thousands of branches this dominates task startup. Add `Workspace.spec.clone.branches` (`All` | `Single`). `Single` clones with `--single-branch`, so only `spec.ref` (or the default branch) is fetched and origin is configured to track only that ref. Omitting the field keeps today's all-branches clone. The branch-setup init container now fetches the Task branch with `--depth 1` and an explicit `refs/remotes/origin/<branch>` destination. Without `--depth 1`, fetching a branch into a single-branch shallow clone downloads its full history; the destination keeps `origin/<branch>` available as the all-branches clone did. In `Single` mode it also adds the Task branch to origin's fetch refspecs, so later fetches and pushes keep `origin/<branch>` current and `git push -u` sets an upstream. Because a shallow fetch cannot fast-forward an existing local branch when the remote moves between clone and fetch, the existing-branch case resets to FETCH_HEAD instead of `merge --ff-only`. branch-setup only runs on a freshly cloned repository, so there are no local commits to preserve.
knechtionscoding
force-pushed
the
hans/workspace-single-branch
branch
from
October 8, 2026 12:54
28c582c to
0132f53
Compare
knechtionscoding
requested a deployment
to
ok-to-test
October 8, 2026 12:54 — with
GitHub Actions
Waiting
This was referenced Oct 8, 2026
Contributor
Author
|
bump @gjkim |
1 similar comment
Contributor
Author
|
bump @gjkim |
This was referenced Oct 19, 2026
Contributor
Author
|
@gjkim42 bump here |
This branch is waiting to be deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
/kind api
What this PR does / why we need it:
Workspaces are cloned with
git clone --depth 1 --no-single-branch, which downloads the tip of every branch. On repositories with many branches this can be most of a Task's startup time. On a repository with about 6,300 branches, a laptop clone took 122s and 818 MB with today's flags, against 40s and 293 MB with--single-branch.This PR adds
Workspace.spec.clone.branches:All, or omitting the field, keeps today's clone of every branch tip.Singleclones onlyspec.ref, or the remote's default branch whenspec.refis empty.originis set up to track only that ref, so a plaingit fetch origindoesn't pick up other branches. To use another branch, rungit remote set-branches --add origin <branch>, thengit fetch --depth 1 origin <branch>. The CRD description anddocs/reference.mdstate this.spec.refis a full commit SHA, which already uses its owninit+fetchpath.The
branch-setupinit container, which runs whenTask.spec.branchorSession.spec.initialBranchis set, now fetches the branch like this:git fetch --depth 1 origin "+refs/heads/$KELOS_BRANCH:refs/remotes/origin/$KELOS_BRANCH"--depth 1: a plaingit fetch origin <branch>into a single-branch shallow clone downloads that branch's entire history. On kelos-dev/kelos that was 1,426 commits against 1. InAllmode the tip is already present, so the change is unconditional.origin/<branch>present, as the all-branches clone does today, so agents that readorigin/<branch>keep working.Singleonly):branch-setupfirst runsgit remote set-branches --add origin "$KELOS_BRANCH". Without it, origin's fetch refspec covers only the cloned ref. After an agent pushes its branch,origin/<branch>stays at the old commit andgit push -usets no upstream. With it, later fetches and pushes keeporigin/<branch>current.Allmode doesn't need it, so the line is only added forSingle.Which issue(s) this PR is related to:
N/A
Special notes for your reviewer:
clone: { branches: All | Single }instead, so the default can change later without reinterpreting what users wrote. It also gives future clone settings a place to go (depth, filter, sparse paths; see New use case: Monorepo support with workspace scoping, sparse checkout, and per-service agent routing #518) without new top-level fields. Onlybranchesis added here.Singlematches git's--single-branch, which is the term users will search for.merge --ff-onlybecamereset --hard FETCH_HEADfor the case where the Task branch already exists locally, which only happens when it is the cloned branch. After a--depth 1fetch, the old local tip is not an ancestor of the new shallow tip. So if the remote moves between clone and fetch,--ff-onlyfails and the init container fails, in both modes; I confirmed this with git locally. Resetting is safe becausebranch-setuponly runs on a freshly cloned repo: Task workspaces areemptyDir, and Session init re-clones until the workspace is marked initialized, then skipsbranch-setup.ghproxy. A dropped value falls back toAll, which is slower but correct.v0.59.0withbranches: Singleand setsspec.branch: main. That makesbranch-setupfetch a branch that isn't in the clone. AsetupCommandprints the git state. The test checks that the repo is shallow,mainis checked out atorigin/main, only one remote branch exists, and origin's fetch refspecs includemain. I ran the same steps locally against GitHub and they passed.SingleandAll, a commit-SHA ref ignoring the field, the full fetch and reset lines in thebranch-setupscript, theset-branchesline present forSingleand absent forAlland commit refs, and WorkerPool clone arguments in both modes.branches: Single, plus a check that an unknown value is rejected.Does this PR introduce a user-facing change?