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

Function ensureGitignore

src/directory.ts:623–638  ·  view source on GitHub ↗

* Write `.codegraph/.gitignore` if it's absent, or upgrade a stale * CodeGraph-generated default in place; a user-customized file is left alone. * Best-effort — returns `false` only if a needed write failed.

(gitignorePath: string)

Source from the content-addressed store, hash-verified

621 * Best-effort — returns `false` only if a needed write failed.
622 */
623function ensureGitignore(gitignorePath: string): boolean {
624 let existing: string | null;
625 try {
626 existing = fs.readFileSync(gitignorePath, 'utf-8');
627 } catch {
628 existing = null; // absent (ENOENT) or unreadable — (re)create below
629 }
630 // Current default or a user-authored file: nothing to do.
631 if (existing !== null && !isStaleDefaultGitignore(existing)) return true;
632 try {
633 fs.writeFileSync(gitignorePath, GITIGNORE_CONTENT, 'utf-8');
634 return true;
635 } catch {
636 return false;
637 }
638}
639
640/**
641 * Create the .codegraph directory structure

Callers 2

createDirectoryFunction · 0.85
validateDirectoryFunction · 0.85

Calls 1

isStaleDefaultGitignoreFunction · 0.85

Tested by

no test coverage detected