Skip to content

Commit afb497d

Browse files
committed
Merge branch 'jn/maint-commit-missing-template' into maint
* jn/maint-commit-missing-template: commit: error out for missing commit message template
2 parents 43c1b6e + 2140b14 commit afb497d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
634634
if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0)
635635
die_errno("could not read SQUASH_MSG");
636636
hook_arg1 = "squash";
637-
} else if (template_file && !stat(template_file, &statbuf)) {
637+
} else if (template_file) {
638638
if (strbuf_read_file(&sb, template_file, 0) < 0)
639639
die_errno("could not read '%s'", template_file);
640640
hook_arg1 = "template";

t/t7500-commit.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,21 @@ test_expect_success 'a basic commit in an empty tree should succeed' '
2828
test_expect_success 'nonexistent template file should return error' '
2929
echo changes >> foo &&
3030
git add foo &&
31-
test_must_fail git commit --template "$PWD"/notexist
31+
(
32+
GIT_EDITOR="echo hello >\"\$1\"" &&
33+
export GIT_EDITOR &&
34+
test_must_fail git commit --template "$PWD"/notexist
35+
)
3236
'
3337

3438
test_expect_success 'nonexistent template file in config should return error' '
3539
git config commit.template "$PWD"/notexist &&
36-
test_must_fail git commit &&
37-
git config --unset commit.template
40+
test_when_finished "git config --unset commit.template" &&
41+
(
42+
GIT_EDITOR="echo hello >\"\$1\"" &&
43+
export GIT_EDITOR &&
44+
test_must_fail git commit
45+
)
3846
'
3947

4048
# From now on we'll use a template file that exists.

0 commit comments

Comments
 (0)