]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit: give advice on empty amend
authorJeff King <peff@peff.net>
Mon, 7 Jun 2010 00:41:46 +0000 (20:41 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 11 Jun 2010 15:55:57 +0000 (08:55 -0700)
We generally disallow empty commits with "git commit". The
output produced by the wt_status functions is generally
sufficient to explain what happened.

With --amend commits, however, things are a little more
confusing. We would create an empty commit not if you
actually have staged changes _now_, but if your staged
changes match HEAD^. In this case, it is not immediately
obvious why "git commit" claims no changes, but "git status"
does not. Furthermore, we should point the user in the
direction of git reset, which would eliminate the empty
commit entirely.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit.c

index c5ab683d5b66d5ad85f53d13d6df71e29cd9234d..216ecc91d18457aad91156bde46dfe669dbb828b 100644 (file)
@@ -48,6 +48,11 @@ static const char implicit_ident_advice[] =
 "\n"
 "    git commit --amend --author='Your Name <you@example.com>'\n";
 
+static const char empty_amend_advice[] =
+"You asked to amend the most recent commit, but doing so would make\n"
+"it empty. You can repeat your command with --allow-empty, or you can\n"
+"remove the commit entirely with \"git reset HEAD^\".\n";
+
 static unsigned char head_sha1[20];
 
 static char *use_message_buffer;
@@ -693,6 +698,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        if (!commitable && !in_merge && !allow_empty &&
            !(amend && is_a_merge(head_sha1))) {
                run_status(stdout, index_file, prefix, 0, s);
+               if (amend)
+                       fputs(empty_amend_advice, stderr);
                return 0;
        }