* Where `dir` sits in its git repository: '' at the repository's root, else the * path from the root with a trailing slash (`app/`). Throws when `dir` is in no * repository. `git status --porcelain` prints every path from the repository's * root, whichever folder it runs in, so a project below th
(dir: string)
| 1519 | * repository does not move under a running process. |
| 1520 | */ |
| 1521 | function gitRepoPrefix(dir: string): string { |
| 1522 | if (fs.existsSync(path.join(dir, '.git'))) return ''; |
| 1523 | const key = path.resolve(dir); |
| 1524 | let prefix = gitRepoPrefixes.get(key); |
| 1525 | if (prefix === undefined) { |
| 1526 | prefix = normalizePath(execFileSync( |
| 1527 | 'git', |
| 1528 | ['rev-parse', '--show-prefix'], |
| 1529 | { cwd: dir, encoding: 'utf-8', timeout: 5000, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true } |
| 1530 | ).trim()); |
| 1531 | gitRepoPrefixes.set(key, prefix); |
| 1532 | } |
| 1533 | return prefix; |
| 1534 | } |
| 1535 | |
| 1536 | /** |
| 1537 | * Get all files visible to git (tracked + untracked but not ignored). |
no test coverage detected