@@ -31,52 +31,70 @@ test_expect_success 'nonexistent template file should return error' '
3131 echo changes >> foo &&
3232 git add foo &&
3333 (
34- GIT_EDITOR="echo hello >\"\$1\" " &&
34+ GIT_EDITOR="echo hello >" &&
3535 export GIT_EDITOR &&
3636 test_must_fail git commit --template "$PWD"/notexist
3737 )
3838'
3939
40+ test_expect_success ' nonexistent optional template file on command line' '
41+ echo changes >> foo &&
42+ git add foo &&
43+ (
44+ GIT_EDITOR="echo hello >\"\$1\"" &&
45+ export GIT_EDITOR &&
46+ git commit --template ":(optional)$PWD/notexist"
47+ )
48+ '
49+
4050test_expect_success ' nonexistent template file in config should return error' '
4151 test_config commit.template "$PWD"/notexist &&
4252 (
43- GIT_EDITOR="echo hello >\"\$1\" " &&
53+ GIT_EDITOR="echo hello >" &&
4454 export GIT_EDITOR &&
45- test_must_fail git commit
55+ test_must_fail git commit --allow-empty
4656 )
4757'
4858
59+ test_expect_success ' nonexistent optional template file in config' '
60+ test_config commit.template ":(optional)$PWD"/notexist &&
61+ GIT_EDITOR="echo hello >" git commit --allow-empty &&
62+ git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
63+ echo hello >expect &&
64+ test_cmp expect actual
65+ '
66+
4967# From now on we'll use a template file that exists.
5068TEMPLATE=" $PWD " /template
5169
5270test_expect_success ' unedited template should not commit' '
53- echo "template line" > "$TEMPLATE" &&
54- test_must_fail git commit --template "$TEMPLATE"
71+ echo "template line" >"$TEMPLATE" &&
72+ test_must_fail git commit --allow-empty -- template "$TEMPLATE"
5573'
5674
5775test_expect_success ' unedited template with comments should not commit' '
58- echo "# comment in template" >> "$TEMPLATE" &&
59- test_must_fail git commit --template "$TEMPLATE"
76+ echo "# comment in template" >>"$TEMPLATE" &&
77+ test_must_fail git commit --allow-empty -- template "$TEMPLATE"
6078'
6179
6280test_expect_success ' a Signed-off-by line by itself should not commit' '
6381 (
6482 test_set_editor "$TEST_DIRECTORY"/t7500/add-signed-off &&
65- test_must_fail git commit --template "$TEMPLATE"
83+ test_must_fail git commit --allow-empty -- template "$TEMPLATE"
6684 )
6785'
6886
6987test_expect_success ' adding comments to a template should not commit' '
7088 (
7189 test_set_editor "$TEST_DIRECTORY"/t7500/add-comments &&
72- test_must_fail git commit --template "$TEMPLATE"
90+ test_must_fail git commit --allow-empty -- template "$TEMPLATE"
7391 )
7492'
7593
7694test_expect_success ' adding real content to a template should commit' '
7795 (
7896 test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
79- git commit --template "$TEMPLATE"
97+ git commit --allow-empty -- template "$TEMPLATE"
8098 ) &&
8199 commit_msg_is "template linecommit message"
82100'
0 commit comments