MCPcopy Create free account
hub / github.com/devcontainers/cli / findGitRootFolder

Function findGitRootFolder

src/spec-common/git.ts:10–33  ·  view source on GitHub ↗
(cliHost: FileHost | CLIHost, folderPath: string, output: Log)

Source from the content-addressed store, hash-verified

8import { FileHost } from '../spec-utils/pfs';
9
10export 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}

Callers 1

getHostMountFolderFunction · 0.90

Calls 2

runCommandNoPtyFunction · 0.90
isFileMethod · 0.65

Tested by

no test coverage detected