Skip to content

fix: check global excludes file before adding .osgrep to .gitignore#87

Open
aliou wants to merge 1 commit intoRyandonofrio3:mainfrom
aliou:check-exclude-file-for-osgrep-entry
Open

fix: check global excludes file before adding .osgrep to .gitignore#87
aliou wants to merge 1 commit intoRyandonofrio3:mainfrom
aliou:check-exclude-file-for-osgrep-entry

Conversation

@aliou
Copy link
Contributor

@aliou aliou commented Jan 18, 2026

Hello!

This is a follow-up to #86. That PR added a check for .git/info/exclude before adding .osgrep to .gitignore. This PR extends that functionality by also checking the global git excludes file.

Git supports a global excludes file (configured via core.excludesFile) that applies to all repositories on the system. If a user has already added .osgrep to their global excludes file, we shouldn't redundantly add it to the local .gitignore.

This implementation:

  • Runs git config --get core.excludesFile to retrieve the configured path
  • Falls back to Git's default location ($XDG_CONFIG_HOME/git/ignore or ~/.config/git/ignore) if not explicitly configured
  • Expands ~ in the path to the user's home directory
  • Uses a 1 second timeout on the git config command to prevent blocking
  • Works cross-platform (Unix, macOS, and Windows)

Note: Not tested on Windows, but implementation follows Git documentation and uses Node's cross-platform APIs (os.homedir(), path.join()) with support for Windows-specific environment variables (USERPROFILE).

Summary from Opus:

Prevents adding a redundant .osgrep entry to .gitignore when it's already present in the global git excludes file.

Changes:

  • Add getGlobalExcludesPath() helper to retrieve and expand the global excludes file path
  • Check global excludes file first in ensureGitignoreEntry() before checking local files
  • Support XDG_CONFIG_HOME environment variable and Git's default path (~/.config/git/ignore)
  • Add 1 second timeout to git config command to prevent blocking
  • Use os.homedir() for cross-platform home directory expansion

Check order is now:

  1. Global excludes file (new - this PR)
  2. .git/info/exclude (from fix: check .git/info/exclude before adding .osgrep to .gitignore #86)
  3. .gitignore

Summary by CodeRabbit

  • New Features
    • Improved Git ignore resolution: the tool now respects global Git exclude settings first (including standard config locations), so entries defined globally are honored and repository checks are skipped when applicable.
    • More robust handling of Git configuration paths and expansion for consistent behavior across environments.

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

@coderabbitai
Copy link

coderabbitai bot commented Jan 18, 2026

Walkthrough

Adds resolution of Git's global excludes file in project-root.ts and reorders ignore-check logic to consult the global excludes file first, falling back to .git/info/exclude and then .gitignore with tilde/XDG path handling.

Changes

Cohort / File(s) Summary
Global excludes resolution
src/lib/utils/project-root.ts
Adds os and execSync imports; adds getGlobalExcludesPath to resolve core.excludesFile with tilde expansion and XDG fallback; ensureGitignoreEntry now checks global excludes first and returns early if entry found; retains existing .git/info/exclude and .gitignore logic (+34/-1)

Sequence Diagram

sequenceDiagram
    participant Caller as Caller
    participant Ensure as ensureGitignoreEntry
    participant GitCfg as Git Config
    participant FS as File System

    Caller->>Ensure: ensureGitignoreEntry(entry)
    Ensure->>GitCfg: read core.excludesFile (exec git config)
    GitCfg-->>Ensure: globalExcludesPath|null
    alt globalExcludesPath available
        Ensure->>FS: read global excludes file
        FS-->>Ensure: contents
        alt entry in global excludes
            Ensure-->>Caller: return (no change)
        else entry not in global excludes
            Ensure->>FS: read .git/info/exclude
            FS-->>Ensure: contents
            alt entry in .git/info/exclude
                Ensure-->>Caller: return
            else
                Ensure->>FS: check/append .gitignore
                FS-->>Ensure: updated/read result
                Ensure-->>Caller: return
            end
        end
    else no globalExcludesPath
        Ensure->>FS: read .git/info/exclude
        FS-->>Ensure: contents
        alt entry in .git/info/exclude
            Ensure-->>Caller: return
        else
            Ensure->>FS: check/append .gitignore
            FS-->>Ensure: updated/read result
            Ensure-->>Caller: return
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sniffed the global git air tonight,
Found excludes tucked under XDG light.
I hop, I check, I skip the fuss—
A tidy repo, thanks to us. 🌿

🚥 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 specifically describes the main change: checking Git's global excludes file before adding .osgrep to .gitignore, which aligns with the primary objective of the PR.

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

✨ Finishing touches
  • 📝 Generate docstrings

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

@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

🤖 Fix all issues with AI agents
In `@src/lib/utils/project-root.ts`:
- Around line 67-89: getGlobalExcludesPath currently does naive ~ expansion and
misses relative/`~user` cases; change the execSync call in getGlobalExcludesPath
to use "git config --path --get core.excludesFile" so Git does tilde expansion
for you, then take the returned result and, if it is a relative path (i.e., not
absolute), resolve it against the repository CWD via path.resolve(process.cwd(),
result) and assign to configuredPath; remove the manual result.replace(/^~/,
home) logic but keep the fallback that constructs the default path when
configuredPath is still null.

@aliou aliou force-pushed the check-exclude-file-for-osgrep-entry branch from 1c20dcd to 15c8fb8 Compare January 19, 2026 09:18
@aliou
Copy link
Contributor Author

aliou commented Jan 20, 2026

@coderabbitai help

@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue comments.

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
    • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
    • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai generate configuration to create a PR that adds the current resolved configuration as .coderabbit.yaml (or show it if already present).
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit configuration file (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

@aliou
Copy link
Contributor Author

aliou commented Jan 21, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 21, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@aliou
Copy link
Contributor Author

aliou commented Jan 26, 2026

@Ryandonofrio3 Hello! Gentle nudge if you have some time to take a look. Thanks!

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