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'
23 ## Not using test_set_editor here so we can easily ensure the editor variable
24 ## is only set for the editor tests
25 FAKE_EDITOR="$(pwd)/fake-editor"
28 test_expect_success 'with no hook (editor)' '
30 echo "more foo" >> file &&
32 echo "more foo" > FAKE_MSG &&
33 GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit
37 test_expect_success '--no-verify with no hook' '
41 git commit --no-verify -m "bar"
45 test_expect_success '--no-verify with no hook (editor)' '
47 echo "more bar" > file &&
49 echo "more bar" > FAKE_MSG &&
50 GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify
54 # now install hook that always succeeds
55 HOOKDIR="$(git rev-parse --git-dir)/hooks"
56 HOOK="$HOOKDIR/commit-msg"
64 test_expect_success 'with succeeding hook' '
66 echo "more" >> file &&
72 test_expect_success 'with succeeding hook (editor)' '
74 echo "more more" >> file &&
76 echo "more more" > FAKE_MSG &&
77 GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit
81 test_expect_success '--no-verify with succeeding hook' '
83 echo "even more" >> file &&
85 git commit --no-verify -m "even more"
89 test_expect_success '--no-verify with succeeding hook (editor)' '
91 echo "even more more" >> file &&
93 echo "even more more" > FAKE_MSG &&
94 GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify
98 # now a hook that fails
104 test_expect_success 'with failing hook' '
106 echo "another" >> file &&
108 ! git commit -m "another"
112 test_expect_success 'with failing hook (editor)' '
114 echo "more another" >> file &&
116 echo "more another" > FAKE_MSG &&
117 ! (GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit)
121 test_expect_success '--no-verify with failing hook' '
123 echo "stuff" >> file &&
125 git commit --no-verify -m "stuff"
129 test_expect_success '--no-verify with failing hook (editor)' '
131 echo "more stuff" >> file &&
133 echo "more stuff" > FAKE_MSG &&
134 GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify
139 test_expect_success 'with non-executable hook' '
141 echo "content" >> file &&
143 git commit -m "content"
147 test_expect_success 'with non-executable hook (editor)' '
149 echo "content again" >> file &&
151 echo "content again" > FAKE_MSG &&
152 GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit -m "content again"
156 test_expect_success '--no-verify with non-executable hook' '
158 echo "more content" >> file &&
160 git commit --no-verify -m "more content"
164 test_expect_success '--no-verify with non-executable hook (editor)' '
166 echo "even more content" >> file &&
168 echo "even more content" > FAKE_MSG &&
169 GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify
173 # now a hook that edits the commit message
174 cat > "$HOOK" <<'EOF'
176 echo "new message" > "$1"
182 test "`git log --pretty=format:%s%b -1`" = "$1"
185 test_expect_success 'hook edits commit message' '
187 echo "additional" >> file &&
189 git commit -m "additional" &&
190 commit_msg_is "new message"
194 test_expect_success 'hook edits commit message (editor)' '
196 echo "additional content" >> file &&
198 echo "additional content" > FAKE_MSG &&
199 GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit &&
200 commit_msg_is "new message"
204 test_expect_success "hook doesn't edit commit message" '
206 echo "plus" >> file &&
208 git commit --no-verify -m "plus" &&
213 test_expect_success "hook doesn't edit commit message (editor)" '
215 echo "more plus" >> file &&
217 echo "more plus" > FAKE_MSG &&
218 GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify &&
219 commit_msg_is "more plus"