* 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)
| 1535 | * repository does not move under a running process. |
| 1536 | */ |
| 1537 | function gitRepoPrefix(dir: string): string { |
| 1538 | if (fs.existsSync(path.join(dir, '.git'))) return ''; |
| 1539 | const key = path.resolve(dir); |
| 1540 | let prefix = gitRepoPrefixes.get(key); |
| 1541 | if (prefix === undefined) { |
| 1542 | prefix = normalizePath(execFileSync( |
| 1543 | 'git', |
| 1544 | ['rev-parse', '--show-prefix'], |
| 1545 | { cwd: dir, encoding: 'utf-8', timeout: 5000, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true } |
| 1546 | ).trim()); |
| 1547 | gitRepoPrefixes.set(key, prefix); |
| 1548 | } |
| 1549 | return prefix; |
| 1550 | } |
| 1551 | |
| 1552 | /** |
| 1553 | * Get all files visible to git (tracked + untracked but not ignored). |
no test coverage detected