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

Function classifyGitDir

src/extraction/index.ts:547–568  ·  view source on GitHub ↗

* Classify a directory's `.git` entry for embedded-repo discovery. * * - A `.git` **directory** is an embedded clone — distinct first-party code a * super-repo merely hides from git; index it (#193, #514). * - A `.git` **file** is a pointer (`gitdir: …`). A git **worktree** points into * th

(absDir: string)

Source from the content-addressed store, hash-verified

545 * Returns `'none'` when there is no `.git` entry here.
546 */
547function classifyGitDir(absDir: string): 'embedded' | 'worktree' | 'none' {
548 let st: fs.Stats;
549 try {
550 st = fs.statSync(path.join(absDir, '.git'));
551 } catch {
552 return 'none';
553 }
554 if (st.isDirectory()) return 'embedded';
555 if (!st.isFile()) return 'none';
556 try {
557 const gitdir = fs.readFileSync(path.join(absDir, '.git'), 'utf8').match(/^gitdir:\s*(.+)$/m)?.[1]?.trim();
558 // A worktree's gitdir lives under some repo's `.git/worktrees/<name>` —
559 // either the top-level repo's (`.git/worktrees/`) or, for a worktree of a
560 // submodule, that submodule's gitdir (`.git/modules/<module>/worktrees/`).
561 // The optional `modules/<module>` segment covers the submodule case (#945).
562 // Match both separators so a Windows-style pointer is recognized too.
563 if (gitdir && /(^|[\\/])\.git[\\/](modules[\\/][^\\/]+[\\/])?worktrees[\\/]/.test(gitdir)) return 'worktree';
564 } catch {
565 // Unreadable `.git` pointer — fall back to the prior "index it" behavior.
566 }
567 return 'embedded';
568}
569
570/**
571 * Find git repositories nested under `absDir` (inclusive), shallow bounded BFS.

Callers 3

findNestedGitReposFunction · 0.85
visitFunction · 0.85
collectGitFilesFunction · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected