(dir: string)
| 56 | * from a nested repo the parent index already covers. Null when not a repo. |
| 57 | */ |
| 58 | export function gitCommonDir(dir: string): string | null { |
| 59 | try { |
| 60 | const out = execFileSync('git', ['rev-parse', '--git-common-dir'], { |
| 61 | cwd: dir, |
| 62 | encoding: 'utf8', |
| 63 | stdio: ['ignore', 'pipe', 'ignore'], |
| 64 | windowsHide: true, |
| 65 | timeout: 5000, // same rationale as gitWorktreeRoot |
| 66 | }).trim(); |
| 67 | if (!out) return null; |
| 68 | // `--git-common-dir` is relative to cwd unless already absolute. |
| 69 | return realpath(path.isAbsolute(out) ? out : path.resolve(dir, out)); |
| 70 | } catch { |
| 71 | return null; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | export interface WorktreeIndexMismatch { |
| 76 | /** The git working tree the command was run from. */ |
no test coverage detected