3 test_description='pre-commit hook'
7 test_expect_success 'with no hook' '
15 test_expect_success '--no-verify with no hook' '
19 git commit --no-verify -m "bar"
23 # now install hook that always succeeds
24 HOOKDIR="$(git rev-parse --git-dir)/hooks"
25 HOOK="$HOOKDIR/pre-commit"
33 test_expect_success 'with succeeding hook' '
35 echo "more" >> file &&
41 test_expect_success '--no-verify with succeeding hook' '
43 echo "even more" >> file &&
45 git commit --no-verify -m "even more"
49 # now a hook that fails
55 test_expect_success 'with failing hook' '
57 echo "another" >> file &&
59 test_must_fail git commit -m "another"
63 test_expect_success '--no-verify with failing hook' '
65 echo "stuff" >> file &&
67 git commit --no-verify -m "stuff"
72 test_expect_success POSIXPERM 'with non-executable hook' '
74 echo "content" >> file &&
76 git commit -m "content"
80 test_expect_success POSIXPERM '--no-verify with non-executable hook' '
82 echo "more content" >> file &&
84 git commit --no-verify -m "more content"
89 # a hook that checks $GIT_PREFIX and succeeds inside the
90 # success/ subdirectory only
93 test \$GIT_PREFIX = success/
96 test_expect_success 'with hook requiring GIT_PREFIX' '
98 echo "more content" >> file &&
103 git commit -m "hook requires GIT_PREFIX = success/"
108 test_expect_success 'with failing hook requiring GIT_PREFIX' '
110 echo "more content" >> file &&
115 test_must_fail git commit -m "hook must fail"
121 test_expect_success 'check the author in hook' '
122 write_script "$HOOK" <<-\EOF &&
123 test "$GIT_AUTHOR_NAME" = "New Author" &&
124 test "$GIT_AUTHOR_EMAIL" = "newauthor@example.com"
126 test_must_fail git commit --allow-empty -m "by a.u.thor" &&
128 GIT_AUTHOR_NAME="New Author" &&
129 GIT_AUTHOR_EMAIL="newauthor@example.com" &&
130 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL &&
131 git commit --allow-empty -m "by new.author via env" &&
134 git commit --author="New Author <newauthor@example.com>" \
135 --allow-empty -m "by new.author via command line" &&