Skip to content

fix(cli): skip incremental-index outside git repos#9

Open
jgangemi wants to merge 2 commits intosdsrss:mainfrom
jgangemi:jae/incremental-index-git-guard
Open

fix(cli): skip incremental-index outside git repos#9
jgangemi wants to merge 2 commits intosdsrss:mainfrom
jgangemi:jae/incremental-index-git-guard

Conversation

@jgangemi
Copy link
Copy Markdown

@jgangemi jgangemi commented Apr 12, 2026

The incremental-index subcommand previously called create_dir_all
on .code-graph/ from std::env::current_dir() with no check that cwd
was a git repo. In multi-repo workspaces this caused stray indexes
to materialize at workspace-parent directories when the PostToolUse
hook fired from those directories.

Add a silent bail in the main.rs dispatch when cwd has no .git,
matching the prevailing hook-layer silent-skip convention (see
incremental-index.js error swallowing and session-init.js
ensureIndexFresh returning 'skipped').

Fixes #8

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Summary by CodeRabbit

  • Bug Fixes
    • The incremental-index command now exits cleanly when run outside a git repository and no longer creates extraneous files.
  • Tests
    • Added automated tests verifying incremental-index behavior both outside a git repo and inside a minimal git repo, ensuring it exits without blocking.

The incremental-index subcommand previously called create_dir_all
on .code-graph/ from std::env::current_dir() with no check that cwd
was a git repo. In multi-repo workspaces this caused stray indexes
to materialize at workspace-parent directories when the PostToolUse
hook fired from those directories.

Add a silent bail in the main.rs dispatch when cwd has no .git,
matching the prevailing hook-layer silent-skip convention (see
incremental-index.js error swallowing and session-init.js
ensureIndexFresh returning 'skipped').

Fixes sdsrss#8

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f598a56c-9f96-420f-a21a-337fcc788bb1

📥 Commits

Reviewing files that changed from the base of the PR and between 3630a4b and f5736c1.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • src/main.rs
✅ Files skipped from review due to trivial changes (1)
  • src/main.rs

📝 Walkthrough

Walkthrough

Added a pre-check in the incremental-index subcommand to detect a .git entry in ancestor directories and return immediately if none is found; added tests that run the built binary in git and non-git temporary directories to verify no unwanted .code-graph is created and the command exits successfully.

Changes

Cohort / File(s) Summary
Test Coverage
claude-plugin/scripts/incremental-index.test.js
New Node.js node:test file with two tests that spawn the incremental-index binary: one verifies behavior outside a git repo (no .code-graph, exit 0), the other verifies behavior inside a minimal git repo (exit 0, non-blocking).
Git Repository Check
src/main.rs
Added logic in the incremental-index subcommand to walk ancestor directories for a .git entry and silently return Ok(()) if none is found, preventing .code-graph creation outside git repos.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through temp dirs, quick and spry,
I checked for .git before digging a sigh,
No stray .code-graph where it shouldn't be,
Tests keep the burrows tidy and free,
Hooray — clean roots, and more time to hop! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: skipping incremental-index execution outside git repositories, which is the core fix for issue #8.
Linked Issues check ✅ Passed The changes implement the core requirement from issue #8: walking ancestor directories to find .git and silently returning if none is found, preventing .code-graph creation outside repos.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the git-repo detection requirement: src/main.rs adds ancestor directory traversal logic, and the test file validates this behavior in both git and non-git directories.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main.rs`:
- Around line 35-37: The current guard only checks for
project_root.join(".git").exists(), which misses nested directories; change it
to detect git membership by scanning ancestors of project_root (e.g., using
project_root.ancestors()) and return Ok(()) only if none of the ancestor
directories contain a .git entry; also account for worktrees where .git can be a
file by testing both existence and is_file on ancestor.join(".git"). Use the
existing project_root symbol and adjust the guard around the incremental-index
startup logic accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ee0ee750-9667-43e4-bbb4-7de949da77ec

📥 Commits

Reviewing files that changed from the base of the PR and between 5977737 and 3630a4b.

📒 Files selected for processing (2)
  • claude-plugin/scripts/incremental-index.test.js
  • src/main.rs

Comment thread src/main.rs Outdated
- Replace simple project_root/.git check with ancestor walk to handle
  subdirectories and worktrees (where .git is a file)
- Add docstring coverage to main(), helper functions, and SharedStdout struct

Fixes CodeRabbit feedback on sdsrss#9

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

incremental-index creates .code-graph/ in any cwd — pollutes workspace-root and non-project directories

1 participant