summaryrefslogtreecommitdiff
path: root/tests/merge/driver.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2015-12-23 23:52:02 -0600
committerEdward Thomson <ethomson@github.com>2016-03-17 11:02:27 -0400
commit7d307c1edc5430dce270302d539d6eab8ed054c7 (patch)
treebe9e36a90db9867bdcef1c40090b673be466b88f /tests/merge/driver.c
parent59f293146503bf5e615161fe89c305f080755dd1 (diff)
downloadlibgit2-7d307c1edc5430dce270302d539d6eab8ed054c7.tar.gz
merge driver: test GIT_EMERGECONFLICT
When a `check` or `apply` callback function returns `GIT_EMERGECONFLICT` stop and product a conflict.
Diffstat (limited to 'tests/merge/driver.c')
-rw-r--r--tests/merge/driver.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/tests/merge/driver.c b/tests/merge/driver.c
index 2597e5721..d45178281 100644
--- a/tests/merge/driver.c
+++ b/tests/merge/driver.c
@@ -301,3 +301,93 @@ void test_merge_driver__apply_can_defer(void)
git_merge_driver_unregister("defer");
}
+static int conflict_driver_check(
+ git_merge_driver *s,
+ void **payload,
+ const char *name,
+ const git_merge_driver_source *src)
+{
+ GIT_UNUSED(s);
+ GIT_UNUSED(payload);
+ GIT_UNUSED(name);
+ GIT_UNUSED(src);
+
+ return GIT_EMERGECONFLICT;
+}
+
+static struct test_merge_driver test_driver_conflict_check = {
+ {
+ GIT_MERGE_DRIVER_VERSION,
+ test_driver_init,
+ test_driver_shutdown,
+ conflict_driver_check,
+ test_driver_apply,
+ test_driver_cleanup
+ },
+ 0,
+ 0,
+};
+
+void test_merge_driver__check_can_conflict(void)
+{
+ const git_index_entry *ancestor, *ours, *theirs;
+
+ cl_git_pass(git_merge_driver_register("conflict",
+ &test_driver_conflict_check.base));
+
+ set_gitattributes_to("conflict");
+ merge_branch();
+
+ cl_git_pass(git_index_conflict_get(&ancestor, &ours, &theirs,
+ repo_index, "automergeable.txt"));
+
+ git_merge_driver_unregister("conflict");
+}
+
+static int conflict_driver_apply(
+ git_merge_driver *s,
+ void **payload,
+ const char **path_out,
+ uint32_t *mode_out,
+ git_buf *merged_out,
+ const git_merge_driver_source *src)
+{
+ GIT_UNUSED(s);
+ GIT_UNUSED(payload);
+ GIT_UNUSED(path_out);
+ GIT_UNUSED(mode_out);
+ GIT_UNUSED(merged_out);
+ GIT_UNUSED(src);
+
+ return GIT_EMERGECONFLICT;
+}
+
+static struct test_merge_driver test_driver_conflict_apply = {
+ {
+ GIT_MERGE_DRIVER_VERSION,
+ test_driver_init,
+ test_driver_shutdown,
+ test_driver_check,
+ conflict_driver_apply,
+ test_driver_cleanup
+ },
+ 0,
+ 0,
+};
+
+void test_merge_driver__apply_can_conflict(void)
+{
+ const git_index_entry *ancestor, *ours, *theirs;
+
+ cl_git_pass(git_merge_driver_register("conflict",
+ &test_driver_conflict_apply.base));
+
+ set_gitattributes_to("conflict");
+ merge_branch();
+
+ cl_git_pass(git_index_conflict_get(&ancestor, &ours, &theirs,
+ repo_index, "automergeable.txt"));
+
+ git_merge_driver_unregister("conflict");
+}
+