* 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 },
)
| 480 | * (#970, #1065). Best-effort throughout: detection never breaks the command. |
| 481 | */ |
| 482 | async function offerIndexIgnoredRepos( |
| 483 | clack: typeof import('@clack/prompts'), |
| 484 | projectPath: string, |
| 485 | reindex: () => Promise<IndexResult>, |
| 486 | opts: { interactive: boolean }, |
| 487 | ): Promise<IndexResult | undefined> { |
| 488 | let repos: string[]; |
| 489 | try { |
| 490 | const { findUnindexedIgnoredRepos } = await import('../extraction'); |
| 491 | repos = findUnindexedIgnoredRepos(projectPath); |
| 492 | } catch { |
| 493 | return; // detection is advisory — never let it break the command |
| 494 | } |
| 495 | if (repos.length === 0) return; |
| 496 | |
| 497 | const { PROJECT_CONFIG_FILENAME } = await import('../project-config'); |
| 498 | const isOne = repos.length === 1; |
| 499 | const SHOWN = 6; |
| 500 | const names = repos.slice(0, SHOWN).map((r) => r.replace(/\/$/, '')); |
| 501 | const extra = repos.length > SHOWN ? ` (+${formatNumber(repos.length - SHOWN)} more)` : ''; |
| 502 | const snippet = `{ "includeIgnored": [${repos.map((p) => JSON.stringify(p)).join(', ')}] }`; |
| 503 | |
| 504 | clack.log.warn( |
| 505 | `Your .gitignore excludes ${isOne ? 'a nested git repository' : `${formatNumber(repos.length)} nested git repositories`} here, ` + |
| 506 | `so ${isOne ? 'it was' : 'they were'} not indexed: ${names.join(', ')}${extra}.`, |
| 507 | ); |
| 508 | |
| 509 | const manualHint = () => { |
| 510 | clack.log.info( |
| 511 | `If ${isOne ? "it's" : "they're"} your code, add ${isOne ? 'it' : 'them'} to ${PROJECT_CONFIG_FILENAME} and re-index:`, |
| 512 | ); |
| 513 | clack.log.info(` ${snippet}`); |
| 514 | }; |
| 515 | |
| 516 | if (!opts.interactive || !process.stdin.isTTY) { |
| 517 | manualHint(); |
| 518 | return; |
| 519 | } |
| 520 | |
| 521 | const yes = await clack.confirm({ |
| 522 | message: `Index ${isOne ? 'it' : `these ${formatNumber(repos.length)}`} now? Adds ${isOne ? 'it' : 'them'} to ${PROJECT_CONFIG_FILENAME}.`, |
| 523 | initialValue: true, |
| 524 | }); |
| 525 | if (clack.isCancel(yes) || !yes) { |
| 526 | manualHint(); |
| 527 | return; |
| 528 | } |
| 529 | |
| 530 | let added: number; |
| 531 | try { |
| 532 | const { addIncludeIgnoredPatterns } = await import('../project-config'); |
| 533 | added = addIncludeIgnoredPatterns(projectPath, repos); |
| 534 | } catch (err) { |
| 535 | clack.log.error(`Could not update ${PROJECT_CONFIG_FILENAME}: ${err instanceof Error ? err.message : String(err)}`); |
| 536 | manualHint(); |
| 537 | return; |
| 538 | } |
| 539 | clack.log.success(`Added ${formatNumber(added)} ${added === 1 ? 'entry' : 'entries'} to ${PROJECT_CONFIG_FILENAME} ${getGlyphs().dash} re-indexing…`); |
no test coverage detected