When get_cleanup_mode was provided with an invalid cleanup_arg, it used to die. Warn user and fallback to default behaviour if an invalid cleanup_arg is given. Signed-off-by: Denton Liu <liu.denton@xxxxxxxxx> --- builtin/commit.c | 2 +- builtin/merge.c | 4 ++-- builtin/revert.c | 2 +- sequencer.c | 10 +++++++--- sequencer.h | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 43291d79bd..0072a5817a 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1167,7 +1167,7 @@ static int parse_and_validate_options(int argc, const char *argv[], die(_("Only one of --include/--only/--all/--interactive/--patch can be used.")); if (argc == 0 && (also || (only && !amend && !allow_empty))) die(_("No paths with --include/--only does not make sense.")); - cleanup_mode = get_cleanup_mode(cleanup_arg, use_editor); + cleanup_mode = get_cleanup_mode(cleanup_arg, use_editor, 1); handle_untracked_files_arg(s); diff --git a/builtin/merge.c b/builtin/merge.c index d4217ebcf5..3b597ec540 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -916,7 +916,7 @@ static int suggest_conflicts(void) * Thus, we will get the cleanup mode which is returned when we _are_ using * an editor. */ - append_conflicts_hint(&msgbuf, get_cleanup_mode(cleanup_arg, 1)); + append_conflicts_hint(&msgbuf, get_cleanup_mode(cleanup_arg, 1, 1)); fputs(msgbuf.buf, fp); strbuf_release(&msgbuf); fclose(fp); @@ -1424,7 +1424,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (option_edit < 0) option_edit = default_edit_option(); - cleanup_mode = get_cleanup_mode(cleanup_arg, 0 < option_edit); + cleanup_mode = get_cleanup_mode(cleanup_arg, 0 < option_edit, 1); if (!use_strategies) { if (!remoteheads) diff --git a/builtin/revert.c b/builtin/revert.c index fe18036be7..a96f2ecd8a 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -139,7 +139,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) opts->allow_empty = 1; if (cleanup_arg) - opts->default_msg_cleanup = get_cleanup_mode(cleanup_arg, 1); + opts->default_msg_cleanup = get_cleanup_mode(cleanup_arg, 1, 1); /* Check for incompatible command line arguments */ if (cmd) { diff --git a/sequencer.c b/sequencer.c index 5c04bae7ac..7d18c55223 100644 --- a/sequencer.c +++ b/sequencer.c @@ -170,7 +170,7 @@ static int git_sequencer_config(const char *k, const char *v, void *cb) if (status) return status; - opts->default_msg_cleanup = get_cleanup_mode(s, !is_rebase_i(opts)); + opts->default_msg_cleanup = get_cleanup_mode(s, !is_rebase_i(opts), 0); free((char *)s); return status; @@ -488,7 +488,7 @@ static int fast_forward_to(const struct object_id *to, const struct object_id *f } enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg, - int use_editor) + int use_editor, int die_on_error) { if (!cleanup_arg || !strcmp(cleanup_arg, "default")) return use_editor ? COMMIT_MSG_CLEANUP_ALL : @@ -502,7 +502,11 @@ enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg, else if (!strcmp(cleanup_arg, "scissors")) return use_editor ? COMMIT_MSG_CLEANUP_SCISSORS : COMMIT_MSG_CLEANUP_SPACE; - else + else if (!die_on_error) { + warning(_("Invalid cleanup mode %s, falling back to default"), cleanup_arg); + return use_editor ? COMMIT_MSG_CLEANUP_ALL : + COMMIT_MSG_CLEANUP_SPACE; + } else die(_("Invalid cleanup mode %s"), cleanup_arg); } diff --git a/sequencer.h b/sequencer.h index aa99503dd7..c4c80051ea 100644 --- a/sequencer.h +++ b/sequencer.h @@ -94,7 +94,7 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag); void append_conflicts_hint(struct strbuf *msgbuf, enum commit_msg_cleanup_mode cleanup_mode); enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg, - int use_editor); + int use_editor, int die_on_error); void cleanup_message(struct strbuf *msgbuf, enum commit_msg_cleanup_mode cleanup_mode, int verbose); -- 2.21.0.370.g4fdb13b891