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>
Ævar Arnfjörð Bjarmason committed
Apr 6, 2010 at 08:40 UTC
c9b5fde7593ac88b1c475bea51d21ba1a1d57d65
3 files changed
+38
-4
Documentation/git-commit.txt
+7
-1
@@ -10,7 +10,7 @@ SYNOPSIS
10
[verse]
11
'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
12
[(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
13
- [--allow-empty] [--no-verify] [-e] [--author=<author>]
13
+ [--allow-empty] [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
14
[--date=<date>] [--cleanup=<mode>] [--status | --no-status] [--]
15
[[-i | -o ]<file>...]
16
@@ -131,6 +131,12 @@ OPTIONS
131
from making such a commit. This option bypasses the safety, and
132
is primarily for use by foreign scm interface scripts.
133
134
+--allow-empty-message::
135
+ Like --allow-empty this command is primarily for use by foreign
136
+ scm interface scripts. It allows you to create a commit with an
137
+ empty commit message without using plumbing commands like
138
+ linkgit:git-commit-tree[1].
139
+
140
--cleanup=<mode>::
141
This option sets how the commit message is cleaned up.
142
The '<mode>' can be one of 'verbatim', 'whitespace', 'strip',
builtin/commit.c
+9
-3
@@ -66,7 +66,7 @@ static char *edit_message, *use_message;
66
static char *author_name, *author_email, *author_date;
67
static int all, edit_flag, also, interactive, only, amend, signoff;
68
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
69
-static int no_post_rewrite;
69
+static int no_post_rewrite, allow_empty_message;
70
static char *untracked_files_arg, *force_date;
71
/*
72
* The default commit message cleanup mode will remove the lines
@@ -140,9 +140,15 @@ static struct option builtin_commit_options[] = {
140
OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
141
OPT_BOOLEAN(0, "no-post-rewrite", &no_post_rewrite, "bypass post-rewrite hook"),
142
{ 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" },
143
- OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
143
/* end commit contents options */
144
145
+ { OPTION_BOOLEAN, 0, "allow-empty", &allow_empty, NULL,
146
+ "ok to record an empty change",
147
+ PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
148
+ { OPTION_BOOLEAN, 0, "allow-empty-message", &allow_empty_message, NULL,
149
+ "ok to record a change with an empty message",
150
+ PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
151
+
152
OPT_END()
153
};
154
@@ -1293,7 +1299,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1299
1300
if (cleanup_mode != CLEANUP_NONE)
1301
stripspace(&sb, cleanup_mode == CLEANUP_ALL);
1296
- if (message_is_empty(&sb)) {
1302
+ if (message_is_empty(&sb) && !allow_empty_message) {
1303
rollback_index_files();
1304
fprintf(stderr, "Aborting commit due to empty commit message.\n");
1305
exit(1);
t/t7500-commit.sh
+22
@@ -193,4 +193,26 @@ test_expect_success 'commit -F overrides -t' '
193
commit_msg_is "-F log"
194
'
195
196
+test_expect_success 'Commit without message is allowed with --allow-empty-message' '
197
+ echo "more content" >>foo &&
198
+ git add foo &&
199
+ >empty &&
200
+ git commit --allow-empty-message <empty &&
201
+ commit_msg_is ""
202
+'
203
+
204
+test_expect_success 'Commit without message is no-no without --allow-empty-message' '
205
+ echo "more content" >>foo &&
206
+ git add foo &&
207
+ >empty &&
208
+ test_must_fail git commit <empty
209
+'
210
+
211
+test_expect_success 'Commit a message with --allow-empty-message' '
212
+ echo "even more content" >>foo &&
213
+ git add foo &&
214
+ git commit --allow-empty-message -m"hello there" &&
215
+ commit_msg_is "hello there"
216
+'
217
+
218
test_done