Skip to content

Commit 352a504

Browse files
committed
refactor(server): simplify isGitRepository per review
Apply review suggestion: collapse the parent-walk into a single while loop using the dirname-equals-self termination check, and drop the redundant parse(cwd).root guard. Behavior is unchanged for every cwd the codebase actually passes in (always a sub-path of the repo).
1 parent aee131d commit 352a504

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

‎apps/server/src/git/Utils.ts‎

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,13 @@ import { Schema } from "effect";
88
import { TextGenerationError } from "@t3tools/contracts";
99

1010
import { existsSync } from "node:fs";
11-
import { dirname, join, parse } from "node:path";
12-
13-
export function isGitRepository(cwd: string): boolean {
14-
const root = parse(cwd).root;
15-
let current = cwd;
16-
while (true) {
17-
if (existsSync(join(current, ".git"))) {
18-
return true;
19-
}
20-
if (current === root) {
21-
return false;
22-
}
23-
const parent = dirname(current);
24-
if (parent === current) {
25-
return false;
26-
}
27-
current = parent;
11+
import { dirname, join } from "node:path";
12+
13+
export function isGitRepository(current: string): boolean {
14+
while (current !== (current = dirname(current))) {
15+
if (existsSync(join(current, ".git"))) return true;
2816
}
17+
return false;
2918
}
3019

3120
/** Convert an Effect Schema to a flat JSON Schema object, inlining `$defs` when present. */

0 commit comments

Comments
 (0)