The work tree's top level (as a rootKey), or null when unknown.
(projectRoot: string)
| 102 | |
| 103 | /** The work tree's top level (as a {@link rootKey}), or null when unknown. */ |
| 104 | function gitToplevelKey(projectRoot: string): string | null { |
| 105 | try { |
| 106 | const out = execFileSync('git', ['rev-parse', '--show-toplevel'], { |
| 107 | cwd: projectRoot, |
| 108 | encoding: 'utf8', |
| 109 | stdio: ['ignore', 'pipe', 'ignore'], |
| 110 | windowsHide: true, |
| 111 | timeout: 5000, // same rationale as isGitRepo |
| 112 | }).trim(); |
| 113 | return out ? rootKey(out) : null; |
| 114 | } catch { |
| 115 | return null; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | function shellQuote(value: string): string { |
| 120 | return `'${value.replace(/'/g, `'\\''`)}'`; |