]> git.proxmox.com Git - libgit2.git/commitdiff
merge driver: tests for set and unset merge attribute
authorEdward Thomson <ethomson@edwardthomson.com>
Sat, 26 Dec 2015 19:47:17 +0000 (19:47 +0000)
committerEdward Thomson <ethomson@github.com>
Thu, 17 Mar 2016 15:02:27 +0000 (11:02 -0400)
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).

tests/merge/driver.c

index c29f87f8a286ffda362a6ed3c1e5acfddcb742b0..26041eca73d6aff951f183572e2ecad823ea0682 100644 (file)
@@ -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"));
+}