Skip to content

Commit e4ae6ef

Browse files
committed
Merge branch 'bf/commit-template-no-cleanup'
* bf/commit-template-no-cleanup: Do not strip empty lines / trailing spaces from a commit message template
2 parents d6ad4ff + 8b1ae67 commit e4ae6ef

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

builtin/commit.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
615615
const char *hook_arg1 = NULL;
616616
const char *hook_arg2 = NULL;
617617
int ident_shown = 0;
618+
int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
618619

619620
if (!no_verify && run_hook(index_file, "pre-commit", NULL))
620621
return 0;
@@ -681,6 +682,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
681682
if (strbuf_read_file(&sb, template_file, 0) < 0)
682683
die_errno(_("could not read '%s'"), template_file);
683684
hook_arg1 = "template";
685+
clean_message_contents = 0;
684686
}
685687

686688
/*
@@ -708,7 +710,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
708710
if (s->fp == NULL)
709711
die_errno(_("could not open '%s'"), git_path(commit_editmsg));
710712

711-
if (cleanup_mode != CLEANUP_NONE)
713+
if (clean_message_contents)
712714
stripspace(&sb, 0);
713715

714716
if (signoff) {

t/t7500-commit.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ test_expect_success 'commit message from file should override template' '
123123
commit_msg_is "standard input msg"
124124
'
125125

126+
cat >"$TEMPLATE" <<\EOF
127+
128+
129+
### template
130+
131+
EOF
132+
test_expect_success 'commit message from template with whitespace issue' '
133+
echo "content galore" >>foo &&
134+
git add foo &&
135+
GIT_EDITOR="$TEST_DIRECTORY"/t7500/add-whitespaced-content git commit \
136+
--template "$TEMPLATE" &&
137+
commit_msg_is "commit message"
138+
'
139+
126140
test_expect_success 'using alternate GIT_INDEX_FILE (1)' '
127141
128142
cp .git/index saved-index &&

t/t7500/add-whitespaced-content

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
sed -e 's/|$//' >>"$1" <<\EOF
3+
4+
|
5+
commit message |
6+
7+
EOF
8+
exit 0

0 commit comments

Comments
 (0)