The best way to control Claude Code, Codex and more from any computer or phone
fix(server): status reports no branch while a clone has not checked out HEAD (#37041)
Julius Marminge committed
Nov 14, 2026 at 21:43 UTC
d8b80a1097a92cc7dcaf2998a71816825d004dad
3 files changed
+29
-3
apps/server/src/vcs/GitVcsDriverCore.test.ts
+15
@@ -5268,6 +5268,21 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
5268
}),
5269
);
5270
5271
+ it.effect("reports no branch while a clone has not checked out HEAD yet", () =>
5272
+ Effect.gen(function* () {
5273
+ const cwd = yield* makeTmpDir();
5274
+ const driver = yield* GitVcsDriver.GitVcsDriver;
5275
+ yield* driver.initRepo({ cwd });
5276
+ // `git clone` points HEAD here until checkout; status then prints `branch.head (unknown)`.
5277
+ yield* (yield* FileSystem.FileSystem).writeFileString(
5278
+ NodePath.join(cwd, ".git", "HEAD"),
5279
+ "ref: refs/heads/.invalid\n",
5280
+ );
5281
+
5282
+ assert.equal((yield* driver.statusDetailsLocal(cwd)).branch, null);
5283
+ }),
5284
+ );
5285
+
5286
it.effect("records no failed span reading status of a repository without a remote", () =>
5287
Effect.gen(function* () {
5288
const cwd = yield* makeTmpDir();
apps/server/src/vcs/GitVcsDriverCore.ts
+2
-1
@@ -2500,7 +2500,8 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2500
}
2501
if (line.startsWith("# branch.head ")) {
2502
const value = line.slice("# branch.head ".length).trim();
2503
- refName = value === "(detached)" ? null : value;
2503
+ // `(unknown)` is printed while HEAD names no resolvable branch, e.g. mid-`git clone`.
2504
+ refName = value === "(detached)" || value === "(unknown)" ? null : value;
2505
continue;
2506
}
2507
if (line.startsWith("# branch.upstream ")) {
apps/web/src/components/BranchToolbarBranchSelector.tsx
+12
-2
@@ -601,7 +601,7 @@ export function BranchToolbarBranchSelector({
601
: resolveDefaultWorktreeBaseBranch(refs);
602
603
const projectCloneDone = useProjectClone(activeProjectRef)?.phase === "done";
604
- const refreshRefsAfterClone = useEffectEvent(() => {
604
+ const refreshStaleRefs = useEffectEvent(() => {
605
if (branchCwd === null) return;
606
void refreshLocalStatusForPicker({
607
environmentId,
@@ -610,8 +610,18 @@ export function BranchToolbarBranchSelector({
610
});
611
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- refs listed while the project was cloning are empty; reload them past the server's snapshot when the clone finishes
612
useEffect(() => {
613
- if (projectCloneDone) refreshRefsAfterClone();
613
+ if (projectCloneDone) refreshStaleRefs();
614
}, [projectCloneDone]);
615
+ // A checkout made outside T3 Code, such as a clone finishing, leaves refs listed before it.
616
+ const statusBranch = branchStatusQuery.data?.refName ?? null;
617
+ const refreshRefsMissingStatusBranch = useEffectEvent((branch: string | null) => {
618
+ if (isInitialBranchesLoadPending || branch === null) return;
619
+ if (branchByName.get(branch)?.current !== true) refreshStaleRefs();
620
+ });
621
+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- reloads refs from the server once per branch live status reports that they do not list as checked out
622
+ useEffect(() => {
623
+ refreshRefsMissingStatusBranch(statusBranch);
624
+ }, [statusBranch]);
625
626
// The server sets started threads' branches; defaulting here would detach the agent from its worktree.
627
const threadStarted = serverSession !== null;