From: Phillip Wood <phillip.wood@xxxxxxxxxxxxx> Return an error rather than dying so that the sequencer can exit cleanly once it starts committing without forking 'git commit' Signed-off-by: Phillip Wood <phillip.wood@xxxxxxxxxxxxx> --- builtin/commit.c | 3 ++- sequencer.c | 17 +++++++++++------ sequencer.h | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 22d260197e84a828f984575cfa92789391531ca3..e924d8a14c8532a78d072420aeb662ce616181a4 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1598,7 +1598,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) flags |= SUMMARY_INITIAL_COMMIT; if (author_date_is_interesting()) flags |= SUMMARY_SHOW_AUTHOR_DATE; - print_commit_summary(prefix, &oid, flags); + if (print_commit_summary(prefix, &oid, flags)) + exit(128); } UNLEAK(err); diff --git a/sequencer.c b/sequencer.c index 03207db71821c0c3d1c442d3b01b11e3b010367e..61bb75352202cf896ffec41e972f366e94d569c1 100644 --- a/sequencer.c +++ b/sequencer.c @@ -877,8 +877,8 @@ static const char *implicit_ident_advice(void) } -void print_commit_summary(const char *prefix, const struct object_id *oid, - unsigned int flags) +int print_commit_summary(const char *prefix, const struct object_id *oid, + unsigned int flags) { struct rev_info rev; struct commit *commit; @@ -887,12 +887,13 @@ void print_commit_summary(const char *prefix, const struct object_id *oid, struct pretty_print_context pctx = {0}; struct strbuf author_ident = STRBUF_INIT; struct strbuf committer_ident = STRBUF_INIT; + int ret = 0; commit = lookup_commit(oid); if (!commit) - die(_("couldn't look up newly created commit")); + return error(_("couldn't look up newly created commit")); if (parse_commit(commit)) - die(_("could not parse newly created commit")); + return error(_("could not parse newly created commit")); strbuf_addstr(&format, "format:%h] %s"); @@ -936,8 +937,10 @@ void print_commit_summary(const char *prefix, const struct object_id *oid, diff_setup_done(&rev.diffopt); head = resolve_ref_unsafe("HEAD", 0, NULL, NULL); - if (!head) - die_errno(_("unable to resolve HEAD after creating commit")); + if (!head) { + ret = error_errno(_("unable to resolve HEAD after creating commit")); + goto out; + } if (!strcmp(head, "HEAD")) head = _("detached HEAD"); else @@ -950,7 +953,9 @@ void print_commit_summary(const char *prefix, const struct object_id *oid, log_tree_commit(&rev, commit); } +out: strbuf_release(&format); + return ret; } static int is_original_commit_empty(struct commit *commit) diff --git a/sequencer.h b/sequencer.h index 8e0dbe59bbc1ccd3847454faf8bd09d5ca1ff93a..e4040cac08cb69c9b91db3fe77ae392c8d6d0f50 100644 --- a/sequencer.h +++ b/sequencer.h @@ -78,6 +78,6 @@ void commit_post_rewrite(const struct commit *current_head, #define SUMMARY_INITIAL_COMMIT (1 << 0) #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1) -void print_commit_summary(const char *prefix, const struct object_id *oid, - unsigned int flags); +int print_commit_summary(const char *prefix, const struct object_id *oid, + unsigned int flags); #endif -- 2.15.0