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>
This commit is contained in:
parent
f448e24e2f
commit
fdc7c81111
@ -554,14 +554,18 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
|
|||||||
|
|
||||||
fprintf(fp,
|
fprintf(fp,
|
||||||
"\n"
|
"\n"
|
||||||
"# Please enter the commit message for your changes.\n"
|
"# Please enter the commit message for your changes.");
|
||||||
"# To abort the commit, use an empty commit message.\n"
|
|
||||||
"# (Comment lines starting with '#' will ");
|
|
||||||
if (cleanup_mode == CLEANUP_ALL)
|
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. */
|
else /* CLEANUP_SPACE, that is. */
|
||||||
fprintf(fp, "be kept.\n"
|
fprintf(fp,
|
||||||
"# You can remove them yourself if you want to)\n");
|
" 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)
|
if (only_include_assumed)
|
||||||
fprintf(fp, "# %s\n", only_include_assumed);
|
fprintf(fp, "# %s\n", only_include_assumed);
|
||||||
|
|
||||||
@ -1004,7 +1008,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
|||||||
stripspace(&sb, cleanup_mode == CLEANUP_ALL);
|
stripspace(&sb, cleanup_mode == CLEANUP_ALL);
|
||||||
if (sb.len < header_len || message_is_empty(&sb, header_len)) {
|
if (sb.len < header_len || message_is_empty(&sb, header_len)) {
|
||||||
rollback_index_files();
|
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');
|
strbuf_addch(&sb, '\0');
|
||||||
if (is_encoding_utf8(git_commit_encoding) && !is_utf8(sb.buf))
|
if (is_encoding_utf8(git_commit_encoding) && !is_utf8(sb.buf))
|
||||||
|
@ -141,16 +141,15 @@ test_expect_success 'cleanup commit messages (strip,-F)' '
|
|||||||
|
|
||||||
echo "sample
|
echo "sample
|
||||||
|
|
||||||
# Please enter the commit message for your changes.
|
# Please enter the commit message for your changes. Lines starting
|
||||||
# To abort the commit, use an empty commit message.
|
# with '#' will be ignored, and an empty message aborts the commit." >expect
|
||||||
# (Comment lines starting with '#' will not be included)" >expect
|
|
||||||
|
|
||||||
test_expect_success 'cleanup commit messages (strip,-F,-e)' '
|
test_expect_success 'cleanup commit messages (strip,-F,-e)' '
|
||||||
|
|
||||||
echo >>negative &&
|
echo >>negative &&
|
||||||
{ echo;echo sample;echo; } >text &&
|
{ echo;echo sample;echo; } >text &&
|
||||||
git commit -e -F text -a &&
|
git commit -e -F text -a &&
|
||||||
head -n 5 .git/COMMIT_EDITMSG >actual &&
|
head -n 4 .git/COMMIT_EDITMSG >actual &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
|
|
||||||
'
|
'
|
||||||
@ -163,7 +162,7 @@ test_expect_success 'author different from committer' '
|
|||||||
|
|
||||||
echo >>negative &&
|
echo >>negative &&
|
||||||
git commit -e -m "sample"
|
git commit -e -m "sample"
|
||||||
head -n 8 .git/COMMIT_EDITMSG >actual &&
|
head -n 7 .git/COMMIT_EDITMSG >actual &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
@ -182,7 +181,7 @@ test_expect_success 'committer is automatic' '
|
|||||||
# must fail because there is no change
|
# must fail because there is no change
|
||||||
test_must_fail git commit -e -m "sample"
|
test_must_fail git commit -e -m "sample"
|
||||||
) &&
|
) &&
|
||||||
head -n 9 .git/COMMIT_EDITMSG | \
|
head -n 8 .git/COMMIT_EDITMSG | \
|
||||||
sed "s/^# Committer: .*/# Committer:/" >actual &&
|
sed "s/^# Committer: .*/# Committer:/" >actual &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
Loading…
Reference in New Issue
Block a user