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

Function offerIndexIgnoredRepos

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

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