merge drivers: handle configured but not found 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 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/src/merge.c b/src/merge.c
index 27c0cea..a0f2405 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -891,7 +891,8 @@ static int merge_conflict_resolve_contents(
git_index_entry *merge_result;
git_odb *odb = NULL;
const char *name;
- int error = 0;
+ bool fallback = false;
+ int error;
assert(resolved && diff_list && conflict);
@@ -924,12 +925,20 @@ static int merge_conflict_resolve_contents(
/* find the merge driver for this file */
if ((error = git_merge_driver_for_source(&name, &driver, &source)) < 0)
goto done;
+
+ if (driver == NULL)
+ fallback = true;
}
- error = merge_conflict_invoke_driver(&merge_result, name, driver,
- diff_list, &source);
+ if (driver) {
+ error = merge_conflict_invoke_driver(&merge_result, name, driver,
+ diff_list, &source);
+
+ if (error == GIT_PASSTHROUGH)
+ fallback = true;
+ }
- if (error == GIT_PASSTHROUGH) {
+ if (fallback) {
error = merge_conflict_invoke_driver(&merge_result, "text",
&git_merge_driver__text.base, diff_list, &source);
}
diff --git a/tests/merge/driver.c b/tests/merge/driver.c
index 670c2c4..c75a007 100644
--- a/tests/merge/driver.c
+++ b/tests/merge/driver.c
@@ -368,3 +368,21 @@ void test_merge_driver__unset_forces_binary(void)
cl_git_pass(git_index_conflict_get(&ancestor, &ours, &theirs,
repo_index, "automergeable.txt"));
}
+
+void test_merge_driver__not_configured_driver_falls_back(void)
+{
+ const git_index_entry *idx;
+
+ test_drivers_unregister();
+
+ /* `merge` without specifying a driver indicates `text` */
+ set_gitattributes_to("notfound");
+
+ merge_branch();
+
+ cl_assert((idx = git_index_get_bypath(repo_index, "automergeable.txt", 0)));
+ cl_assert_equal_oid(&automergeable_id, &idx->id);
+
+ test_drivers_register();
+}
+