Do not strip empty lines / trailing spaces from a commit message template

Templates should be just that: A form that the user fills out, and forms have blanks. If people are attached to not having extra whitespace in the editor, they can simply clean up their templates. Added test with editor adding even more whitespace. Signed-off-by: Boris Faure <billiob@gmail.com> Based-on-patch-by:Sebastian Schuberth <sschuberth@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Boris Faure committed May 8, 2011 at 12:31 UTC 8b1ae678a33e2d1ccf3080977b692a59acad9b50
3 files changed +25 -1
builtin/commit.c
+3 -1
@@ -615,6 +615,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
615 const char *hook_arg1 = NULL;
616 const char *hook_arg2 = NULL;
617 int ident_shown = 0;
618 + int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
619
620 if (!no_verify && run_hook(index_file, "pre-commit", NULL))
621 return 0;
@@ -681,6 +682,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
682 if (strbuf_read_file(&sb, template_file, 0) < 0)
683 die_errno(_("could not read '%s'"), template_file);
684 hook_arg1 = "template";
685 + clean_message_contents = 0;
686 }
687
688 /*
@@ -708,7 +710,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
710 if (s->fp == NULL)
711 die_errno(_("could not open '%s'"), git_path(commit_editmsg));
712
711 - if (cleanup_mode != CLEANUP_NONE)
713 + if (clean_message_contents)
714 stripspace(&sb, 0);
715
716 if (signoff) {
t/t7500-commit.sh
+14
@@ -123,6 +123,20 @@ test_expect_success 'commit message from file should override template' '
123 commit_msg_is "standard input msg"
124 '
125
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 +
140 test_expect_success 'using alternate GIT_INDEX_FILE (1)' '
141
142 cp .git/index saved-index &&
t/t7500/add-whitespaced-content new
+8
@@ -0,0 +1,8 @@
1 +#!/bin/sh
2 +sed -e 's/|$//' >>"$1" <<\EOF
3 +
4 + |
5 +commit message |
6 +
7 +EOF
8 +exit 0