Commits

Anonymous committed 197cf8d Merge

Merge branch 'jc/maint-1.6.0-diff-borrow-carefully' into maint

* jc/maint-1.6.0-diff-borrow-carefully:
diff --cached: do not borrow from a work tree when a path is marked as assume-unchanged

Comments (0)

Files changed (2)

 	struct stat st;
 	int pos, len;
 
-	/* We do not read the cache ourselves here, because the
+	/*
+	 * We do not read the cache ourselves here, because the
 	 * benchmark with my previous version that always reads cache
 	 * shows that it makes things worse for diff-tree comparing
 	 * two linux-2.6 kernel trees in an already checked out work
 		return 0;
 
 	/*
+	 * If ce is marked as "assume unchanged", there is no
+	 * guarantee that work tree matches what we are looking for.
+	 */
+	if (ce->ce_flags & CE_VALID)
+		return 0;
+
+	/*
 	 * If ce matches the file in the work tree, we can reuse it.
 	 */
 	if (ce_uptodate(ce) ||

t/t4020-diff-external.sh

 	test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
 '
 
+test_expect_success 'diff --cached' '
+	git add file &&
+	git update-index --assume-unchanged file &&
+	echo second >file &&
+	git diff --cached >actual &&
+	test_cmp ../t4020/diff.NUL actual
+'
+
 test_done