3 test_description='commit-msg hook'
7 test_expect_success 'with no hook' '
15 # set up fake editor for interactive editing
16 cat > fake-editor <<'EOF'
22 FAKE_EDITOR="$(pwd)/fake-editor"
25 test_expect_success 'with no hook (editor)' '
27 echo "more foo" >> file &&
29 echo "more foo" > FAKE_MSG &&
30 GIT_EDITOR="$FAKE_EDITOR" git commit
34 test_expect_success '--no-verify with no hook' '
38 git commit --no-verify -m "bar"
42 test_expect_success '--no-verify with no hook (editor)' '
44 echo "more bar" > file &&
46 echo "more bar" > FAKE_MSG &&
47 GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
51 # now install hook that always succeeds
52 HOOKDIR="$(git rev-parse --git-dir)/hooks"
53 HOOK="$HOOKDIR/commit-msg"
61 test_expect_success 'with succeeding hook' '
63 echo "more" >> file &&
69 test_expect_success 'with succeeding hook (editor)' '
71 echo "more more" >> file &&
73 echo "more more" > FAKE_MSG &&
74 GIT_EDITOR="$FAKE_EDITOR" git commit
78 test_expect_success '--no-verify with succeeding hook' '
80 echo "even more" >> file &&
82 git commit --no-verify -m "even more"
86 test_expect_success '--no-verify with succeeding hook (editor)' '
88 echo "even more more" >> file &&
90 echo "even more more" > FAKE_MSG &&
91 GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
95 # now a hook that fails
101 test_expect_success 'with failing hook' '
103 echo "another" >> file &&
105 ! git commit -m "another"
109 test_expect_success 'with failing hook (editor)' '
111 echo "more another" >> file &&
113 echo "more another" > FAKE_MSG &&
114 ! (GIT_EDITOR="$FAKE_EDITOR" git commit)
118 test_expect_success '--no-verify with failing hook' '
120 echo "stuff" >> file &&
122 git commit --no-verify -m "stuff"
126 test_expect_success '--no-verify with failing hook (editor)' '
128 echo "more stuff" >> file &&
130 echo "more stuff" > FAKE_MSG &&
131 GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
136 test_expect_success 'with non-executable hook' '
138 echo "content" >> file &&
140 git commit -m "content"
144 test_expect_success 'with non-executable hook (editor)' '
146 echo "content again" >> file &&
148 echo "content again" > FAKE_MSG &&
149 GIT_EDITOR="$FAKE_EDITOR" git commit -m "content again"
153 test_expect_success '--no-verify with non-executable hook' '
155 echo "more content" >> file &&
157 git commit --no-verify -m "more content"
161 test_expect_success '--no-verify with non-executable hook (editor)' '
163 echo "even more content" >> file &&
165 echo "even more content" > FAKE_MSG &&
166 GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
170 # now a hook that edits the commit message
171 cat > "$HOOK" <<'EOF'
173 echo "new message" > "$1"
179 test "`git log --pretty=format:%s%b -1`" = "$1"
182 test_expect_success 'hook edits commit message' '
184 echo "additional" >> file &&
186 git commit -m "additional" &&
187 commit_msg_is "new message"
191 test_expect_success 'hook edits commit message (editor)' '
193 echo "additional content" >> file &&
195 echo "additional content" > FAKE_MSG &&
196 GIT_EDITOR="$FAKE_EDITOR" git commit &&
197 commit_msg_is "new message"
201 test_expect_success "hook doesn't edit commit message" '
203 echo "plus" >> file &&
205 git commit --no-verify -m "plus" &&
210 test_expect_success "hook doesn't edit commit message (editor)" '
212 echo "more plus" >> file &&
214 echo "more plus" > FAKE_MSG &&
215 GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify &&
216 commit_msg_is "more plus"