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

Function offerIndexIgnoredRepos

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

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