fix(init): make the generated .codegraph index invisible to git in every repo (#492) - #1601
Open
walterf3 wants to merge 1 commit into
Open
fix(init): make the generated .codegraph index invisible to git in every repo (#492)#1601walterf3 wants to merge 1 commit into
walterf3 wants to merge 1 commit into
Conversation
…where (colbymchenry#492) `.codegraph/.gitignore` ended with `!.gitignore`, which un-ignored the generated file itself. Git therefore had one non-ignored path under the data dir, so in any repository whose root `.gitignore` has no rule for `.codegraph/` — i.e. every consumer repo — `git status` reported the whole generated index as untracked work: ?? .codegraph/ # git status ?? .codegraph/.gitignore # git status -uall This is the residual of colbymchenry#492: the issue asked for "the entire `.codegraph/` directory is not tracked by Git" and suggested `*` + `!.gitignore`, but that suggestion cannot deliver it. Git reads and honors an ignore file that ignores itself, so dropping the negation is what actually hides the directory — with no edit to the consumer's own root `.gitignore`, which CodeGraph has no business writing to. - Generated content is now a bare `*` (self-ignoring). - The stale-default predicate gains a second generation: under our header, `*` plus `!.gitignore` is now recognized as stale and upgraded in place, so existing projects self-heal on the next CodeGraph command. User-authored files (no header) are still never rewritten, and neither is a headered file customized with some other negation — only the exact `!.gitignore` line marks a stale default. Regression coverage drives real `git` against real temp repos, since this repo's own root `.gitignore` masks `.codegraph/` and would hide the bug: fresh init, migration from the deployed form, an alternate `CODEGRAPH_DIR`, and a user-authored file keeping its own semantics. All six new/updated assertions fail on the unfixed source. Co-Authored-By: Claude Opus 5 <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.
Problem
codegraph initwrites.codegraph/.gitignoreending in!.gitignore. Thatnegation un-ignores the generated file, so git sees one non-ignored path under
the data dir — and in any repository whose root
.gitignorehas no rule for.codegraph/(that is, every consumer repo), the generated index shows up asuntracked work:
This repo doesn't see it, because its own root
.gitignorecarries.codegraph/for the test projects. Consumers have no such rule.This is the residual of #492. That issue asked for "the entire
.codegraph/directory is not tracked by Git" and suggested
*+!.gitignore; thesuggestion shipped, but it cannot deliver the thing that was asked for. Git
reads and honors an ignore file that ignores itself, so dropping the negation is
what actually hides the directory:
The alternative — writing
.codegraph/into the consumer's root.gitignore—is deliberately not what this does. CodeGraph editing a file the project
owns and commits is a much bigger intrusion than owning its own generated
directory end to end.
Change
src/directory.tsonly:*. It covers the ignore file itself, sothe data dir is invisible in every repository with no consumer-side change.
# CodeGraph data filesheader, it now treats*plus!.gitignoreas stalein addition to the pre-wildcard allowlists from .codegraph/.gitignore should include daemon.pid #788, so existing projects
self-heal on the next CodeGraph command (
init,status,sync, MCPstartup — anything that runs
validateDirectory). Idempotent afterwards.alone, unchanged from before. A file that has our header but customizes the
default with some other negation (
!notes.md) is also left alone: only theexact
!.gitignoreline marks a stale default.Nothing else moves — extraction, graph contents, resolution, routing, telemetry,
the watcher, and
codegraph uninitare untouched..codegraph/was alreadyskipped by name during indexing and watching, independent of this file, so index
contents are unaffected.
Validation
Verified against real
gitin throwaway repos, plus the built CLI:git status -uallaftercodegraph initin a fresh consumer repocodegraph status?? .codegraph/.gitignore→ clean, file healedcodegraph query helloreturns the symbolCODEGRAPH_DIR=.codegraph-wincodegraph uninit --forcenpm test)tsc --noEmit/git diff --checkNew coverage in
__tests__/foundation.test.tsdrives realgitagainst realtemp repos, with
GIT_CONFIG_GLOBAL/GIT_CONFIG_SYSTEMpointed away so adeveloper's personal
core.excludesFilecan neither mask a regression nor causea false failure. Its header records why the tests can't just use this repo:
the root
.gitignorehere would hide the bug.Confirmed load-bearing — all 6 new/updated assertions fail on the unfixed
source and pass with it.
Compatibility
Existing indexes upgrade silently and keep working; the database and everything
else in the directory are untouched.
One edge case worth naming: if someone committed
.codegraph/.gitignore(which the
!.gitignoreform invited), the upgrade rewrites a tracked file, sothey see a one-file
M .codegraph/.gitignore— git's ignore rules never applyto tracked files, so this is unavoidable for any content change. The rest of the
index stays hidden either way, and they can commit the new content or
git rm --cachedthe file to get the full benefit.Rollback is reverting this commit: it restores the previous generated content,
and the predicate stops matching the new form, so nothing is left in a broken
state either way.