Thread (2 messages) flat view 2 messages, 1 author, 2016-06-15
DORMANTno replies

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

From: Jay Soffian <hidden>
Date: 2016-06-15 22:52:05
Subsystem: the rest · Maintainer: Linus Torvalds

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help