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

Function findNestedGitRepos

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

941 * data dirs. Depth- and entry-capped so a huge ignored tree can't stall the scan.
942 */
943function findNestedGitRepos(absDir: string, relPrefix: string): string[] {
944 const found: string[] = [];
945 const defaults = defaultsOnlyIgnore();
946 const queue: Array<{ abs: string; rel: string; depth: number }> = [
947 { abs: absDir, rel: relPrefix, depth: 0 },
948 ];
949 let examined = 0;
950 while (queue.length > 0) {
951 const { abs, rel, depth } = queue.shift()!;
952 if (++examined > EMBEDDED_REPO_SEARCH_ENTRIES) {
953 logDebug('Embedded-repo search entry cap hit — deeper repos (if any) not discovered', { under: relPrefix });
954 break;
955 }
956 const cls = classifyGitDir(abs);
957 if (cls === 'worktree') {
958 continue; // a git worktree duplicates an already-indexed repo (#848) — skip
959 }
960 if (cls === 'embedded') {
961 found.push(rel);
962 continue; // its own git handles everything below
963 }
964 if (depth >= EMBEDDED_REPO_SEARCH_DEPTH) continue;
965 let entries: fs.Dirent[];
966 try {
967 entries = fs.readdirSync(abs, { withFileTypes: true });
968 } catch {
969 continue;
970 }
971 for (const entry of entries) {
972 if (!entry.isDirectory()) continue;
973 if (entry.name === '.git' || isCodeGraphDataDir(entry.name)) continue;
974 const childRel = rel + entry.name + '/';
975 if (defaults.ignores(childRel)) continue;
976 queue.push({ abs: path.join(abs, entry.name), rel: childRel, depth: depth + 1 });
977 }
978 }
979 return found;
980}
981
982/**
983 * 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