BurntSushi/ripgrep

Support `GIT_CONFIG_GLOBAL` and `GIT_CONFIG_SYSTEM` environment variables for finding `core.excludesFile`

Open

#3.275 geöffnet am 17. Feb. 2026

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)Rust (2.559 Forks)batch import
enhancementhelp wanted

Repository-Metriken

Stars
 (63.768 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 2T 12h) (5 gemergte PRs in 30 T)

Beschreibung

Git 2.32 (which was released in June 2021) introduced two environment variables for overriding git config file locations:

  • GIT_CONFIG_GLOBAL which overrides ~/.gitconfig and $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 opened

I'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.

Contributor Guide