]> Pileus Git - ~andy/git/commitdiff
commit: error out for missing commit message template
authorJonathan Nieder <jrnieder@gmail.com>
Fri, 25 Feb 2011 09:07:57 +0000 (03:07 -0600)
committerJunio C Hamano <gitster@pobox.com>
Fri, 25 Feb 2011 20:13:55 +0000 (12:13 -0800)
When "git commit" was rewritten in C (v1.5.4-rc0~78^2~30,
2007-11-08), a subtle bug in --template was introduced.  If the
file named by a --template parameter is missing, previously git
would error out with a message:

Commit template file does not exist.

but in the C version the --template parameter gets ignored and
the default template is used.

t7500 has two tests for this case which would have caught it, except
that with the default $EDITOR, the commit message template is left
unmodified, causing 'git commit' to error out and the test to
succeed.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit.c
t/t7500-commit.sh

index 6e2f12accc82b02863736a10ae5c107717f96a96..cc16e3f292403814e137078fd46927eeaecf0d36 100644 (file)
@@ -602,7 +602,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0)
                        die_errno("could not read SQUASH_MSG");
                hook_arg1 = "squash";
-       } else if (template_file && !stat(template_file, &statbuf)) {
+       } else if (template_file) {
                if (strbuf_read_file(&sb, template_file, 0) < 0)
                        die_errno("could not read '%s'", template_file);
                hook_arg1 = "template";
index aa9c577e9e306bce05cd0fe076c56017c1b97e41..1590877c425c4ae4b884770ca812de7f1a5f359f 100755 (executable)
@@ -23,13 +23,21 @@ test_expect_success 'a basic commit in an empty tree should succeed' '
 test_expect_success 'nonexistent template file should return error' '
        echo changes >> foo &&
        git add foo &&
-       test_must_fail git commit --template "$PWD"/notexist
+       (
+               GIT_EDITOR="echo hello >\"\$1\"" &&
+               export GIT_EDITOR &&
+               test_must_fail git commit --template "$PWD"/notexist
+       )
 '
 
 test_expect_success 'nonexistent template file in config should return error' '
        git config commit.template "$PWD"/notexist &&
-       test_must_fail git commit &&
-       git config --unset commit.template
+       test_when_finished "git config --unset commit.template" &&
+       (
+               GIT_EDITOR="echo hello >\"\$1\"" &&
+               export GIT_EDITOR &&
+               test_must_fail git commit
+       )
 '
 
 # From now on we'll use a template file that exists.