@@ -31,52 +31,70 @@ test_expect_success 'nonexistent template file should return error' '
31
31
echo changes >> foo &&
32
32
git add foo &&
33
33
(
34
- GIT_EDITOR="echo hello >\"\$1\" " &&
34
+ GIT_EDITOR="echo hello >" &&
35
35
export GIT_EDITOR &&
36
36
test_must_fail git commit --template "$PWD"/notexist
37
37
)
38
38
'
39
39
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
+
40
50
test_expect_success ' nonexistent template file in config should return error' '
41
51
test_config commit.template "$PWD"/notexist &&
42
52
(
43
- GIT_EDITOR="echo hello >\"\$1\" " &&
53
+ GIT_EDITOR="echo hello >" &&
44
54
export GIT_EDITOR &&
45
- test_must_fail git commit
55
+ test_must_fail git commit --allow-empty
46
56
)
47
57
'
48
58
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
+
49
67
# From now on we'll use a template file that exists.
50
68
TEMPLATE=" $PWD " /template
51
69
52
70
test_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"
55
73
'
56
74
57
75
test_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"
60
78
'
61
79
62
80
test_expect_success ' a Signed-off-by line by itself should not commit' '
63
81
(
64
82
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"
66
84
)
67
85
'
68
86
69
87
test_expect_success ' adding comments to a template should not commit' '
70
88
(
71
89
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"
73
91
)
74
92
'
75
93
76
94
test_expect_success ' adding real content to a template should commit' '
77
95
(
78
96
test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
79
- git commit --template "$TEMPLATE"
97
+ git commit --allow-empty -- template "$TEMPLATE"
80
98
) &&
81
99
commit_msg_is "template linecommit message"
82
100
'
0 commit comments