ignore: info/exclude should trump core.excludesfile
$GIT_DIR/info/exclude and core.excludesfile (which falls back to $XDG_HOME/git/ignore) are both ways to override the ignore pattern lists given by the project in .gitignore files. The former, which is per-repository personal preference, should take precedence over the latter, which is a personal preference default across different repositories that are accessed from that machine. The existing documentation also agrees. However, the precedence order was screwed up between these two from the very beginning when 896bdfa2 (add: Support specifying an excludes file with a configuration variable, 2007-02-27) introduced core.excludesfile variable. Noticed-by: Yohei Endo <yoheie@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Apr 22, 2015 at 14:31 UTC
099d2d86a8e17218aca31bf7c4070a820baf4baa
2 files changed
+17
-3
dir.c
+7
-3
@@ -1530,15 +1530,19 @@ void setup_standard_excludes(struct dir_struct *dir)
1530
char *xdg_path;
1531
1532
dir->exclude_per_dir = ".gitignore";
1533
- path = git_path("info/exclude");
1533
+
1534
+ /* core.excludefile defaulting to $XDG_HOME/git/ignore */
1535
if (!excludes_file) {
1536
home_config_paths(NULL, &xdg_path, "ignore");
1537
excludes_file = xdg_path;
1538
}
1538
- if (!access_or_warn(path, R_OK, 0))
1539
- add_excludes_from_file(dir, path);
1539
if (excludes_file && !access_or_warn(excludes_file, R_OK, 0))
1540
add_excludes_from_file(dir, excludes_file);
1541
+
1542
+ /* per repository user preference */
1543
+ path = git_path("info/exclude");
1544
+ if (!access_or_warn(path, R_OK, 0))
1545
+ add_excludes_from_file(dir, path);
1546
}
1547
1548
int remove_path(const char *name)
t/t0008-ignores.sh
+10
@@ -775,4 +775,14 @@ test_expect_success PIPE 'streaming support for --stdin' '
775
echo "$response" | grep "^:: two"
776
'
777
778
+test_expect_success 'info/exclude trumps core.excludesfile' '
779
+ echo >>global-excludes usually-ignored &&
780
+ echo >>.git/info/exclude "!usually-ignored" &&
781
+ >usually-ignored &&
782
+ echo "?? usually-ignored" >expect &&
783
+
784
+ git status --porcelain usually-ignored >actual &&
785
+ test_cmp expect actual
786
+'
787
+
788
test_done