Skip to content

Commit 2012225

Browse files
anandgupta42claude
andcommitted
fix: treat empty git branch as undefined in detectGit
In CI detached HEAD, git branch --show-current returns an empty string. Convert empty string to undefined so callers get a clean undefined instead of "". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c85804d commit 2012225

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

packages/altimate-code/src/tool/project-scan.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export async function detectGit(): Promise<GitInfo> {
5656
stdout: "pipe",
5757
stderr: "pipe",
5858
})
59-
const branch = branchResult.exitCode === 0 ? branchResult.stdout.toString().trim() : undefined
59+
const branch = branchResult.exitCode === 0 ? branchResult.stdout.toString().trim() || undefined : undefined
6060

6161
let remoteUrl: string | undefined
6262
const remoteResult = Bun.spawnSync(["git", "remote", "get-url", "origin"], {

packages/altimate-code/test/tool/project-scan.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ describe("detectGit", () => {
4848
expect(typeof result.branch).toBe("string")
4949
})
5050

51-
test("returns a branch name or undefined in detached HEAD", async () => {
51+
test("branch is a non-empty string or undefined (detached HEAD)", async () => {
5252
const result = await detectGit()
53-
// In CI, GitHub Actions checks out in detached HEAD, so branch may be undefined
53+
// In CI, GitHub Actions checks out in detached HEAD → branch is undefined
54+
// Locally, branch is a non-empty string
5455
if (result.branch !== undefined) {
56+
expect(typeof result.branch).toBe("string")
5557
expect(result.branch.length).toBeGreaterThan(0)
5658
}
5759
})

0 commit comments

Comments
 (0)