Skip to content

Commit fdc7c81

Browse files
peffgitster
authored andcommitted
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>
1 parent f448e24 commit fdc7c81

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

builtin-commit.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -554,14 +554,18 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
554554

555555
fprintf(fp,
556556
"\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.");
560558
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");
562563
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");
565569
if (only_include_assumed)
566570
fprintf(fp, "# %s\n", only_include_assumed);
567571

@@ -1004,7 +1008,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
10041008
stripspace(&sb, cleanup_mode == CLEANUP_ALL);
10051009
if (sb.len < header_len || message_is_empty(&sb, header_len)) {
10061010
rollback_index_files();
1007-
die("no commit message? aborting commit.");
1011+
fprintf(stderr, "Aborting commit due to empty commit message.\n");
1012+
exit(1);
10081013
}
10091014
strbuf_addch(&sb, '\0');
10101015
if (is_encoding_utf8(git_commit_encoding) && !is_utf8(sb.buf))

t/t7502-commit.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,15 @@ test_expect_success 'cleanup commit messages (strip,-F)' '
141141

142142
echo "sample
143143
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
147146

148147
test_expect_success 'cleanup commit messages (strip,-F,-e)' '
149148
150149
echo >>negative &&
151150
{ echo;echo sample;echo; } >text &&
152151
git commit -e -F text -a &&
153-
head -n 5 .git/COMMIT_EDITMSG >actual &&
152+
head -n 4 .git/COMMIT_EDITMSG >actual &&
154153
test_cmp expect actual
155154
156155
'
@@ -163,7 +162,7 @@ test_expect_success 'author different from committer' '
163162
164163
echo >>negative &&
165164
git commit -e -m "sample"
166-
head -n 8 .git/COMMIT_EDITMSG >actual &&
165+
head -n 7 .git/COMMIT_EDITMSG >actual &&
167166
test_cmp expect actual
168167
'
169168

@@ -182,7 +181,7 @@ test_expect_success 'committer is automatic' '
182181
# must fail because there is no change
183182
test_must_fail git commit -e -m "sample"
184183
) &&
185-
head -n 9 .git/COMMIT_EDITMSG | \
184+
head -n 8 .git/COMMIT_EDITMSG | \
186185
sed "s/^# Committer: .*/# Committer:/" >actual &&
187186
test_cmp expect actual
188187
'

0 commit comments

Comments
 (0)