@ 261027.5

260709.17 · 241b87b3377136659ef0f57948b8e0739e9a691b

ignore: support `GIT_CONFIG_GLOBAL` and `GIT_CONFIG_SYSTEM` for `core.excludesFile`

`gitconfig_excludes_path()` resolves the global gitignore by reading `core.excludesFile` from `$HOME/.gitconfig` and `$XDG_CONFIG_HOME/git/config`, but git 2.32 (June 2021) introduced `GIT_CONFIG_GLOBAL` and `GIT_CONFIG_SYSTEM` environment variables that override these locations. The `ignore` crate doesn't check either of them, so users who point `GIT_CONFIG_GLOBAL` at a non-standard path (e.g. NixOS managing git config at `/etc/git/config`) have their global gitignore silently ignored by ripgrep while `git` itself respects it.

This commit checks `GIT_CONFIG_GLOBAL` before the hardcoded paths, matching git's semantics where it replaces both `$HOME/.gitconfig` and the XDG config. It also adds system-level config (`GIT_CONFIG_SYSTEM`, falling back to `/etc/gitconfig`) as a lowest-priority source for `core.excludesFile`, which the crate previously didn't consult at all.

Fixes #3275, Closes #3276

reading declarations

Changes to tests/regression.rs. All files

tests/regression.rs

@@ -1717,3 +1717,28 @@ rgtest!(r3180_look_around_panic, |dir: Dir, mut cmd: TestCommand| {         .stdout();     eqnice!("xbxbx\n", got); });++// See: https://github.com/BurntSushi/ripgrep/issues/3275+//+// This test doesn't seem to work on Windows for whatever reason. I haven't+// investigated it yet, but I'm pretty sure it's just the test. I'm guessing+// it's related to path separators. ---AG+#[cfg(not(windows))]+rgtest!(r3275_git_global_config_env, |dir: Dir, mut cmd: TestCommand| {+    dir.create_dir("foo");+    dir.create(".git", "");+    dir.create("foo/foo1", "");+    dir.create("foo/foo2", "");+    dir.create("global-excludes-nonstandard", "foo2");+    dir.create(+        "global-config-nonstandard",+        &format!(+            "[core]\n\texcludesFile = {path}",+            path = dir.path().join("global-excludes-nonstandard").display()+        ),+    );++    let config_path = dir.path().join("global-config-nonstandard");+    cmd.env("GIT_CONFIG_GLOBAL", config_path);+    eqnice!("foo/foo1\n", cmd.arg("--files").arg("foo").stdout());+});