@matheusbsbs / matheus-bagliano / commits / 2140b14064
Fork 0

commit: error out for missing commit message template

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>

Jonathan Nieder committed Feb 25, 2011 at 03:07 UTC 2140b14064ffe6b12ba6818b2894d1461a943fb9
2 files changed +12 -4
builtin/commit.c
+1 -1
@@ -602,7 +602,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
602 if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0)
603 die_errno("could not read SQUASH_MSG");
604 hook_arg1 = "squash";
605 - } else if (template_file && !stat(template_file, &statbuf)) {
605 + } else if (template_file) {
606 if (strbuf_read_file(&sb, template_file, 0) < 0)
607 die_errno("could not read '%s'", template_file);
608 hook_arg1 = "template";
t/t7500-commit.sh
+11 -3
@@ -23,13 +23,21 @@ test_expect_success 'a basic commit in an empty tree should succeed' '
23 test_expect_success 'nonexistent template file should return error' '
24 echo changes >> foo &&
25 git add foo &&
26 - test_must_fail git commit --template "$PWD"/notexist
26 + (
27 + GIT_EDITOR="echo hello >\"\$1\"" &&
28 + export GIT_EDITOR &&
29 + test_must_fail git commit --template "$PWD"/notexist
30 + )
31 '
32
33 test_expect_success 'nonexistent template file in config should return error' '
34 git config commit.template "$PWD"/notexist &&
31 - test_must_fail git commit &&
32 - git config --unset commit.template
35 + test_when_finished "git config --unset commit.template" &&
36 + (
37 + GIT_EDITOR="echo hello >\"\$1\"" &&
38 + export GIT_EDITOR &&
39 + test_must_fail git commit
40 + )
41 '
42
43 # From now on we'll use a template file that exists.