git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Brandon Williams <bmwill@google.com>
To: git@vger.kernel.org
Cc: Brandon Williams <bmwill@google.com>,
	ben.boeckel@kitware.com, sunshine@sunshineco.com,
	sbeller@google.com, gitster@pobox.com
Subject: [PATCH v2] diff-tree: read the index so attribute checks work in bare repositories
Date: Wed,  6 Dec 2017 14:02:56 -0800	[thread overview]
Message-ID: <20171206220256.44482-1-bmwill@google.com> (raw)
In-Reply-To: <20171205221337.140548-1-bmwill@google.com>

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>
---
 builtin/diff-tree.c        |  2 ++
 t/t4015-diff-whitespace.sh | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index d66499909..b775a7564 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -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;
diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index 559a7541a..17df491a3 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -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 &&
-- 
2.15.1.424.g9478a66081-goog


      parent reply	other threads:[~2017-12-06 22:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-04 21:22 gitattributes not read for diff-tree anymore in 2.15? Ben Boeckel
2017-12-04 23:03 ` Brandon Williams
2017-12-05 15:42   ` Ben Boeckel
2017-12-05 18:16     ` Brandon Williams
2017-12-05 19:48       ` Ben Boeckel
2017-12-05 22:13         ` [PATCH] diff-tree: read the index so attribute checks work in bare repositories Brandon Williams
2017-12-05 22:29           ` Ben Boeckel
2017-12-05 22:31             ` Brandon Williams
2017-12-05 23:13           ` Junio C Hamano
2017-12-05 23:14           ` Stefan Beller
2017-12-06 21:47             ` Brandon Williams
2017-12-05 23:25           ` Eric Sunshine
2017-12-06 22:00             ` Brandon Williams
2017-12-06 22:07               ` Eric Sunshine
2017-12-06 22:02           ` Brandon Williams [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171206220256.44482-1-bmwill@google.com \
    --to=bmwill@google.com \
    --cc=ben.boeckel@kitware.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sbeller@google.com \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).