{"thread":{"id":"25501","subject":"[PATCH] commit: give advice on empty amend","startedAt":"2010-10-21T15:08:36Z","lastAt":"2010-10-21T15:14:14Z","messageCount":2,"participants":["Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"153970","messageId":"20101021150836.GA18535@sigill.intra.peff.net","threadId":"25501","inReplyTo":null,"subject":"[PATCH] commit: give advice on empty amend","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-10-21T15:08:36Z","receivedAt":"2010-10-21T15:08:36Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"We generally disallow empty commits with \"git commit\". The\noutput produced by the wt_status functions is generally\nsufficient to explain what happened.\n\nWith --amend commits, however, things are a little more\nconfusing. We would create an empty commit not if you\nactually have staged changes _now_, but if your staged\nchanges match HEAD^. In this case, it is not immediately\nobvious why \"git commit\" claims no changes, but \"git status\"\ndoes not. Furthermore, we should point the user in the\ndirection of git reset, which would eliminate the empty\ncommit entirely.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nAnother re-post from my fall cleaning. I have many more, but I'll make\nthis the last for today.\n\nOriginal discussion here:\n\n  http://thread.gmane.org/gmane.comp.version-control.git/147980/focus=148521\n\nThere were no objections; I think it simply got overlooked.\n\n builtin/commit.c |    7 +++++++\n 1 files changed, 7 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex ddf77e4..2a106a1 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -48,6 +48,11 @@ static const char implicit_ident_advice[] =\n \"\\n\"\n \"    git commit --amend --author='Your Name <you@example.com>'\\n\";\n \n+static const char empty_amend_advice[] =\n+\"You asked to amend the most recent commit, but doing so would make\\n\"\n+\"it empty. You can repeat your command with --allow-empty, or you can\\n\"\n+\"remove the commit entirely with \\\"git reset HEAD^\\\".\\n\";\n+\n static unsigned char head_sha1[20];\n \n static char *use_message_buffer;\n@@ -700,6 +705,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \tif (!commitable && !in_merge && !allow_empty &&\n \t    !(amend && is_a_merge(head_sha1))) {\n \t\trun_status(stdout, index_file, prefix, 0, s);\n+\t\tif (amend)\n+\t\t\tfputs(empty_amend_advice, stderr);\n \t\treturn 0;\n \t}\n \n-- \n1.7.3.1.235.gdd6c0\n"},{"id":"153971","messageId":"20101021151414.GA21325@sigill.intra.peff.net","threadId":"25501","inReplyTo":"20101021150836.GA18535@sigill.intra.peff.net","subject":"Re: [PATCH] commit: give advice on empty amend","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-10-21T15:14:14Z","receivedAt":"2010-10-21T15:14:14Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Oct 21, 2010 at 11:08:36AM -0400, Jeff King wrote:\n\n> Another re-post from my fall cleaning. I have many more, but I'll make\n> this the last for today.\n\nArgh, sorry, this one actually did get merged. I'm just incompetent at\nusing git. :)\n\nSorry for the noise.\n\n-Peff\n"}]}