git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2] Remove --allow-empty from the git-commit synopsis
Date: Wed, 07 Apr 2010 15:25:36 -0700	[thread overview]
Message-ID: <7vbpduc333.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <7vfx37cckf.fsf@alter.siamese.dyndns.org> (Junio C. Hamano's message of "Wed\, 07 Apr 2010 12\:00\:48 -0700")

Junio C Hamano <gitster@pobox.com> writes:

> I do not think Jeff was against having a complete listing in the
> documentation.  Wasn't his suggestion about "git commit -h" output?

I'll amend the earlier "allow-empty-message" one from you to cover this
topic.

-- >8 --
From: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date: Tue, 6 Apr 2010 08:40:35 +0000
Subject: [PATCH] Add option to git-commit to allow empty log messages

Change git-commit(1) to accept the --allow-empty-message option
to allow a commit with an empty message.  This is analogous to the
existing --allow-empty option which allows a commit that records
no changes.  As these are mainly for interoperating with foreign SCM
systems, and are not meant for normal use, ensure that "git commit -h"
does not talk about them.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/git-commit.txt |    8 +++++++-
 builtin/commit.c             |   12 +++++++++---
 t/t7500-commit.sh            |   22 ++++++++++++++++++++++
 3 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 64fb458..32c482f 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 [verse]
 'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
 	   [(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
-	   [--allow-empty] [--no-verify] [-e] [--author=<author>]
+	   [--allow-empty] [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
 	   [--date=<date>] [--cleanup=<mode>] [--status | --no-status] [--]
 	   [[-i | -o ]<file>...]
 
@@ -131,6 +131,12 @@ OPTIONS
 	from making such a commit.  This option bypasses the safety, and
 	is primarily for use by foreign scm interface scripts.
 
+--allow-empty-message::
+       Like --allow-empty this command is primarily for use by foreign
+       scm interface scripts. It allows you to create a commit with an
+       empty commit message without using plumbing commands like
+       linkgit:git-commit-tree[1].
+
 --cleanup=<mode>::
 	This option sets how the commit message is cleaned up.
 	The  '<mode>' can be one of 'verbatim', 'whitespace', 'strip',
diff --git a/builtin/commit.c b/builtin/commit.c
index c5ab683..821a49d 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -66,7 +66,7 @@ static char *edit_message, *use_message;
 static char *author_name, *author_email, *author_date;
 static int all, edit_flag, also, interactive, only, amend, signoff;
 static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
-static int no_post_rewrite;
+static int no_post_rewrite, allow_empty_message;
 static char *untracked_files_arg, *force_date;
 /*
  * The default commit message cleanup mode will remove the lines
@@ -140,9 +140,15 @@ static struct option builtin_commit_options[] = {
 	OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
 	OPT_BOOLEAN(0, "no-post-rewrite", &no_post_rewrite, "bypass post-rewrite hook"),
 	{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
-	OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
 	/* end commit contents options */
 
+	{ OPTION_BOOLEAN, 0, "allow-empty", &allow_empty, NULL,
+	  "ok to record an empty change",
+	  PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
+	{ OPTION_BOOLEAN, 0, "allow-empty-message", &allow_empty_message, NULL,
+	  "ok to record a change with an empty message",
+	  PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
+
 	OPT_END()
 };
 
@@ -1293,7 +1299,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 
 	if (cleanup_mode != CLEANUP_NONE)
 		stripspace(&sb, cleanup_mode == CLEANUP_ALL);
-	if (message_is_empty(&sb)) {
+	if (message_is_empty(&sb) && !allow_empty_message) {
 		rollback_index_files();
 		fprintf(stderr, "Aborting commit due to empty commit message.\n");
 		exit(1);
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index 9f5c3ed..aa9c577 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -193,4 +193,26 @@ test_expect_success 'commit -F overrides -t' '
 	commit_msg_is "-F log"
 '
 
+test_expect_success 'Commit without message is allowed with --allow-empty-message' '
+	echo "more content" >>foo &&
+	git add foo &&
+	>empty &&
+	git commit --allow-empty-message <empty &&
+	commit_msg_is ""
+'
+
+test_expect_success 'Commit without message is no-no without --allow-empty-message' '
+	echo "more content" >>foo &&
+	git add foo &&
+	>empty &&
+	test_must_fail git commit <empty
+'
+
+test_expect_success 'Commit a message with --allow-empty-message' '
+	echo "even more content" >>foo &&
+	git add foo &&
+	git commit --allow-empty-message -m"hello there" &&
+	commit_msg_is "hello there"
+'
+
 test_done
-- 
1.7.1.rc0.212.gbd88f

  parent reply	other threads:[~2010-04-07 22:26 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-03 22:06 Does Git really need a commit message to go with a commit? Ævar Arnfjörð Bjarmason
2010-04-04  1:58 ` Avery Pennarun
     [not found] ` <p2kadf1fd3d1004031526r3beff4e3ldd977dfc7e9da782@mail.gmail.com>
     [not found]   ` <h2m51dd1af81004040415xc7381f6cp1bf81bcfd684b99d@mail.gmail.com>
2010-04-04 12:37     ` Santi Béjar
2010-04-04 14:49 ` [PATCH] Add option to git-commit to allow empty log messages Ævar Arnfjörð Bjarmason
2010-04-04 22:43   ` David Aguilar
2010-04-04 23:53     ` Ævar Arnfjörð Bjarmason
2010-04-05  2:11       ` Junio C Hamano
2010-04-05  2:15         ` Sverre Rabbelier
2010-04-05  3:57           ` Junio C Hamano
2010-04-05 14:46             ` Sverre Rabbelier
2010-04-05  5:10         ` Miles Bader
2010-04-05  5:27           ` Junio C Hamano
2010-04-05  5:51           ` Jeff King
2010-04-05 12:50             ` Ævar Arnfjörð Bjarmason
2010-04-05 17:58               ` Jonathan Nieder
2010-04-05 18:11                 ` Jonathan Nieder
2010-04-06  5:55                 ` Jeff King
2010-04-06  8:40                   ` [PATCH v2] " Ævar Arnfjörð Bjarmason
2010-04-07  5:16                     ` Junio C Hamano
2010-04-07 14:28                       ` Ævar Arnfjörð Bjarmason
2010-04-06  8:42                   ` [PATCH] " Ævar Arnfjörð Bjarmason
2010-04-07 15:09                     ` [PATCH] Remove --allow-empty from the git-commit synopsis Ævar Arnfjörð Bjarmason
2010-04-07 15:29                       ` Sverre Rabbelier
2010-04-07 17:28                         ` [PATCH v2] " Ævar Arnfjörð Bjarmason
2010-04-07 17:52                           ` Sverre Rabbelier
2010-04-07 18:17                             ` Ævar Arnfjörð Bjarmason
2010-04-07 18:21                           ` Tay Ray Chuan
2010-04-07 18:48                             ` [PATCH v3] " Ævar Arnfjörð Bjarmason
2010-04-07 18:55                           ` [PATCH v2] " Johannes Sixt
2010-04-07 19:00                           ` Junio C Hamano
2010-04-07 19:28                             ` [PATCH v4] " Ævar Arnfjörð Bjarmason
2010-04-07 19:45                               ` Stephen Boyd
2010-04-07 22:25                             ` Junio C Hamano [this message]
2010-04-08  6:44                               ` [PATCH v2] " Jeff King
2010-04-06  5:43               ` [PATCH] Add option to git-commit to allow empty log messages Jeff King

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=7vbpduc333.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).