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

Function sparseCheckoutStamp

src/extraction/index.ts:534–559  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

532 * whole cost and the answer, ''.
533 */
534function 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`. */
562function expandUserPath(p: string): string {

Callers 2

beginGitIndexStateMethod · 0.85
sparseCheckoutChangesMethod · 0.85

Calls 4

resolveGitDirFunction · 0.85
hashContentFunction · 0.85
resolveMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected