Compact commit template message
We recently let the user know explicitly that an empty commit message will abort the commit. However, this adds yet another line to the template; let's rephrase and re-wrap so that this fits back on two lines. 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. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jul 31, 2008 at 03:36 UTC
fdc7c81111a2ca8d97b8b45e260d7a4e737c8766
2 files changed
+17
-13
builtin-commit.c
+12
-7
@@ -554,14 +554,18 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
554
555
fprintf(fp,
556
"\n"
557
- "# Please enter the commit message for your changes.\n"
558
- "# To abort the commit, use an empty commit message.\n"
559
- "# (Comment lines starting with '#' will ");
557
+ "# Please enter the commit message for your changes.");
558
if (cleanup_mode == CLEANUP_ALL)
561
- fprintf(fp, "not be included)\n");
559
+ fprintf(fp,
560
+ " Lines starting\n"
561
+ "# with '#' will be ignored, and an empty"
562
+ " message aborts the commit.\n");
563
else /* CLEANUP_SPACE, that is. */
563
- fprintf(fp, "be kept.\n"
564
- "# You can remove them yourself if you want to)\n");
564
+ fprintf(fp,
565
+ " Lines starting\n"
566
+ "# with '#' will be kept; you may remove them"
567
+ " yourself if you want to.\n"
568
+ "# An empty message aborts the commit.\n");
569
if (only_include_assumed)
570
fprintf(fp, "# %s\n", only_include_assumed);
571
@@ -1004,7 +1008,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1008
stripspace(&sb, cleanup_mode == CLEANUP_ALL);
1009
if (sb.len < header_len || message_is_empty(&sb, header_len)) {
1010
rollback_index_files();
1007
- die("no commit message? aborting commit.");
1011
+ fprintf(stderr, "Aborting commit due to empty commit message.\n");
1012
+ exit(1);
1013
}
1014
strbuf_addch(&sb, '\0');
1015
if (is_encoding_utf8(git_commit_encoding) && !is_utf8(sb.buf))
t/t7502-commit.sh
+5
-6
@@ -141,16 +141,15 @@ test_expect_success 'cleanup commit messages (strip,-F)' '
141
142
echo "sample
143
144
-# Please enter the commit message for your changes.
145
-# To abort the commit, use an empty commit message.
146
-# (Comment lines starting with '#' will not be included)" >expect
144
+# Please enter the commit message for your changes. Lines starting
145
+# with '#' will be ignored, and an empty message aborts the commit." >expect
146
147
test_expect_success 'cleanup commit messages (strip,-F,-e)' '
148
149
echo >>negative &&
150
{ echo;echo sample;echo; } >text &&
151
git commit -e -F text -a &&
153
- head -n 5 .git/COMMIT_EDITMSG >actual &&
152
+ head -n 4 .git/COMMIT_EDITMSG >actual &&
153
test_cmp expect actual
154
155
'
@@ -163,7 +162,7 @@ test_expect_success 'author different from committer' '
162
163
echo >>negative &&
164
git commit -e -m "sample"
166
- head -n 8 .git/COMMIT_EDITMSG >actual &&
165
+ head -n 7 .git/COMMIT_EDITMSG >actual &&
166
test_cmp expect actual
167
'
168
@@ -182,7 +181,7 @@ test_expect_success 'committer is automatic' '
181
# must fail because there is no change
182
test_must_fail git commit -e -m "sample"
183
) &&
185
- head -n 9 .git/COMMIT_EDITMSG | \
184
+ head -n 8 .git/COMMIT_EDITMSG | \
185
sed "s/^# Committer: .*/# Committer:/" >actual &&
186
test_cmp expect actual
187
'