Skip to content

Support GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM environment variables for finding core.excludesFile #3275

@amaanq

Description

@amaanq

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAn enhancement to the functionality of the software.help wantedOthers are encouraged to work on this issue.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions