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