All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Ramana Kumar <ramana@member.fsf.org>, git@vger.kernel.org
Subject: Re: [PATCH 3/3] commit: give a hint when a commit message has been abandoned
Date: Mon, 23 Jul 2012 13:49:55 -0700	[thread overview]
Message-ID: <7vzk6qjj7w.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <20120723185218.GC27588@sigill.intra.peff.net> (Jeff King's message of "Mon, 23 Jul 2012 14:52:18 -0400")

Jeff King <peff@peff.net> writes:

> 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.

>
> 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"));

  reply	other threads:[~2012-07-23 20:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAMej=25=xj61pc+k42dv3byuBqUJzW21Sz+BXwoufqnKwV5Bbg@mail.gmail.com>
2012-07-21 14:26 ` empty ident name trashes commit message Ramana Kumar
2012-07-23 17:27   ` Jeff King
2012-07-23 18:05     ` Ramana Kumar
2012-07-23 18:46     ` Jeff King
2012-07-23 18:48       ` [PATCH 1/3] advice: pass varargs to strbuf_vaddf, not strbuf_addf Jeff King
2012-07-23 18:50       ` [PATCH 2/3] commit: check committer identity more strictly Jeff King
2012-07-23 20:51         ` Junio C Hamano
2012-07-23 20:53           ` Jeff King
2012-07-23 18:52       ` [PATCH 3/3] commit: give a hint when a commit message has been abandoned Jeff King
2012-07-23 20:49         ` Junio C Hamano [this message]
2012-07-23 20:52           ` Jeff King
2012-07-23 21:00             ` Junio C Hamano
2012-07-23 21:13               ` Jeff King
2012-07-23 21:35                 ` Junio C Hamano
2012-07-23 21:43                   ` Jeff King
2012-07-23 22:09                     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vzk6qjj7w.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=ramana@member.fsf.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.