Commit 58d33126d44eeff69e375e500d1e77e03e2665a0

Edward Thomson 2015-12-26T19:47:17

merge driver: tests for set and unset merge attribute Ensure that setting the merge attribute forces the built-in default `text` driver and does *not* honor the `merge.default` configuration option. Further ensure that unsetting the merge attribute forces a conflict (the `binary` driver).

diff --git a/tests/merge/driver.c b/tests/merge/driver.c
index c29f87f..26041ec 100644
--- a/tests/merge/driver.c
+++ b/tests/merge/driver.c
@@ -146,7 +146,15 @@ static void set_gitattributes_to(const char *driver)
 {
 	git_buf line = GIT_BUF_INIT;
 
-	cl_git_pass(git_buf_printf(&line, "automergeable.txt merge=%s\n", driver));
+	if (driver && strcmp(driver, ""))
+		git_buf_printf(&line, "automergeable.txt merge=%s\n", driver);
+	else if (driver)
+		git_buf_printf(&line, "automergeable.txt merge\n");
+	else
+		git_buf_printf(&line, "automergeable.txt -merge\n");
+
+	cl_assert(!git_buf_oom(&line));
+
 	cl_git_mkfile(TEST_REPO_PATH "/.gitattributes", line.ptr);
 	git_buf_free(&line);
 }
@@ -450,3 +458,30 @@ void test_merge_driver__mergedefault_deferring_falls_back_to_text(void)
 	git_merge_driver_unregister("defer");
 }
 
+void test_merge_driver__set_forces_text(void)
+{
+	const git_index_entry *idx;
+
+	/* `merge` without specifying a driver indicates `text` */
+	set_gitattributes_to("");
+	cl_repo_set_string(repo, "merge.default", "custom");
+
+	merge_branch();
+
+	cl_assert((idx = git_index_get_bypath(repo_index, "automergeable.txt", 0)));
+	cl_assert_equal_oid(&automergeable_id, &idx->id);
+}
+
+void test_merge_driver__unset_forces_binary(void)
+{
+	const git_index_entry *ancestor, *ours, *theirs;
+
+	/* `-merge` without specifying a driver indicates `binary` */
+	set_gitattributes_to(NULL);
+	cl_repo_set_string(repo, "merge.default", "custom");
+
+	merge_branch();
+
+	cl_git_pass(git_index_conflict_get(&ancestor, &ours, &theirs,
+		repo_index, "automergeable.txt"));
+}