Merge branch 'bw/submodule-config-cleanup'
authorJunio C Hamano <gitster@pobox.com>
Tue, 19 Dec 2017 19:33:57 +0000 (11:33 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 Dec 2017 19:33:57 +0000 (11:33 -0800)
Recent update to the submodule configuration code broke "diff-tree"
by accidentally stopping to read from the index upfront.

* bw/submodule-config-cleanup:
diff-tree: read the index so attribute checks work in bare repositories

builtin/diff-tree.c
t/t4015-diff-whitespace.sh
index d66499909e82e255a8d1356b606f9b901935317f..b775a756470ddc365907fae53dcc949bcaae7ca5 100644 (file)
@@ -110,6 +110,8 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
 
        git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
        init_revisions(opt, prefix);
+       if (read_cache() < 0)
+               die(_("index file corrupt"));
        opt->abbrev = 0;
        opt->diff = 1;
        opt->disable_stdin = 1;
index 559a7541a83eb8bd8b465aac154cf67f8783b13d..17df491a3abe84fca63bb899d1162832d13e1847 100755 (executable)
@@ -636,6 +636,23 @@ test_expect_success 'check with space before tab in indent (diff-tree)' '
        test_must_fail git diff-tree --check HEAD^ HEAD
 '
 
+test_expect_success 'check with ignored trailing whitespace attr (diff-tree)' '
+       test_when_finished "git reset --hard HEAD^" &&
+
+       # create a whitespace error that should be ignored
+       echo "* -whitespace" >.gitattributes &&
+       git add .gitattributes &&
+       echo "foo(); " >x &&
+       git add x &&
+       git commit -m "add trailing space" &&
+
+       # with a worktree diff-tree ignores the whitespace error
+       git diff-tree --root --check HEAD &&
+
+       # without a worktree diff-tree still ignores the whitespace error
+       git -C .git diff-tree --root --check HEAD
+'
+
 test_expect_success 'check trailing whitespace (trailing-space: off)' '
        git config core.whitespace "-trailing-space" &&
        echo "foo ();   " >x &&