Commit c4ce017fd5e829a81860470fc4a26ae34f537841

Edward Thomson 2018-02-18T22:27:34

index::names tests: add conflicts with high stages We add entries into the main index to correspond with the NAME entries that we're going to test. NAME entries store the results of conflicts occuring with rename detection during merge, and they must correspond to conflicts in the index. This test was mistakenly adding regular entries. The checkout validation failed, since it requires NAME entries to correspond to high-stage (conflict) entries. Correct the test to actually create conflicts.

diff --git a/tests/index/names.c b/tests/index/names.c
index d462088..664ddd1 100644
--- a/tests/index/names.c
+++ b/tests/index/names.c
@@ -25,10 +25,47 @@ void test_index_names__cleanup(void)
 	cl_git_sandbox_cleanup();
 }
 
+static void index_add_conflicts(void)
+{
+	git_index_entry entry = {{0}};
+	const char *paths[][3] = {
+		{ "ancestor", "ours", "theirs" },
+		{ "ancestor2", "ours2", "theirs2" },
+		{ "ancestor3", "ours3", "theirs3" } };
+	const char **conflict;
+	size_t i;
+
+	for (i = 0; i < ARRAY_SIZE(paths); i++) {
+		conflict = paths[i];
+
+		/* ancestor */
+		entry.path = conflict[0];
+		entry.mode = GIT_FILEMODE_BLOB;
+		GIT_IDXENTRY_STAGE_SET(&entry, GIT_INDEX_STAGE_ANCESTOR);
+		git_oid_fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81");
+		cl_git_pass(git_index_add(repo_index, &entry));
+
+		/* ours */
+		entry.path = conflict[1];
+		entry.mode = GIT_FILEMODE_BLOB;
+		GIT_IDXENTRY_STAGE_SET(&entry, GIT_INDEX_STAGE_OURS);
+		git_oid_fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81");
+		cl_git_pass(git_index_add(repo_index, &entry));
+
+		/* theirs */
+		entry.path = conflict[2];
+		entry.mode = GIT_FILEMODE_BLOB;
+		GIT_IDXENTRY_STAGE_SET(&entry, GIT_INDEX_STAGE_THEIRS);
+		git_oid_fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81");
+		cl_git_pass(git_index_add(repo_index, &entry));
+	}
+}
+
 void test_index_names__add(void)
 {
 	const git_index_name_entry *conflict_name;
 
+	index_add_conflicts();
 	cl_git_pass(git_index_name_add(repo_index, "ancestor", "ours", "theirs"));
 	cl_git_pass(git_index_name_add(repo_index, "ancestor2", "ours2", NULL));
 	cl_git_pass(git_index_name_add(repo_index, "ancestor3", NULL, "theirs3"));