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

Function offerIndexIgnoredRepos

src/bin/codegraph.ts:577–641  ·  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

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