Fix typo setting sorted flag when reloading index This fixes a typo I made for setting the sorted flag on the index after a reload. That typo didn't actually cause any test failures so I'm also adding a test that explicitly checks that the index is correctly sorted after a reload when ignoring case and when not.
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 55 56 57 58 59
diff --git a/src/index.c b/src/index.c
index 1ab126c..42eb5fd 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1811,8 +1811,10 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
#undef seek_forward
- /* Entries are stored case-sensitively on disk. */
- git_vector_set_sorted(&index->entries, index->ignore_case);
+ /* Entries are stored case-sensitively on disk, so re-sort now if
+ * in-memory index is supposed to be case-insensitive
+ */
+ git_vector_set_sorted(&index->entries, !index->ignore_case);
git_vector_sort(&index->entries);
return 0;
diff --git a/tests/index/tests.c b/tests/index/tests.c
index 55a2f2c..6e28af1 100644
--- a/tests/index/tests.c
+++ b/tests/index/tests.c
@@ -543,3 +543,37 @@ void test_index_tests__corrupted_extension(void)
cl_git_fail_with(git_index_open(&index, TEST_INDEXBAD_PATH), GIT_ERROR);
}
+
+static void assert_index_is_sorted(git_index *index)
+{
+ git_vector *entries = &index->entries;
+ size_t i;
+
+ cl_assert(git_vector_is_sorted(entries));
+
+ for (i = 1; i < git_vector_length(entries); ++i) {
+ git_index_entry *prev = git_vector_get(entries, i - 1);
+ git_index_entry *curr = git_vector_get(entries, i);
+ cl_assert(index->entries._cmp(prev, curr) <= 0);
+ }
+}
+
+void test_index_tests__reload_while_ignoring_case(void)
+{
+ git_index *index;
+ unsigned int caps;
+
+ cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+ assert_index_is_sorted(index);
+
+ caps = git_index_caps(index);
+ cl_git_pass(git_index_set_caps(index, caps &= ~GIT_INDEXCAP_IGNORE_CASE));
+ cl_git_pass(git_index_read(index, true));
+ assert_index_is_sorted(index);
+
+ cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE));
+ cl_git_pass(git_index_read(index, true));
+ assert_index_is_sorted(index);
+
+ git_index_free(index);
+}