Commit f608f3bb274dbf413127ba352f48021ed538139e

Russell Belfer 2014-04-24T15:25:01

Test toggling core.precomposeunicode yields rename There is an interesting difference with core Git here, though. Because libgit2 will do rename detection with the working directory, in the last case where the HEAD and the working directory both have the decomposed data and the index has the composed data, we generate a single status record with two renames whereas Git will generate one rename (head to index) and one untracked file.

diff --git a/tests/status/renames.c b/tests/status/renames.c
index ab9cd74..39fb801 100644
--- a/tests/status/renames.c
+++ b/tests/status/renames.c
@@ -636,4 +636,73 @@ void test_status_renames__precomposed_unicode_rename(void)
 	git_status_list_free(statuslist);
 }
 
+void test_status_renames__precomposed_unicode_toggle_is_rename(void)
+{
+	git_status_list *statuslist;
+	git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+	struct status_entry expected0[] = {
+		{ GIT_STATUS_INDEX_RENAMED, "ikeepsix.txt", nfd },
+	};
+	struct status_entry expected1[] = {
+		{ GIT_STATUS_WT_RENAMED, nfd, nfc },
+	};
+	struct status_entry expected2[] = {
+		{ GIT_STATUS_INDEX_RENAMED, nfd, nfc },
+	};
+	struct status_entry expected3[] = {
+		{ GIT_STATUS_INDEX_RENAMED | GIT_STATUS_WT_RENAMED, nfd, nfd },
+	};
+
+	cl_repo_set_bool(g_repo, "core.precomposeunicode", false);
+	rename_file(g_repo, "ikeepsix.txt", nfd);
+
+	{
+		git_index *index;
+		cl_git_pass(git_repository_index(&index, g_repo));
+		cl_git_pass(git_index_remove_bypath(index, "ikeepsix.txt"));
+		cl_git_pass(git_index_add_bypath(index, nfd));
+		cl_git_pass(git_index_write(index));
+		git_index_free(index);
+	}
+
+	opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+		GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
+		GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR;
+
+	cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+	check_status(statuslist, expected0, ARRAY_SIZE(expected0));
+	git_status_list_free(statuslist);
+
+	cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "commit nfd");
+
+	cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+	cl_assert_equal_sz(0, git_status_list_entrycount(statuslist));
+	git_status_list_free(statuslist);
+
+	cl_repo_set_bool(g_repo, "core.precomposeunicode", true);
+
+	cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+	check_status(statuslist, expected1, ARRAY_SIZE(expected1));
+	git_status_list_free(statuslist);
+
+	{
+		git_index *index;
+		cl_git_pass(git_repository_index(&index, g_repo));
+		cl_git_pass(git_index_remove_bypath(index, nfd));
+		cl_git_pass(git_index_add_bypath(index, nfc));
+		cl_git_pass(git_index_write(index));
+		git_index_free(index);
+	}
+
+	cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+	check_status(statuslist, expected2, ARRAY_SIZE(expected2));
+	git_status_list_free(statuslist);
+
+	cl_repo_set_bool(g_repo, "core.precomposeunicode", false);
+
+	cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+	check_status(statuslist, expected3, ARRAY_SIZE(expected3));
+	git_status_list_free(statuslist);
+}
+
 #endif