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).
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
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"));
+}