Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(server): handle unborn HEAD in VCS status (#5944)

t3-code[bot]9c7622dac3d1
diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts
index 6e352f013..18e594512 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts
@@ -1001,6 +1001,23 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
}),
);
+ it.effect("reports remote status on unborn HEAD without failing", () =>
+ Effect.gen(function* () {
+ const cwd = yield* makeTmpDir();
+ const driver = yield* GitVcsDriver.GitVcsDriver;
+ yield* driver.initRepo({ cwd });
+ const initialBranch = yield* git(cwd, ["symbolic-ref", "--short", "HEAD"]);
+
+ const status = yield* driver.statusDetailsRemote(cwd, { refreshUpstream: false });
+
+ assert.equal(status.isRepo, true);
+ assert.equal(status.branch, initialBranch);
+ assert.equal(status.hasUpstream, false);
+ assert.equal(status.aheadCount, 0);
+ assert.equal(status.behindCount, 0);
+ }),
+ );
+
it.effect("can read cached remote divergence without fetching upstream", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts
index 5b9359ada..1489db9b3 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.ts
@@ -1477,25 +1477,35 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
if (branchResult === null) {
return NON_REPOSITORY_REMOTE_STATUS_DETAILS;
}
+ let branch: string | null;
if (branchResult.exitCode !== 0) {
if (isNonRepositoryGitStderr(branchResult.stderr)) {
return NON_REPOSITORY_REMOTE_STATUS_DETAILS;
}
- return yield* new GitCommandError({
- ...gitCommandContext({
- operation: "GitVcsDriver.statusDetailsRemote.branch",
- cwd,
- args: ["rev-parse", "--abbrev-ref", "HEAD"],
- }),
- detail: "Git branch lookup failed.",
- exitCode: branchResult.exitCode,
- stdoutLength: branchResult.stdout.length,
- stderrLength: branchResult.stderr.length,
- });
- }
+ if (!isUnbornHeadStderr(branchResult.stderr)) {
+ return yield* new GitCommandError({
+ ...gitCommandContext({
+ operation: "GitVcsDriver.statusDetailsRemote.branch",
+ cwd,
+ args: ["rev-parse", "--abbrev-ref", "HEAD"],
+ }),
+ detail: "Git branch lookup failed.",
+ exitCode: branchResult.exitCode,
+ stdoutLength: branchResult.stdout.length,
+ stderrLength: branchResult.stderr.length,
+ });
+ }
- const branchValue = branchResult.stdout.trim();
- const branch = branchValue.length > 0 && branchValue !== "HEAD" ? branchValue : null;
+ const branchValue = yield* runGitStdout(
+ "GitVcsDriver.statusDetailsRemote.unbornBranch",
+ cwd,
+ ["symbolic-ref", "--quiet", "--short", "HEAD"],
+ );
+ branch = branchValue.trim() || null;
+ } else {
+ const branchValue = branchResult.stdout.trim();
+ branch = branchValue.length > 0 && branchValue !== "HEAD" ? branchValue : null;
+ }
const upstream = yield* resolveCurrentUpstream(cwd);
const upstreamRef = upstream?.upstreamRef ?? null;
let aheadCount = 0;