* Classify a directory's `.git` entry for embedded-repo discovery. * * - A `.git` **directory** is an embedded clone — distinct first-party code a * super-repo merely hides from git; index it (#193, #514). * - A `.git` **file** is a pointer (`gitdir: …`). A git **worktree** points into * th
(absDir: string)
| 378 | * Returns `'none'` when there is no `.git` entry here. |
| 379 | */ |
| 380 | function classifyGitDir(absDir: string): 'embedded' | 'worktree' | 'none' { |
| 381 | let st: fs.Stats; |
| 382 | try { |
| 383 | st = fs.statSync(path.join(absDir, '.git')); |
| 384 | } catch { |
| 385 | return 'none'; |
| 386 | } |
| 387 | if (st.isDirectory()) return 'embedded'; |
| 388 | if (!st.isFile()) return 'none'; |
| 389 | try { |
| 390 | const gitdir = fs.readFileSync(path.join(absDir, '.git'), 'utf8').match(/^gitdir:\s*(.+)$/m)?.[1]?.trim(); |
| 391 | // A worktree's gitdir lives under some repo's `.git/worktrees/<name>` — |
| 392 | // either the top-level repo's (`.git/worktrees/`) or, for a worktree of a |
| 393 | // submodule, that submodule's gitdir (`.git/modules/<module>/worktrees/`). |
| 394 | // The optional `modules/<module>` segment covers the submodule case (#945). |
| 395 | // Match both separators so a Windows-style pointer is recognized too. |
| 396 | if (gitdir && /(^|[\\/])\.git[\\/](modules[\\/][^\\/]+[\\/])?worktrees[\\/]/.test(gitdir)) return 'worktree'; |
| 397 | } catch { |
| 398 | // Unreadable `.git` pointer — fall back to the prior "index it" behavior. |
| 399 | } |
| 400 | return 'embedded'; |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Find git repositories nested under `absDir` (inclusive), shallow bounded BFS. |
no test coverage detected