git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Advertise the ability to abort a commit

From
Jeff King <peff@peff.net>
Date
Jul 31, 2008, 06:36 UTC
Message-ID
<20080731063619.GA28345@sigill.intra.peff.net>
In-Reply-To
<7vwsj23896.fsf@gitster.siamese.dyndns.org>
From: Anders Melchiorsen <mail@cup.kalibalik.dk>

We explicitly let the user know that an empty commit message will abort the commit. At the same time, we take the opportunity to reword the template text a bit to keep it more compact.

This patch also makes the "fatal: empty commit message?" warning a bit less scary, since this is now a "feature" instead of an error. However, we retain the non-zero exit status to indicate to callers that nothing was committed.

[jk: I compacted the text and expanded the commit message from Anders' original patch]

Signed-off-by: Anders Melchiorsen <mail@cup.kalibalik.dk>
Signed-off-by: Jeff King <peff@peff.net>
---
 builtin-commit.c  |   18 ++++++++++++------
 t/t7502-commit.sh |    4 ++--
 2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index 9a11ca0..b783e6e 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -554,13 +554,18 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
 
 		fprintf(fp,
 			"\n"
-			"# Please enter the commit message for your changes.\n"
-			"# (Comment lines starting with '#' will ");
+			"# Please enter the commit message for your changes.");
 		if (cleanup_mode == CLEANUP_ALL)
-			fprintf(fp, "not be included)\n");
+			fprintf(fp,
+				" Lines starting\n"
+				"# with '#' will be ignored, and an empty"
+				" message aborts the commit.\n");
 		else /* CLEANUP_SPACE, that is. */
-			fprintf(fp, "be kept.\n"
-				"# You can remove them yourself if you want to)\n");
+			fprintf(fp,
+				" Lines starting\n"
+				"# with '#' will be kept; you may remove them"
+				" yourself if you want to.\n"
+				"# An empty message aborts the commit.\n");
 		if (only_include_assumed)
 			fprintf(fp, "# %s\n", only_include_assumed);
 
@@ -1003,7 +1008,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		stripspace(&sb, cleanup_mode == CLEANUP_ALL);
 	if (sb.len < header_len || message_is_empty(&sb, header_len)) {
 		rollback_index_files();
-		die("no commit message?  aborting commit.");
+		fprintf(stderr, "Aborting commit due to empty commit message.\n");
+		exit(1);
 	}
 	strbuf_addch(&sb, '\0');
 	if (is_encoding_utf8(git_commit_encoding) && !is_utf8(sb.buf))
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index 4f2682e..3eb9fae 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -141,8 +141,8 @@ test_expect_success 'cleanup commit messages (strip,-F)' '
 
 echo "sample
 
-# Please enter the commit message for your changes.
-# (Comment lines starting with '#' will not be included)" >expect
+# Please enter the commit message for your changes. Lines starting
+# with '#' will be ignored, and an empty message aborts the commit." >expect
 
 test_expect_success 'cleanup commit messages (strip,-F,-e)' '
 
-- 
1.6.0.rc1.168.g8c00d.dirty
Previous: Junio C HamanoNext: Jeff King
Message 14 of 19 in “Advertise the ability to abort a commit”
  1. Advertise the ability to abort a commitAnders Melchiorsen, Jul 29, 2008
  2. Advertise the ability to abort a commitAnders Melchiorsen, Jul 29, 2008
  3. Junio C HamanoJul 29, 2008
  4. Anders MelchiorsenJul 29, 2008
  5. Jeff KingJul 30, 2008
  6. Jeff KingJul 30, 2008
  7. Advertise the ability to abort a commitAnders Melchiorsen, Jul 30, 2008
  8. Brian GernhardtJul 30, 2008
  9. Avery PennarunJul 30, 2008
  10. Brian GernhardtJul 30, 2008
  11. Anders MelchiorsenJul 30, 2008
  12. Jeff KingJul 31, 2008
  13. Junio C HamanoJul 31, 2008
  14. Advertise the ability to abort a commitJeff King, Jul 31, 2008
  15. Jeff KingJul 31, 2008
  16. Petr BaudisJul 31, 2008
  17. Jeff KingJul 31, 2008
  18. Anders MelchiorsenJul 31, 2008
  19. Jeff KingJul 31, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.