* The sparse checkout of the repository holding `dir`, as a stamp to compare * (INDEXED_SPARSE_CHECKOUT_KEY): a hash of its patterns and of the config * lines that switch them, since `git sparse-checkout disable` leaves the patterns * as they were. No git process, so this is safe on every
(dir: string)
| 532 | * whole cost and the answer, ''. |
| 533 | */ |
| 534 | function sparseCheckoutStamp(dir: string): string { |
| 535 | let repoRoot = path.resolve(dir); |
| 536 | while (!fs.existsSync(path.join(repoRoot, '.git'))) { |
| 537 | const parent = path.dirname(repoRoot); |
| 538 | if (parent === repoRoot) return ''; |
| 539 | repoRoot = parent; |
| 540 | } |
| 541 | const gitDir = resolveGitDir(repoRoot); |
| 542 | if (!gitDir) return ''; |
| 543 | let patterns: string; |
| 544 | try { |
| 545 | patterns = fs.readFileSync(path.join(gitDir, 'info', 'sparse-checkout'), 'utf8'); |
| 546 | } catch { |
| 547 | return ''; |
| 548 | } |
| 549 | // Which of the two git writes depends on `extensions.worktreeConfig`, and a |
| 550 | // linked worktree's git dir holds only its own `config.worktree`. |
| 551 | const switches = ['config', 'config.worktree'].flatMap((name) => { |
| 552 | try { |
| 553 | return fs.readFileSync(path.join(gitDir, name), 'utf8').split('\n').filter((line) => /sparsecheckout/i.test(line)); |
| 554 | } catch { |
| 555 | return []; |
| 556 | } |
| 557 | }); |
| 558 | return hashContent(`${patterns}\0${switches.join('\n')}`); |
| 559 | } |
| 560 | |
| 561 | /** Expand a leading `~/` the way git does for `core.excludesFile`. */ |
| 562 | function expandUserPath(p: string): string { |
no test coverage detected