Skip to content

Commit fd66bcc

Browse files
bmwillgitster
authored andcommitted
diff-tree: read the index so attribute checks work in bare repositories
A regression was introduced in 557a599 (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 557a599 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 <[email protected]> Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 557a599 commit fd66bcc

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

builtin/diff-tree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
110110

111111
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
112112
init_revisions(opt, prefix);
113+
if (read_cache() < 0)
114+
die(_("index file corrupt"));
113115
opt->abbrev = 0;
114116
opt->diff = 1;
115117
opt->disable_stdin = 1;

t/t4015-diff-whitespace.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,23 @@ test_expect_success 'check with space before tab in indent (diff-tree)' '
608608
test_must_fail git diff-tree --check HEAD^ HEAD
609609
'
610610

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+
611628
test_expect_success 'check trailing whitespace (trailing-space: off)' '
612629
git config core.whitespace "-trailing-space" &&
613630
echo "foo (); " >x &&

0 commit comments

Comments
 (0)