Skip to content

init: exclude local .codegraph indexes from git#561

Open
Wood-Q wants to merge 1 commit into
colbymchenry:mainfrom
Wood-Q:main
Open

init: exclude local .codegraph indexes from git#561
Wood-Q wants to merge 1 commit into
colbymchenry:mainfrom
Wood-Q:main

Conversation

@Wood-Q
Copy link
Copy Markdown

@Wood-Q Wood-Q commented May 29, 2026

Summary

Automatically add newly initialized .codegraph/ directories to the local Git exclude file (.git/info/exclude) during codegraph init.

Problem

Today, every time a user runs codegraph init, the generated .codegraph/ directory can appear in git status. In practice, that means users often have to manually add .codegraph/ to .gitignore after initialization.

That is annoying repeated cleanup, and it also creates a product mismatch: .codegraph/ is local generated index state, not source code. Repositories published to GitHub should not need to carry CodeGraph-specific ignore rules just because one developer initialized an index locally. Other users can simply run codegraph init themselves.

Solution

This PR writes the ignore rule to .git/info/exclude instead of the tracked .gitignore.

That gives users the desired behavior locally:

  • .codegraph/ no longer appears in git status after init
  • project .gitignore remains untouched
  • GitHub/released source trees do not gain CodeGraph-specific metadata
  • repeated init flows do not duplicate existing exclude entries
  • nested project roots in monorepos write the correct relative exclude path

If the project is not inside a Git worktree, or Git metadata cannot be accessed, initialization still succeeds and the exclude step is skipped.

Tests

  • Added coverage for adding .codegraph/ to .git/info/exclude
  • Added idempotency coverage for existing exclude entries
  • Added nested project coverage for monorepo-style paths
  • Added non-Git initialization coverage
  • Verified with:
    • npm run build
    • npx vitest run __tests__/foundation.test.ts
    • git diff --check

Add .codegraph/ to the repository-local .git/info/exclude during
project initialization so generated CodeGraph indexes do not show up in
git status after `codegraph init`.

This keeps GitHub/project .gitignore files clean, avoids committing
CodeGraph-specific local state, handles nested project roots, and keeps
the operation idempotent.
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.

1 participant