merge driver: test GIT_EMERGECONFLICT When a `check` or `apply` callback function returns `GIT_EMERGECONFLICT` stop and product a conflict.
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
diff --git a/tests/merge/driver.c b/tests/merge/driver.c
index 2597e57..d451782 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");
+}
+