Skip to content

fix(directory): self-heal stale .codegraph/.gitignore so daemon.pid is ignored (#788)#802

Merged
colbymchenry merged 1 commit into
mainfrom
fix/gitignore-daemon-pid-788
Jun 11, 2026
Merged

fix(directory): self-heal stale .codegraph/.gitignore so daemon.pid is ignored (#788)#802
colbymchenry merged 1 commit into
mainfrom
fix/gitignore-daemon-pid-788

Conversation

@colbymchenry

Copy link
Copy Markdown
Owner

What

Closes #788.

.codegraph/.gitignore files written by CodeGraph ≤ 0.9.9 use an explicit allowlist (*.db, cache/, .dirty, …) that never ignored daemon.pid or 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.ts now self-heals:

  • ensureGitignore() — writes the file if absent, upgrades a stale CodeGraph-generated default in place, and leaves a user-authored file untouched.
  • "Stale default" = carries our # CodeGraph data files header 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).
  • Wired into both createDirectory and validateDirectory. Since validateDirectory runs on every open() / 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.
  • The gitignore template (previously duplicated in two formats) is consolidated into one GITIGNORE_CONTENT constant.

Tests

  • Two new unit tests in foundation.test.ts: a stale pre-wildcard gitignore is upgraded on open; a user-customized one is left byte-for-byte intact.
  • Full suite green (the only red is a pre-existing daemon process-lifecycle timing flake that passes in isolation; 2 skipped are Windows-only).
  • End-to-end via the built binary: planted a v0.9.9 stale gitignore → ran codegraph status → it healed to the wildcard form → git check-ignore confirms .codegraph/daemon.pid is now ignored.

🤖 Generated with Claude Code

… 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>
@colbymchenry colbymchenry merged commit 9a0f144 into main Jun 11, 2026
@colbymchenry colbymchenry deleted the fix/gitignore-daemon-pid-788 branch June 11, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.codegraph/.gitignore should include daemon.pid

1 participant