-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Git 2.32 (which was released in June 2021) introduced two environment variables for overriding git config file locations:
- GIT_CONFIG_GLOBAL which overrides
~/.gitconfigand$XDG_CONFIG_HOME/git/config - GIT_CONFIG_SYSTEM which overrides
/etc/gitconfig
The ignore crate's gitconfig_excludes_path() currently only checks the hardcoded paths ($HOME/.gitconfig, $XDG_CONFIG_HOME/git/config) when looking for core.excludesFile. It does not check these environment variables, so users who set GIT_CONFIG_GLOBAL to a non-standard path will have their global gitignore silently ignored by ripgrep while git itself respects it.
My use case is that my NixOS system manages system-wide git configuration at /etc/git/config and sets GIT_CONFIG_GLOBAL to /etc/git/config. The config contains core.excludesFile = /etc/git/ignore. Git commands like git check-ignore work correctly, but ripgrep never finds the global excludes file because it doesn't check GIT_CONFIG_GLOBAL.
Reproducer:
echo -e '[core]\n\texcludesFile = /tmp/test-ignore' > /tmp/test-gitconfig
echo '*.log' > /tmp/test-ignore
export GIT_CONFIG_GLOBAL=/tmp/test-gitconfig
mkdir /tmp/rg-test && cd /tmp/rg-test && git init
touch foo.txt bar.log
# git respects `GIT_CONFIG_GLOBAL`
git check-ignore bar.log # outputs: bar.log
# ripgrep does not
rg --files # lists bar.log
rg --debug --files 2>&1 | grep 'opened gitignore'
# which only shows .git/info/exclude, meaning the global excludes file wasn't openedI'd expect that when GIT_CONFIG_GLOBAL is set, ripgrep should read git config from that path (instead of $HOME/.gitconfig & $XDG_CONFIG_HOME/git/config) to find core.excludesFile, which would match git's own behavior. Similarly for GIT_CONFIG_SYSTEM overriding the system-level config path.