BurntSushi/ripgrep

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

已關閉

#3,275 建立於 2026年2月17日

 (1 則留言) (0 個反應) (0 位負責人)Rust (2,559 個分叉)batch import
enhancementhelp wanted

倉庫指標

星標
 (63,768 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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.

貢獻者指南