A truly libified function does not die() just for fun. As such, the recursive merge will convert all die() calls to return -1 instead in the next commits, giving the caller a chance at least to print some helpful message. Let's prepare the builtins for this fatal error condition, even if we do not really do more than imitating the previous die()'s exit(128): this is what callers of e.g. `git merge` have come to expect. Note that the callers of the sequencer (revert and cherry-pick) already fail fast even for the return value -1; The only difference is that they now get a chance to say "<command> failed". Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- builtin/checkout.c | 4 +++- builtin/merge.c | 4 ++++ sequencer.c | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index c3486bd..14312f7 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -567,8 +567,10 @@ static int merge_working_tree(const struct checkout_opts *opts, o.ancestor = old->name; o.branch1 = new->name; o.branch2 = "local"; - merge_trees(&o, new->commit->tree, work, + ret = merge_trees(&o, new->commit->tree, work, old->commit->tree, &result); + if (ret < 0) + exit(128); ret = reset_tree(new->commit->tree, opts, 0, writeout_error); if (ret) diff --git a/builtin/merge.c b/builtin/merge.c index b555a1b..133b853 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -682,6 +682,8 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, hold_locked_index(&lock, 1); clean = merge_recursive(&o, head, remoteheads->item, reversed, &result); + if (clean < 0) + exit(128); if (active_cache_changed && write_locked_index(&the_index, &lock, COMMIT_LOCK)) die (_("unable to write %s"), get_index_file()); @@ -1550,6 +1552,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) ret = try_merge_strategy(use_strategies[i]->name, common, remoteheads, head_commit, head_arg); + if (ret < 0) + exit(128); if (!option_commit && !ret) { merge_was_ok = 1; /* diff --git a/sequencer.c b/sequencer.c index c6362d6..13b794a 100644 --- a/sequencer.c +++ b/sequencer.c @@ -293,6 +293,8 @@ static int do_recursive_merge(struct commit *base, struct commit *next, clean = merge_trees(&o, head_tree, next_tree, base_tree, &result); + if (clean < 0) + return clean; if (active_cache_changed && write_locked_index(&the_index, &index_lock, COMMIT_LOCK)) @@ -561,6 +563,8 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts) if (!opts->strategy || !strcmp(opts->strategy, "recursive") || opts->action == REPLAY_REVERT) { res = do_recursive_merge(base, next, base_label, next_label, head, &msgbuf, opts); + if (res < 0) + return res; write_message(&msgbuf, git_path_merge_msg()); } else { struct commit_list *common = NULL; -- 2.9.0.268.gcabc8b0 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html