Skip to content

fix: check .git/info/exclude before adding .osgrep to .gitignore#86

Merged
Ryandonofrio3 merged 1 commit intoRyandonofrio3:mainfrom
aliou:check-exclude-file-for-osgrep-entry
Jan 17, 2026
Merged

fix: check .git/info/exclude before adding .osgrep to .gitignore#86
Ryandonofrio3 merged 1 commit intoRyandonofrio3:mainfrom
aliou:check-exclude-file-for-osgrep-entry

Conversation

@aliou
Copy link
Contributor

@aliou aliou commented Jan 16, 2026

Hello! I've been using osgrep via specialized subagents1 more and more and noticed that it adds the .osgrep file to the .gitignore if it doesn't already include it. However, it doesn't check for the .git/info/exclude, another file that is used to ignore files.

In addition, it doesn't check yet for a global excludes file, I'll create a separate PR as it requires calling git config --get core.excludesFile instead of "simply" reading a file.

Note

Also, please note that this PR was made with assistance from a coding agent. I couldn't find anything in the docs that explicitly disallow it, but please let me know if it's an issue.
I reviewed the code and made sure it worked before opening this PR. In addition, please see the implementation session below.

Implementation session: https://buildwithpi.ai/session/?b31744872cf959ab6222a7696bcc39b8

Summary from Opus:

Prevents adding a redundant .osgrep entry to .gitignore when it's already present in .git/info/exclude.

Changes:

  • Extract fileContainsEntry() helper for checking ignore files
  • Check .git/info/exclude before .gitignore in ensureGitignoreEntry()

Summary by CodeRabbit

  • Refactor
    • Improved internal code organization and error handling for configuration file management with no user-facing changes.

✏️ Tip: You can customize this high-level summary in your review settings.

Footnotes

  1. The session linked above somewhat shows it: the Lookout subagent uses osgrep for semantic search :)

@coderabbitai
Copy link

coderabbitai bot commented Jan 16, 2026

Walkthrough

This change refactors internal Gitignore handling in project-root.ts by introducing a helper function fileContainsEntry to centralize file reading and entry-checking logic. The code now uses this helper to check both .git/info/exclude and .gitignore files, replaces hard-coded checks with a constant, and improves code reusability without altering the public API.

Changes

Cohort / File(s) Summary
Gitignore entry management refactoring
src/lib/utils/project-root.ts
Introduced internal helper fileContainsEntry to read files and check for trimmed line entries. Reworked ensureGitignoreEntry to use this helper for both .git/info/exclude and .gitignore. Introduced constant entry = ".osgrep" and replaced hard-coded inline checks with centralized approach. Public API unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A helper hops in, so tidy and neat,
Checking for entries, a refactoring treat,
Constants take shape where hard-codes once stood,
Making the code flow just as it should! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: checking .git/info/exclude before adding .osgrep to .gitignore, which directly matches the PR's primary objective.

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

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 7a90edf and e6728dd.

📒 Files selected for processing (1)
  • src/lib/utils/project-root.ts
🔇 Additional comments (2)
src/lib/utils/project-root.ts (2)

53-63: LGTM!

Clean helper function with appropriate error handling. Silently returning false when the file doesn't exist or can't be read is the correct behavior for checking optional ignore files.


65-92: LGTM!

The control flow is well-structured: checking .git/info/exclude first, then .gitignore, and only appending if the entry is absent from both. The extracted entry constant improves consistency between the check and write operations.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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.

@Ryandonofrio3 Ryandonofrio3 merged commit 2813f70 into Ryandonofrio3:main Jan 17, 2026
2 checks passed
@aliou aliou deleted the check-exclude-file-for-osgrep-entry branch January 18, 2026 09:31
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.

2 participants