(
localRepoIndex: Map<string, number>,
)
| 66 | } |
| 67 | |
| 68 | export async function collectLocalReposConfig( |
| 69 | localRepoIndex: Map<string, number>, |
| 70 | ): Promise<CollectResult> { |
| 71 | note( |
| 72 | [ |
| 73 | 'Point at a directory on your machine that contains git repositories.', |
| 74 | `The wizard will scan up to ${MAX_DEPTH} levels deep and let you pick which to index.`, |
| 75 | 'Local repos are treated as read-only.', |
| 76 | ].join('\n'), |
| 77 | 'Local Git repositories', |
| 78 | ); |
| 79 | |
| 80 | let hostPath: string; |
| 81 | let repos: string[]; |
| 82 | |
| 83 | // eslint-disable-next-line no-constant-condition |
| 84 | while (true) { |
| 85 | const rawPath = await input({ |
| 86 | message: 'Path to your repos directory (e.g. ~/code)', |
| 87 | validate: (v) => { |
| 88 | if (!v?.trim()) { |
| 89 | return 'Path is required'; |
| 90 | } |
| 91 | const resolved = expandHostPath(v); |
| 92 | if (!existsSync(resolved)) { |
| 93 | return `Path does not exist: ${resolved}`; |
| 94 | } |
| 95 | if (!statSync(resolved).isDirectory()) { |
| 96 | return `Not a directory: ${resolved}`; |
| 97 | } |
| 98 | return true; |
| 99 | }, |
| 100 | }); |
| 101 | |
| 102 | hostPath = expandHostPath(rawPath); |
| 103 | |
| 104 | const spinner = ora(`Scanning ${hostPath} for git repositories...`).start(); |
| 105 | repos = await findGitRepos(hostPath, MAX_DEPTH); |
| 106 | if (repos.length === 0) { |
| 107 | spinner.fail(`No git repositories found under ${hostPath}`); |
| 108 | continue; |
| 109 | } |
| 110 | spinner.succeed(`Found ${repos.length} repositor${repos.length === 1 ? 'y' : 'ies'}`); |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | let index = localRepoIndex.get(hostPath); |
| 115 | if (index === undefined) { |
| 116 | index = localRepoIndex.size; |
| 117 | localRepoIndex.set(hostPath, index); |
| 118 | } |
| 119 | const containerRoot = `/repos/${index}`; |
| 120 | |
| 121 | const hostPathIsRepo = repos.length === 1 && repos[0] === hostPath; |
| 122 | if (hostPathIsRepo) { |
| 123 | return { |
| 124 | connections: [{ |
| 125 | name: basename(hostPath), |
no test coverage detected