Browse Source

Merge branch 'jn/maint-commit-missing-template'

* jn/maint-commit-missing-template:
  commit: error out for missing commit message template
maint
Junio C Hamano 14 years ago
parent
commit
5cb3c9b7df
  1. 2
      builtin/commit.c
  2. 14
      t/t7500-commit.sh

2
builtin/commit.c

@ -634,7 +634,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0) if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0)
die_errno("could not read SQUASH_MSG"); die_errno("could not read SQUASH_MSG");
hook_arg1 = "squash"; hook_arg1 = "squash";
} else if (template_file && !stat(template_file, &statbuf)) { } else if (template_file) {
if (strbuf_read_file(&sb, template_file, 0) < 0) if (strbuf_read_file(&sb, template_file, 0) < 0)
die_errno("could not read '%s'", template_file); die_errno("could not read '%s'", template_file);
hook_arg1 = "template"; hook_arg1 = "template";

14
t/t7500-commit.sh

@ -28,13 +28,21 @@ test_expect_success 'a basic commit in an empty tree should succeed' '
test_expect_success 'nonexistent template file should return error' ' test_expect_success 'nonexistent template file should return error' '
echo changes >> foo && echo changes >> foo &&
git add 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' ' test_expect_success 'nonexistent template file in config should return error' '
git config commit.template "$PWD"/notexist && git config commit.template "$PWD"/notexist &&
test_must_fail git commit && test_when_finished "git config --unset commit.template" &&
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. # From now on we'll use a template file that exists.

Loading…
Cancel
Save