Re: [PATCH 3/3] commit: give a hint when a commit message has been abandoned
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 23, 2012, 20:49 UTC
- Message-ID
- <7vzk6qjj7w.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <20120723185218.GC27588@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 9 quoted lines
> If we launch an editor for the user to create a commit > message, they may put significant work into doing so. > Typically we try to check common mistakes that could cause > the commit to fail early, so that we die before the user > goes to the trouble. > > We may still experience some errors afterwards, though; in > this case, the user is given no hint that their commit > message has been saved. Let's tell them where it is.
Liberal use of atexit() for something like this makes me cringe somewhat.
Show 62 quoted lines
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> I did not bother protecting this with advice.* config, as it is unlikely
> to come up regularly. If somebody cares, they are welcome to add it on
> top.
>
> builtin/commit.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 20cef95..149e07d 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -116,6 +116,16 @@ static enum {
> STATUS_FORMAT_PORCELAIN
> } status_format = STATUS_FORMAT_LONG;
>
> +static int mention_abandoned_message;
> +static void maybe_mention_abandoned_message(void)
> +{
> + if (!mention_abandoned_message)
> + return;
> + advise(_("Your commit message has been saved in '%s' and will be\n"
> + "overwritten by the next invocation of \"git commit\"."),
> + git_path(commit_editmsg));
> +}
> +
> static int opt_parse_m(const struct option *opt, const char *arg, int unset)
> {
> struct strbuf *buf = opt->value;
> @@ -848,6 +858,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
> _("Please supply the message using either -m or -F option.\n"));
> exit(1);
> }
> + atexit(maybe_mention_abandoned_message);
> + mention_abandoned_message = 1;
> }
>
> if (!no_verify &&
> @@ -1532,11 +1544,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
> if (template_untouched(&sb) && !allow_empty_message) {
> rollback_index_files();
> fprintf(stderr, _("Aborting commit; you did not edit the message.\n"));
> + mention_abandoned_message = 0;
> exit(1);
> }
> if (message_is_empty(&sb) && !allow_empty_message) {
> rollback_index_files();
> fprintf(stderr, _("Aborting commit due to empty commit message.\n"));
> + mention_abandoned_message = 0;
> exit(1);
> }
>
> @@ -1579,6 +1593,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
> die(_("cannot update HEAD ref"));
> }
>
> + mention_abandoned_message = 0;
> unlink(git_path("CHERRY_PICK_HEAD"));
> unlink(git_path("REVERT_HEAD"));
> unlink(git_path("MERGE_HEAD"));