fix(directory): self-heal stale .codegraph/.gitignore so daemon.pid is ignored (#788)#802
Merged
Merged
Conversation
… is ignored (#788) Versions <= 0.9.9 wrote an explicit-allowlist .codegraph/.gitignore (*.db, cache/, .dirty, ...) that never listed daemon.pid or the socket, so the daemon's runtime pidfile got committed. The wildcard rewrite in #654/#492/#484 fixed new inits, but the file is only written when absent, so existing installs kept their stale file forever — the fix never reached the people hitting it. Make the gitignore self-heal: ensureGitignore() writes the file if absent and upgrades a stale CodeGraph-generated default in place, leaving a user-authored file untouched. A "stale default" is one that carries our `# CodeGraph data files` header but predates the wildcard ignore (no bare `*` line) — a header match heals every historical variant (v0.7.x..0.9.9, all verified to share it) and is idempotent. validateDirectory() runs on every open()/openSync(), so existing repos heal on the next codegraph command after upgrading. The duplicated template (previously inlined in two formats) is consolidated into one GITIGNORE_CONTENT constant. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Closes #788.
.codegraph/.gitignorefiles written by CodeGraph ≤ 0.9.9 use an explicit allowlist (*.db,cache/,.dirty, …) that never ignoreddaemon.pidor the daemon socket — so those runtime files get committed to git.The wildcard rewrite in #654 / #492 / #484 fixed this for new inits, but the gitignore is only ever written when absent. Existing installs keep their stale file indefinitely, so the fix never reaches anyone who already ran
codegraph init— including the reporter on 0.9.9.How
src/directory.tsnow self-heals:ensureGitignore()— writes the file if absent, upgrades a stale CodeGraph-generated default in place, and leaves a user-authored file untouched.# CodeGraph data filesheader but predates the wildcard ignore (no bare*line). Matching on the header rather than a byte-exact list of past defaults heals every historical variant (v0.7.x → 0.9.9 — all verified to share that header), is idempotent once upgraded, and never touches a file the user wrote (no header → skipped).createDirectoryandvalidateDirectory. SincevalidateDirectoryruns on everyopen()/openSync(), existing repos heal on the next codegraph command after upgrading. The prior "missing & uncreatable → error" semantics are preserved; a failed in-place upgrade is non-fatal.GITIGNORE_CONTENTconstant.Tests
foundation.test.ts: a stale pre-wildcard gitignore is upgraded on open; a user-customized one is left byte-for-byte intact.codegraph status→ it healed to the wildcard form →git check-ignoreconfirms.codegraph/daemon.pidis now ignored.🤖 Generated with Claude Code