Merge branch 'jc/gitignore-precedence'
authorJunio C Hamano <gitster@pobox.com>
Tue, 19 May 2015 20:17:50 +0000 (13:17 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 May 2015 20:17:51 +0000 (13:17 -0700)
core.excludesfile (defaulting to $XDG_HOME/git/ignore) is supposed
to be overridden by repository-specific .git/info/exclude file, but
the order was swapped from the beginning. This belatedly fixes it.

* jc/gitignore-precedence:
ignore: info/exclude should trump core.excludesfile

1  2 
dir.c
t/t0008-ignores.sh
diff --cc dir.c
index 0c38d8601448053f94eca534833d47a975580856,e67b6f9b8bf95b284ee6976f4968eba80e281b8d..4183acc082671f135fe64cbcaa66ed3b17bc6364
--- 1/dir.c
--- 2/dir.c
+++ b/dir.c
@@@ -1671,15 -1527,22 +1671,19 @@@ int remove_dir_recursively(struct strbu
  void setup_standard_excludes(struct dir_struct *dir)
  {
        const char *path;
 -      char *xdg_path;
  
        dir->exclude_per_dir = ".gitignore";
-       path = git_path("info/exclude");
+       /* core.excludefile defaulting to $XDG_HOME/git/ignore */
 -      if (!excludes_file) {
 -              home_config_paths(NULL, &xdg_path, "ignore");
 -              excludes_file = xdg_path;
 -      }
 +      if (!excludes_file)
 +              excludes_file = xdg_config_home("ignore");
-       if (!access_or_warn(path, R_OK, 0))
-               add_excludes_from_file(dir, path);
        if (excludes_file && !access_or_warn(excludes_file, R_OK, 0))
                add_excludes_from_file(dir, excludes_file);
+       /* per repository user preference */
+       path = git_path("info/exclude");
+       if (!access_or_warn(path, R_OK, 0))
+               add_excludes_from_file(dir, path);
  }
  
  int remove_path(const char *name)
index 8dc6939b9049baa32aca1200e36378e6e2296e9d,38405de17d6f9625a07080d4fc2e4b4541351cc5..4ef5ed484c12a4509b9bc66f2cc41118f7254431
@@@ -775,60 -775,14 +775,70 @@@ test_expect_success PIPE 'streaming sup
        echo "$response" | grep "^::    two"
  '
  
 +############################################################################
 +#
 +# test whitespace handling
 +
 +test_expect_success 'trailing whitespace is ignored' '
 +      mkdir whitespace &&
 +      >whitespace/trailing &&
 +      >whitespace/untracked &&
 +      echo "whitespace/trailing   " >ignore &&
 +      cat >expect <<EOF &&
 +whitespace/untracked
 +EOF
 +      : >err.expect &&
 +      git ls-files -o -X ignore whitespace >actual 2>err &&
 +      test_cmp expect actual &&
 +      test_cmp err.expect err
 +'
 +
 +test_expect_success !MINGW 'quoting allows trailing whitespace' '
 +      rm -rf whitespace &&
 +      mkdir whitespace &&
 +      >"whitespace/trailing  " &&
 +      >whitespace/untracked &&
 +      echo "whitespace/trailing\\ \\ " >ignore &&
 +      echo whitespace/untracked >expect &&
 +      : >err.expect &&
 +      git ls-files -o -X ignore whitespace >actual 2>err &&
 +      test_cmp expect actual &&
 +      test_cmp err.expect err
 +'
 +
 +test_expect_success !MINGW,!CYGWIN 'correct handling of backslashes' '
 +      rm -rf whitespace &&
 +      mkdir whitespace &&
 +      >"whitespace/trailing 1  " &&
 +      >"whitespace/trailing 2 \\\\" &&
 +      >"whitespace/trailing 3 \\\\" &&
 +      >"whitespace/trailing 4   \\ " &&
 +      >"whitespace/trailing 5 \\ \\ " &&
 +      >"whitespace/trailing 6 \\a\\" &&
 +      >whitespace/untracked &&
 +      sed -e "s/Z$//" >ignore <<-\EOF &&
 +      whitespace/trailing 1 \    Z
 +      whitespace/trailing 2 \\\\Z
 +      whitespace/trailing 3 \\\\ Z
 +      whitespace/trailing 4   \\\    Z
 +      whitespace/trailing 5 \\ \\\   Z
 +      whitespace/trailing 6 \\a\\Z
 +      EOF
 +      echo whitespace/untracked >expect &&
 +      >err.expect &&
 +      git ls-files -o -X ignore whitespace >actual 2>err &&
 +      test_cmp expect actual &&
 +      test_cmp err.expect err
 +'
 +
+ test_expect_success 'info/exclude trumps core.excludesfile' '
+       echo >>global-excludes usually-ignored &&
+       echo >>.git/info/exclude "!usually-ignored" &&
+       >usually-ignored &&
+       echo "?? usually-ignored" >expect &&
+       git status --porcelain usually-ignored >actual &&
+       test_cmp expect actual
+ '
  test_done