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

Function discoverEmbeddedRepoRoots

src/extraction/index.ts:1194–1248  ·  view source on GitHub ↗
(rootDir: string)

Source from the content-addressed store, hash-verified

1192 * there already.
1193 */
1194export function discoverEmbeddedRepoRoots(rootDir: string): string[] {
1195 try {
1196 execFileSync('git', ['rev-parse', '--git-dir'], { cwd: rootDir, encoding: 'utf-8', timeout: 5000, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true });
1197 } catch {
1198 return [];
1199 }
1200 const out: string[] = [];
1201 const defaults = defaultsOnlyIgnore();
1202 const includeIgnored = loadIncludeIgnoredMatcher(rootDir);
1203 const visit = (repoAbs: string, prefix: string): void => {
1204 const candidates: string[] = [];
1205 try {
1206 const o = execFileSync(
1207 'git',
1208 ['ls-files', '-z', '-o', '--exclude-standard', '--directory'],
1209 { cwd: repoAbs, encoding: 'utf-8', timeout: 30000, maxBuffer: 50 * 1024 * 1024, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true }
1210 );
1211 for (const e of o.split('\0')) {
1212 if (e.endsWith('/') && !isWholeCwdEntry(e) && !defaults.ignores(e)) {
1213 candidates.push(...findNestedGitRepos(path.join(repoAbs, e), e));
1214 }
1215 }
1216 } catch { /* untracked listing failed — ignored-side discovery still runs */ }
1217 // Unexpanded gitlinks (mode 160000) with a real checkout on disk — embedded
1218 // repos `git add`ed without `.gitmodules`, or submodules not active here. The
1219 // untracked listing above can't see them (they're tracked), so find them the
1220 // same way collectGitFiles does, keeping watcher scope == indexer scope.
1221 // (#1031, #1033)
1222 try {
1223 const staged = lsFilesStaged(
1224 { cwd: repoAbs, encoding: 'utf-8', timeout: 30000, maxBuffer: 50 * 1024 * 1024, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true }
1225 );
1226 const repoIgnore = buildDefaultIgnore(repoAbs);
1227 for (const entry of staged.split('\0')) {
1228 if (!entry || !isGitlinkEntry(entry)) continue;
1229 const tab = entry.indexOf('\t');
1230 if (tab === -1) continue;
1231 const rel = entry.slice(tab + 1);
1232 const relDir = rel.endsWith('/') ? rel : rel + '/';
1233 // A gitlink under a gitignored path is respected (not indexed) unless the
1234 // project opted it in — same rule as the untracked-ignored kind (#1065).
1235 if (gitlinkEmbeddedRepoSkipped(relDir, prefix, defaults, repoIgnore, includeIgnored)) continue;
1236 if (classifyGitDir(path.join(repoAbs, rel)) === 'embedded') candidates.push(relDir);
1237 }
1238 } catch { /* staged listing failed — other discovery still runs */ }
1239 candidates.push(...findIgnoredEmbeddedRepos(repoAbs, includeIgnored, prefix));
1240 for (const rel of candidates) {
1241 const full = normalizePath(prefix + rel);
1242 out.push(full);
1243 visit(path.join(repoAbs, rel), full);
1244 }
1245 };
1246 visit(rootDir, '');
1247 return out;
1248}
1249
1250/**
1251 * Cap on how many skipped gitignored repos the CLI hint enumerates — a huge

Callers 3

extraction.test.tsFile · 0.90
buildScopeIgnoreFunction · 0.85

Calls 3

defaultsOnlyIgnoreFunction · 0.85
visitFunction · 0.70

Tested by

no test coverage detected