(directory: string)
| 48 | * @returns The git repository root path, or null if not in a git repository |
| 49 | */ |
| 50 | export function findGitRoot(directory: string): string | null { |
| 51 | try { |
| 52 | let currentDir = path.resolve(directory); |
| 53 | |
| 54 | while (true) { |
| 55 | const gitDir = path.join(currentDir, '.git'); |
| 56 | |
| 57 | if (fs.existsSync(gitDir)) { |
| 58 | return currentDir; |
| 59 | } |
| 60 | |
| 61 | const parentDir = path.dirname(currentDir); |
| 62 | |
| 63 | if (parentDir === currentDir) { |
| 64 | break; |
| 65 | } |
| 66 | |
| 67 | currentDir = parentDir; |
| 68 | } |
| 69 | |
| 70 | return null; |
| 71 | } catch (_error) { |
| 72 | return null; |
| 73 | } |
| 74 | } |
nothing calls this directly
no outgoing calls
no test coverage detected