Commit 58d33126 by Edward Thomson Committed by Edward Thomson

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).
parent d3f0875a
...@@ -146,7 +146,15 @@ static void set_gitattributes_to(const char *driver) ...@@ -146,7 +146,15 @@ static void set_gitattributes_to(const char *driver)
{ {
git_buf line = GIT_BUF_INIT; 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); cl_git_mkfile(TEST_REPO_PATH "/.gitattributes", line.ptr);
git_buf_free(&line); git_buf_free(&line);
} }
...@@ -450,3 +458,30 @@ void test_merge_driver__mergedefault_deferring_falls_back_to_text(void) ...@@ -450,3 +458,30 @@ void test_merge_driver__mergedefault_deferring_falls_back_to_text(void)
git_merge_driver_unregister("defer"); 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"));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment