git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] diff_index: honor in-index, not working-tree, .gitattributes

From
Jay Soffian <jaysoffian@gmail.com>
Date
Sep 22, 2011, 21:44 UTC
Message-ID
<1316727861-90460-2-git-send-email-jaysoffian@gmail.com>
In-Reply-To
<1316727861-90460-1-git-send-email-jaysoffian@gmail.com>

When diff'ing the index against a tree (using either diff-index or diff --cached), git previously looked at .gitattributes in the working tree before considering .gitattributes in the index, even though the diff itself otherwise ignores the working tree.

Further, with an index, but no working tree, the in-index .gitattributes were ignored entirely.

Calling git_attr_set_direction(GIT_ATTR_INDEX) before generating the diff fixes both of these behaviors.

--- This is a weather balloon patch I guess.

Obviously there is a behavior change here as evidenced by the change to t4020-diff-external.sh. I think the old behavior was wrong and this is a bug fix. But the old behavior has been that way a long time, so maybe we should use '--cached-attributes' instead for the "correct" behavior.

Since I'm not really sure what we should do with --cached -R, I'm punting on that for now.

Jeff's message regarding diff-tree made my head hurt, so tackling that will have to wait...

 diff-lib.c               |    3 +++
 t/t4020-diff-external.sh |    4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/diff-lib.c b/diff-lib.c
index f8454dd291..fe218931e6 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -11,6 +11,7 @@
 #include "unpack-trees.h"
 #include "refs.h"
 #include "submodule.h"
+#include "attr.h"
 
 /*
  * diff-files
@@ -476,6 +477,8 @@ static int diff_cache(struct rev_info *revs,
 int run_diff_index(struct rev_info *revs, int cached)
 {
 	struct object_array_entry *ent;
+	if (cached)
+		git_attr_set_direction(GIT_ATTR_INDEX, NULL);
 
 	ent = revs->pending.objects;
 	if (diff_cache(revs, ent->item->sha1, ent->name, cached))
diff --git a/t/t4020-diff-external.sh b/t/t4020-diff-external.sh
index 083f62d1d6..c6fdab3e87 100755
--- a/t/t4020-diff-external.sh
+++ b/t/t4020-diff-external.sh
@@ -160,10 +160,10 @@ test_expect_success 'external diff with autocrlf = true' '
 '
 
 test_expect_success 'diff --cached' '
-	git add file &&
+	git add .gitattributes file &&
 	git update-index --assume-unchanged file &&
 	echo second >file &&
-	git diff --cached >actual &&
+	git diff --cached file >actual &&
 	test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
 '
 
-- 
1.7.7.rc2.5.g12a2f
Previous: Jay SoffianNext: Junio C Hamano
Message 2 of 11 in “Teach '--cached' option to check-attr”
  1. 1/2 Teach '--cached' option to check-attrJay Soffian, Sep 22, 2011
  2. 2/2 diff_index: honor in-index, not working-tree, .gitattributesJay Soffian, Sep 22, 2011
  3. Junio C HamanoSep 22, 2011
  4. Jay SoffianSep 23, 2011
  5. Jay SoffianSep 23, 2011
  6. Junio C HamanoSep 23, 2011
  7. Jay SoffianSep 23, 2011
  8. Junio C HamanoSep 23, 2011
  9. Michael HaggertySep 23, 2011
  10. Jay SoffianSep 23, 2011
  11. Junio C HamanoSep 22, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.