Merge branch 'bf/commit-template-no-cleanup'
authorJunio C Hamano <gitster@pobox.com>
Fri, 13 May 2011 18:03:08 +0000 (11:03 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 13 May 2011 18:03:08 +0000 (11:03 -0700)
* bf/commit-template-no-cleanup:
Do not strip empty lines / trailing spaces from a commit message template

builtin/commit.c
t/t7500-commit.sh
t/t7500/add-whitespaced-content [new file with mode: 0755]
index 67757e999fba514b62767d3351031e9eb6ef8c10..411d5e41531adabe679df2d1381dbf923c5e925b 100644 (file)
@@ -615,6 +615,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        const char *hook_arg1 = NULL;
        const char *hook_arg2 = NULL;
        int ident_shown = 0;
+       int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
 
        if (!no_verify && run_hook(index_file, "pre-commit", NULL))
                return 0;
@@ -681,6 +682,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                if (strbuf_read_file(&sb, template_file, 0) < 0)
                        die_errno(_("could not read '%s'"), template_file);
                hook_arg1 = "template";
+               clean_message_contents = 0;
        }
 
        /*
@@ -708,7 +710,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
        if (s->fp == NULL)
                die_errno(_("could not open '%s'"), git_path(commit_editmsg));
 
-       if (cleanup_mode != CLEANUP_NONE)
+       if (clean_message_contents)
                stripspace(&sb, 0);
 
        if (signoff) {
index 47096f9014a0f36251eeb643ea302555e9ddc4d5..1c908f4d3966cb9a2769465652981bef831f312d 100755 (executable)
@@ -123,6 +123,20 @@ test_expect_success 'commit message from file should override template' '
        commit_msg_is "standard input msg"
 '
 
+cat >"$TEMPLATE" <<\EOF
+
+
+### template
+
+EOF
+test_expect_success 'commit message from template with whitespace issue' '
+       echo "content galore" >>foo &&
+       git add foo &&
+       GIT_EDITOR="$TEST_DIRECTORY"/t7500/add-whitespaced-content git commit \
+               --template "$TEMPLATE" &&
+       commit_msg_is "commit message"
+'
+
 test_expect_success 'using alternate GIT_INDEX_FILE (1)' '
 
        cp .git/index saved-index &&
diff --git a/t/t7500/add-whitespaced-content b/t/t7500/add-whitespaced-content
new file mode 100755 (executable)
index 0000000..ccf07c6
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+sed -e 's/|$//' >>"$1" <<\EOF
+
+ |
+commit message          |
+
+EOF
+exit 0