(cliHost: FileHost | CLIHost, folderPath: string, output: Log)
| 8 | import { FileHost } from '../spec-utils/pfs'; |
| 9 | |
| 10 | export async function findGitRootFolder(cliHost: FileHost | CLIHost, folderPath: string, output: Log) { |
| 11 | if (!('exec' in cliHost)) { |
| 12 | for (let current = folderPath, previous = ''; current !== previous; previous = current, current = cliHost.path.dirname(current)) { |
| 13 | if (await cliHost.isFile(cliHost.path.join(current, '.git', 'config'))) { |
| 14 | return current; |
| 15 | } |
| 16 | } |
| 17 | return undefined; |
| 18 | } |
| 19 | try { |
| 20 | // Preserves symlinked paths (unlike --show-toplevel). |
| 21 | const { stdout } = await runCommandNoPty({ |
| 22 | exec: cliHost.exec, |
| 23 | cmd: 'git', |
| 24 | args: ['rev-parse', '--show-cdup'], |
| 25 | cwd: folderPath, |
| 26 | output, |
| 27 | }); |
| 28 | const cdup = stdout.toString().trim(); |
| 29 | return cliHost.path.resolve(folderPath, cdup); |
| 30 | } catch { |
| 31 | return undefined; |
| 32 | } |
| 33 | } |
no test coverage detected