Skip to content

feat: auto-ignore .codemap/ when setting up codemap in a repo#80

Open
JordanCoin wants to merge 1 commit into
mainfrom
feat/auto-gitignore-codemap
Open

feat: auto-ignore .codemap/ when setting up codemap in a repo#80
JordanCoin wants to merge 1 commit into
mainfrom
feat/auto-gitignore-codemap

Conversation

@JordanCoin

Copy link
Copy Markdown
Owner

Problem

codemap writes all its runtime state to .codemap/ (config, event log, watch PID, handoffs, hub cache) — but it never tells git to ignore that directory. This repo's own .gitignore has .codemap/ only because it was added by hand. Every other project a user runs codemap in gets an unprotected .codemap/ that they'll accidentally commit.

This came out of a discussion about how codemap should behave across git worktrees: because .codemap/ is (correctly) per-working-directory runtime state, the tool should own making sure its own footprint is ignored — per git root, across worktrees and nested repos.

What this does

New ensureCodemapIgnored(root, mode) helper:

  • No-op if git already ignores .codemap/ — checked via git check-ignore, so it honors global excludes, existing .gitignore rules, and negations. No duplicate lines.
  • Two tiers:
    • ignoreTracked → writes .codemap/ to the repo's tracked .gitignore (team convention; every clone/worktree inherits it).
    • ignoreLocal → writes to <git-common-dir>/info/exclude (local-only, no tracked diff, shared across worktrees). Wired in a follow-up.
  • Safe: silent no-op outside a git work tree; creates the ignore file if missing; preserves existing content + trailing newline.

Wired the tracked tier into config init and setup through a shared reportEnsureIgnored seam that prints a one-line Added .codemap/ to .gitignore notice.

Testing (TDD)

Tests written first, red → green. go test ./... fully green, go vet clean.

  • TestEnsureCodemapIgnored — tracked write, no-op-when-ignored, create-when-missing, append-preserving-newline, ignoreLocal→info/exclude, non-git skip.
  • TestReportEnsureIgnored — notice on first run, silent when already ignored, silent outside git.

Also smoke-tested the built binary: codemap config init in a fresh repo prints the notice, git check-ignore confirms the rule, and a second run stays idempotent.

Follow-ups (not in this PR)

  • Wire the ignoreLocal safety-net into the lazy .codemap/ creation paths (cmd/hooks.go, watch/daemon.go) — needs the helper promoted to a shared package since watch can't call cmd's unexported helper.
  • Multi-repo: ensure each git root codemap materializes state under gets its own rule.

🤖 Generated with Claude Code

codemap writes its runtime state to `.codemap/`, but never told git to
ignore it — so every project a user ran codemap in would leak `.codemap/`
into commits unless they added the rule by hand.

Add `ensureCodemapIgnored(root, mode)`:
- No-op if git already ignores `.codemap/` (checked via `git check-ignore`,
  so it honors global excludes, existing rules, and negations).
- `ignoreTracked` writes `.codemap/` to the repo's tracked `.gitignore`
  (team convention); `ignoreLocal` writes to `<git-common-dir>/info/exclude`
  (local-only, no tracked diff, shared across worktrees).
- Silent no-op outside a git work tree; creates the file if missing;
  preserves existing content and trailing newline; never double-appends.

Wire the tracked tier into `config init` and `setup` via a shared
`reportEnsureIgnored` seam that prints a one-line notice on write.

Tested first (TDD): ensureCodemapIgnored across write/no-op/create/append/
local/non-git cases, plus the reporting seam.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 14, 2026 01:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.68421% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/gitignore.go 72.97% 11 Missing and 9 partials ⚠️

📢 Thoughts on this report? Let us know!

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.

3 participants