Commit 1540b19990fa5c566d607785c7b3651756e706ff

Edward Thomson 2013-05-31T18:12:49

some simple case-sensitive index tests

diff --git a/tests-clar/diff/rename.c b/tests-clar/diff/rename.c
index 224945e..6227a54 100644
--- a/tests-clar/diff/rename.c
+++ b/tests-clar/diff/rename.c
@@ -906,3 +906,35 @@ void test_diff_rename__rejected_match_can_match_others(void)
 	git_buf_free(&one);
 	git_buf_free(&two);
 }
+
+void test_diff_rename__case_changes_are_split(void)
+{
+	git_index *index;
+	git_tree *tree;
+	git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+	git_diff_list *diff = NULL;
+	diff_expects exp;
+
+	cl_git_pass(git_repository_index(&index, g_repo));
+
+	cl_git_pass(
+		git_revparse_single((git_object **)&tree, g_repo, "HEAD^{tree}"));
+
+	cl_git_pass(p_rename("renames/ikeepsix.txt", "renames/IKEEPSIX.txt"));
+
+	cl_git_pass(git_index_remove_bypath(index, "ikeepsix.txt"));
+	cl_git_pass(git_index_add_bypath(index, "IKEEPSIX.txt"));
+	cl_git_pass(git_index_write(index));
+
+	cl_git_pass(git_diff_tree_to_index(&diff, g_repo, tree, index, NULL));
+
+	memset(&exp, 0, sizeof(exp));
+	cl_git_pass(git_diff_foreach(
+		diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+	cl_assert_equal_i(2, exp.files);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
+	cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]);
+
+	git_index_free(index);
+}
+
diff --git a/tests-clar/index/tests.c b/tests-clar/index/tests.c
index 88e374e..53d45a8 100644
--- a/tests-clar/index/tests.c
+++ b/tests-clar/index/tests.c
@@ -416,3 +416,35 @@ void test_index_tests__remove_directory(void)
 	git_repository_free(repo);
 	cl_fixture_cleanup("index_test");
 }
+
+void test_index_tests__preserves_case(void)
+{
+	git_repository *repo;
+	git_index *index;
+	const git_index_entry *entry;
+
+	cl_set_cleanup(&cleanup_myrepo, NULL);
+
+	cl_git_pass(git_repository_init(&repo, "./myrepo", 0));
+	cl_git_pass(git_repository_index(&index, repo));
+
+	cl_git_rewritefile("myrepo/test.txt", "hey there\n");
+	cl_git_pass(git_index_add_bypath(index, "test.txt"));
+
+	cl_git_pass(p_rename("myrepo/test.txt", "myrepo/TEST.txt"));
+	cl_git_rewritefile("myrepo/TEST.txt", "hello again\n");
+	cl_git_pass(git_index_add_bypath(index, "TEST.txt"));
+
+	cl_assert(git_index_entrycount(index) == 1);
+
+	/* Test access by path instead of index */
+	cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL);
+	cl_assert((entry = git_index_get_bypath(index, "TEST.txt", 0)) != NULL);
+
+	/* The path should *not* have changed without an explicit remove */
+	cl_assert(git__strcmp(entry->path, "test.txt") == 0);
+
+	git_index_free(index);
+	git_repository_free(repo);
+}
+