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

Function offerIndexIgnoredRepos

src/bin/codegraph.ts:596–660  ·  view source on GitHub ↗

* When an `init`/`index` produced an EMPTY graph and the reason is that the * project's own `.gitignore` excludes nested git repositories — the "super-repo * gitignores its child repos" layout (#1156), where `init` at the parent * correctly indexes ~nothing while `init` inside each child works —

(
  clack: typeof import('@clack/prompts'),
  projectPath: string,
  reindex: () => Promise<IndexResult>,
  opts: { interactive: boolean },
)

Source from the content-addressed store, hash-verified

594 * (#970, #1065). Best-effort throughout: detection never breaks the command.
595 */
596async function offerIndexIgnoredRepos(
597 clack: typeof import('@clack/prompts'),
598 projectPath: string,
599 reindex: () => Promise<IndexResult>,
600 opts: { interactive: boolean },
601): Promise<IndexResult | undefined> {
602 let repos: string[];
603 let patterns: string[];
604 try {
605 const { findUnindexedIgnoredRepos, includeIgnoredPatternFor } = await import('../extraction');
606 repos = findUnindexedIgnoredRepos(projectPath);
607 patterns = repos.map(includeIgnoredPatternFor);
608 } catch {
609 return; // detection is advisory — never let it break the command
610 }
611 if (repos.length === 0) return;
612
613 const { PROJECT_CONFIG_FILENAME } = await import('../project-config');
614 const isOne = repos.length === 1;
615 const SHOWN = 6;
616 const names = repos.slice(0, SHOWN).map((r) => r.replace(/\/$/, ''));
617 const extra = repos.length > SHOWN ? ` (+${formatNumber(repos.length - SHOWN)} more)` : '';
618 const snippet = `{ "includeIgnored": [${patterns.map((p) => JSON.stringify(p)).join(', ')}] }`;
619
620 clack.log.warn(
621 `Your .gitignore excludes ${isOne ? 'a nested git repository' : `${formatNumber(repos.length)} nested git repositories`} here, ` +
622 `so ${isOne ? 'it was' : 'they were'} not indexed: ${names.join(', ')}${extra}.`,
623 );
624
625 const manualHint = () => {
626 clack.log.info(
627 `If ${isOne ? "it's" : "they're"} your code, add ${isOne ? 'it' : 'them'} to ${PROJECT_CONFIG_FILENAME} and re-index:`,
628 );
629 clack.log.info(` ${snippet}`);
630 };
631
632 if (!opts.interactive || !process.stdin.isTTY) {
633 manualHint();
634 return;
635 }
636
637 const yes = await clack.confirm({
638 message: `Index ${isOne ? 'it' : `these ${formatNumber(repos.length)}`} now? Adds ${isOne ? 'it' : 'them'} to ${PROJECT_CONFIG_FILENAME}.`,
639 initialValue: true,
640 });
641 if (clack.isCancel(yes) || !yes) {
642 manualHint();
643 return;
644 }
645
646 let added: number;
647 try {
648 const { addIncludeIgnoredPatterns } = await import('../project-config');
649 added = addIncludeIgnoredPatterns(projectPath, patterns);
650 } catch (err) {
651 clack.log.error(`Could not update ${PROJECT_CONFIG_FILENAME}: ${err instanceof Error ? err.message : String(err)}`);
652 manualHint();
653 return;

Callers 2

runInitFunction · 0.85
mainFunction · 0.85

Calls 11

getGlyphsFunction · 0.90
manualHintFunction · 0.85
reindexFunction · 0.85
printIndexResultFunction · 0.85
mapMethod · 0.80
warnMethod · 0.80
formatNumberFunction · 0.70
errorMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected