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

Function findNestedGitRepos

src/extraction/index.ts:959–996  ·  view source on GitHub ↗

* Find git repositories nested under `absDir` (inclusive), shallow bounded BFS. * Stops descending at each repo root found — contents belong to that repo's own * enumeration. Skips default-ignored dirs (`node_modules` can contain `.git` * from npm git-dependencies — that never makes it project co

(absDir: string, relPrefix: string)

Source from the content-addressed store, hash-verified

957 * data dirs. Depth- and entry-capped so a huge ignored tree can't stall the scan.
958 */
959function findNestedGitRepos(absDir: string, relPrefix: string): string[] {
960 const found: string[] = [];
961 const defaults = defaultsOnlyIgnore();
962 const queue: Array<{ abs: string; rel: string; depth: number }> = [
963 { abs: absDir, rel: relPrefix, depth: 0 },
964 ];
965 let examined = 0;
966 while (queue.length > 0) {
967 const { abs, rel, depth } = queue.shift()!;
968 if (++examined > EMBEDDED_REPO_SEARCH_ENTRIES) {
969 logDebug('Embedded-repo search entry cap hit — deeper repos (if any) not discovered', { under: relPrefix });
970 break;
971 }
972 const cls = classifyGitDir(abs);
973 if (cls === 'worktree') {
974 continue; // a git worktree duplicates an already-indexed repo (#848) — skip
975 }
976 if (cls === 'embedded') {
977 found.push(rel);
978 continue; // its own git handles everything below
979 }
980 if (depth >= EMBEDDED_REPO_SEARCH_DEPTH) continue;
981 let entries: fs.Dirent[];
982 try {
983 entries = fs.readdirSync(abs, { withFileTypes: true });
984 } catch {
985 continue;
986 }
987 for (const entry of entries) {
988 if (!entry.isDirectory()) continue;
989 if (entry.name === '.git' || isCodeGraphDataDir(entry.name)) continue;
990 const childRel = rel + entry.name + '/';
991 if (defaults.ignores(childRel)) continue;
992 queue.push({ abs: path.join(abs, entry.name), rel: childRel, depth: depth + 1 });
993 }
994 }
995 return found;
996}
997
998/**
999 * Workspace-scope ignore matcher. Ordinary paths get the root's matcher

Callers 4

visitFunction · 0.85
findIgnoredEmbeddedReposFunction · 0.85
collectGitStatusFunction · 0.85

Calls 7

logDebugFunction · 0.90
isCodeGraphDataDirFunction · 0.90
defaultsOnlyIgnoreFunction · 0.85
classifyGitDirFunction · 0.85
pushMethod · 0.80
ignoresMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected