Always do tree to index diffs case sensitively Trees are always case sensitive. The index is always case preserving and will be case sensitive when it is turned into a tree. Therefore the tree and the index can and should always be compared to one another case sensitively. This will restore the index to case insensitive order after the diff has been generated. Consider this a short-term fix. The long term fix is to have the index always stored both case sensitively and case insensitively (at least on platforms that sometimes require case insensitivity).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
diff --git a/src/diff.c b/src/diff.c
index 87189a4..fa2c5c7 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -364,6 +364,8 @@ static git_diff_list *diff_list_alloc(
diff->strncomp = git__strncasecmp;
diff->pfxcomp = git__prefixcmp_icase;
diff->entrycomp = git_index_entry__cmp_icase;
+
+ diff->deltas._cmp = git_diff_delta__casecmp;
}
return diff;
@@ -1127,17 +1129,40 @@ int git_diff_tree_to_index(
const git_diff_options *opts)
{
int error = 0;
+ bool reset_index_ignore_case = false;
assert(diff && repo);
if (!index && (error = git_repository_index__weakptr(&index, repo)) < 0)
return error;
+ if (index->ignore_case) {
+ git_index__set_ignore_case(index, false);
+ reset_index_ignore_case = true;
+ }
+
DIFF_FROM_ITERATORS(
git_iterator_for_tree(&a, old_tree, 0, pfx, pfx),
git_iterator_for_index(&b, index, 0, pfx, pfx)
);
+ if (reset_index_ignore_case) {
+ git_index__set_ignore_case(index, true);
+
+ if (!error) {
+ git_diff_list *d = *diff;
+
+ d->opts.flags |= GIT_DIFF_DELTAS_ARE_ICASE;
+ d->strcomp = git__strcasecmp;
+ d->strncomp = git__strncasecmp;
+ d->pfxcomp = git__prefixcmp_icase;
+ d->entrycomp = git_index_entry__cmp_icase;
+
+ d->deltas._cmp = git_diff_delta__casecmp;
+ git_vector_sort(&d->deltas);
+ }
+ }
+
return error;
}