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.

Filter detached HEAD pseudo-refs from branch listings

Julius Marminge29825f2f8a7c
diff --git a/apps/server/src/git/Layers/GitCore.test.ts b/apps/server/src/git/Layers/GitCore.test.ts
index 2325f8e5f..2667c7aaa 100644
--- a/apps/server/src/git/Layers/GitCore.test.ts
+++ b/apps/server/src/git/Layers/GitCore.test.ts
@@ -266,6 +266,18 @@ it.layer(TestLayer)("git integration", (it) => {
}),
);
+ it.effect("does not include detached HEAD pseudo-refs as branches", () =>
+ Effect.gen(function* () {
+ const tmp = yield* makeTmpDir();
+ yield* initRepoWithCommit(tmp);
+ yield* git(tmp, ["checkout", "--detach", "HEAD"]);
+
+ const result = yield* listGitBranches({ cwd: tmp });
+ expect(result.branches.some((branch) => branch.name.startsWith("("))).toBe(false);
+ expect(result.branches.some((branch) => branch.current)).toBe(false);
+ }),
+ );
+
it.effect("keeps current branch first and sorts the remaining branches by recency", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
diff --git a/apps/server/src/git/Layers/GitCore.ts b/apps/server/src/git/Layers/GitCore.ts
index 76968fcde..d3b7fc567 100644
--- a/apps/server/src/git/Layers/GitCore.ts
+++ b/apps/server/src/git/Layers/GitCore.ts
@@ -82,7 +82,8 @@ function parseBranchLine(line: string): { name: string; current: boolean } | nul
const name = trimmed.replace(/^[*+]\s+/, "");
// Exclude symbolic refs like: "origin/HEAD -> origin/main".
- if (name.includes(" -> ")) return null;
+ // Exclude detached HEAD pseudo-refs like: "(HEAD detached at origin/main)".
+ if (name.includes(" -> ") || name.startsWith("(")) return null;
return {
name,