merge_recursive: abort properly upon errors

There are a couple of places where return values never indicated errors before, as we simply died instead of returning. But now negative return values mean that there was an error and we have to abort the operation. Let's do exactly that. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 26, 2016 at 18:06 UTC de8946de1694a8cf311daab7b2c416d76cb04d23
1 file changed +12 -5
merge-recursive.c
+12 -5
@@ -1949,17 +1949,19 @@ int merge_recursive(struct merge_options *o,
1949 /*
1950 * When the merge fails, the result contains files
1951 * with conflict markers. The cleanness flag is
1952 - * ignored, it was never actually used, as result of
1953 - * merge_trees has always overwritten it: the committed
1954 - * "conflicts" were already resolved.
1952 + * ignored (unless indicating an error), it was never
1953 + * actually used, as result of merge_trees has always
1954 + * overwritten it: the committed "conflicts" were
1955 + * already resolved.
1956 */
1957 discard_cache();
1958 saved_b1 = o->branch1;
1959 saved_b2 = o->branch2;
1960 o->branch1 = "Temporary merge branch 1";
1961 o->branch2 = "Temporary merge branch 2";
1961 - merge_recursive(o, merged_common_ancestors, iter->item,
1962 - NULL, &merged_common_ancestors);
1962 + if (merge_recursive(o, merged_common_ancestors, iter->item,
1963 + NULL, &merged_common_ancestors) < 0)
1964 + return -1;
1965 o->branch1 = saved_b1;
1966 o->branch2 = saved_b2;
1967 o->call_depth--;
@@ -1975,6 +1977,8 @@ int merge_recursive(struct merge_options *o,
1977 o->ancestor = "merged common ancestors";
1978 clean = merge_trees(o, h1->tree, h2->tree, merged_common_ancestors->tree,
1979 &mrtree);
1980 + if (clean < 0)
1981 + return clean;
1982
1983 if (o->call_depth) {
1984 *result = make_virtual_commit(mrtree, "merged tree");
@@ -2031,6 +2035,9 @@ int merge_recursive_generic(struct merge_options *o,
2035 hold_locked_index(lock, 1);
2036 clean = merge_recursive(o, head_commit, next_commit, ca,
2037 result);
2038 + if (clean < 0)
2039 + return clean;
2040 +
2041 if (active_cache_changed &&
2042 write_locked_index(&the_index, lock, COMMIT_LOCK))
2043 return error(_("Unable to write index."));