diff-tree: read the index so attribute checks work in bare repositories

A regression was introduced in 557a5998d (submodule: remove gitmodules_config, 2017-08-03) to how attribute processing was handled in bare repositories when running the diff-tree command. By default the attribute system will first try to read ".gitattribute" files from the working tree and then falls back to reading them from the index if there isn't a copy checked out in the worktree. Prior to 557a5998d the index was read as a side effect of the call to 'gitmodules_config()' which ensured that the index was already populated before entering the attribute subsystem. Since the call to 'gitmodules_config()' was removed the index is no longer being read so when the attribute system tries to read from the in-memory index it doesn't find any ".gitattribute" entries effectively ignoring any configured attributes. Fix this by explicitly reading the index during the setup of diff-tree. Reported-by: Ben Boeckel <ben.boeckel@kitware.com> Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Dec 6, 2017 at 14:02 UTC fd66bcc31ff294cdeaa3e960a3aa7fee619ec3b8
2 files changed +19
builtin/diff-tree.c
+2
@@ -110,6 +110,8 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
110
111 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
112 init_revisions(opt, prefix);
113 + if (read_cache() < 0)
114 + die(_("index file corrupt"));
115 opt->abbrev = 0;
116 opt->diff = 1;
117 opt->disable_stdin = 1;
t/t4015-diff-whitespace.sh
+17
@@ -608,6 +608,23 @@ test_expect_success 'check with space before tab in indent (diff-tree)' '
608 test_must_fail git diff-tree --check HEAD^ HEAD
609 '
610
611 +test_expect_success 'check with ignored trailing whitespace attr (diff-tree)' '
612 + test_when_finished "git reset --hard HEAD^" &&
613 +
614 + # create a whitespace error that should be ignored
615 + echo "* -whitespace" >.gitattributes &&
616 + git add .gitattributes &&
617 + echo "foo(); " >x &&
618 + git add x &&
619 + git commit -m "add trailing space" &&
620 +
621 + # with a worktree diff-tree ignores the whitespace error
622 + git diff-tree --root --check HEAD &&
623 +
624 + # without a worktree diff-tree still ignores the whitespace error
625 + git -C .git diff-tree --root --check HEAD
626 +'
627 +
628 test_expect_success 'check trailing whitespace (trailing-space: off)' '
629 git config core.whitespace "-trailing-space" &&
630 echo "foo (); " >x &&