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

Function gitRepoPrefix

src/extraction/index.ts:1537–1550  ·  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

1535 * repository does not move under a running process.
1536 */
1537function 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).

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