MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / gitRepoPrefix

Function gitRepoPrefix

src/extraction/index.ts:1521–1534  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

1519 * repository does not move under a running process.
1520 */
1521function 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).

Callers 1

getGitChangedFilesFunction · 0.85

Calls 5

normalizePathFunction · 0.90
resolveMethod · 0.65
getMethod · 0.65
joinMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected