- ignore branch lines starting with `(` when parsing `git branch` output - add integration test to verify detached HEAD does not appear as a branch
Unified · Split
| @@ -266,6 +266,18 @@ it.layer(TestLayer)("git integration", (it) => { · 265 unmodified lines | ||
| 266 | 266 | }), |
| 267 | 267 | ); |
| 268 | 268 | |
| 269 | + it.effect("does not include detached HEAD pseudo-refs as branches", () => | |
| 270 | + Effect.gen(function* () { | |
| 271 | + const tmp = yield* makeTmpDir(); | |
| 272 | + yield* initRepoWithCommit(tmp); | |
| 273 | + yield* git(tmp, ["checkout", "--detach", "HEAD"]); | |
| 274 | + | |
| 275 | + const result = yield* listGitBranches({ cwd: tmp }); | |
| 276 | + expect(result.branches.some((branch) => branch.name.startsWith("("))).toBe(false); | |
| 277 | + expect(result.branches.some((branch) => branch.current)).toBe(false); | |
| 278 | + }), | |
| 279 | + ); | |
| 280 | + | |
| 269 | 281 | it.effect("keeps current branch first and sorts the remaining branches by recency", () => |
| 270 | 282 | Effect.gen(function* () { |
| 271 | 283 | const tmp = yield* makeTmpDir(); |
| @@ -82,7 +82,8 @@ function parseBranchLine(line: string): { name: string; current: boolean } | nul · 81 unmodified lines | ||
| 82 | 82 | |
| 83 | 83 | const name = trimmed.replace(/^[*+]\s+/, ""); |
| 84 | 84 | // Exclude symbolic refs like: "origin/HEAD -> origin/main". |
| 85 | − if (name.includes(" -> ")) return null; | |
| 85 | + // Exclude detached HEAD pseudo-refs like: "(HEAD detached at origin/main)". | |
| 86 | + if (name.includes(" -> ") || name.startsWith("(")) return null; | |
| 86 | 87 | |
| 87 | 88 | return { |
| 88 | 89 | name, |