fix: check global excludes file before adding .osgrep to .gitignore#87
fix: check global excludes file before adding .osgrep to .gitignore#87aliou wants to merge 1 commit intoRyandonofrio3:mainfrom
Conversation
WalkthroughAdds resolution of Git's global excludes file in Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
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.
1c20dcd to
15c8fb8
Compare
|
@coderabbitai help |
ChatThere are 3 ways to chat with CodeRabbit:
CodeRabbit commands
Other keywords and placeholders
CodeRabbit configuration file (
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@Ryandonofrio3 Hello! Gentle nudge if you have some time to take a look. Thanks! |
Hello!
This is a follow-up to #86. That PR added a check for
.git/info/excludebefore adding.osgrepto.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.osgrepto their global excludes file, we shouldn't redundantly add it to the local.gitignore.This implementation:
git config --get core.excludesFileto retrieve the configured path$XDG_CONFIG_HOME/git/ignoreor~/.config/git/ignore) if not explicitly configured~in the path to the user's home directoryNote: 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
.osgrepentry to.gitignorewhen it's already present in the global git excludes file.Changes:
getGlobalExcludesPath()helper to retrieve and expand the global excludes file pathensureGitignoreEntry()before checking local filesXDG_CONFIG_HOMEenvironment variable and Git's default path (~/.config/git/ignore)git configcommand to prevent blockingos.homedir()for cross-platform home directory expansionCheck order is now:
.git/info/exclude(from fix: check .git/info/exclude before adding .osgrep to .gitignore #86).gitignoreSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.