@@ -101,6 +101,10 @@ cat > "$HOOK" <<EOF
101
101
exit 1
102
102
EOF
103
103
104
+ commit_msg_is () {
105
+ test " $( git log --pretty=format:%s%b -1) " = " $1 "
106
+ }
107
+
104
108
test_expect_success ' with failing hook' '
105
109
106
110
echo "another" >> file &&
@@ -135,6 +139,32 @@ test_expect_success '--no-verify with failing hook (editor)' '
135
139
136
140
'
137
141
142
+ test_expect_success ' merge fails with failing hook' '
143
+
144
+ test_when_finished "git branch -D newbranch" &&
145
+ test_when_finished "git checkout -f master" &&
146
+ git checkout --orphan newbranch &&
147
+ : >file2 &&
148
+ git add file2 &&
149
+ git commit --no-verify file2 -m in-side-branch &&
150
+ test_must_fail git merge --allow-unrelated-histories master &&
151
+ commit_msg_is "in-side-branch" # HEAD before merge
152
+
153
+ '
154
+
155
+ test_expect_success ' merge bypasses failing hook with --no-verify' '
156
+
157
+ test_when_finished "git branch -D newbranch" &&
158
+ test_when_finished "git checkout -f master" &&
159
+ git checkout --orphan newbranch &&
160
+ : >file2 &&
161
+ git add file2 &&
162
+ git commit --no-verify file2 -m in-side-branch &&
163
+ git merge --no-verify --allow-unrelated-histories master &&
164
+ commit_msg_is "Merge branch ' \' ' master' \' ' into newbranch"
165
+ '
166
+
167
+
138
168
chmod -x " $HOOK "
139
169
test_expect_success POSIXPERM ' with non-executable hook' '
140
170
@@ -178,10 +208,6 @@ exit 0
178
208
EOF
179
209
chmod +x " $HOOK "
180
210
181
- commit_msg_is () {
182
- test " $( git log --pretty=format:%s%b -1) " = " $1 "
183
- }
184
-
185
211
test_expect_success ' hook edits commit message' '
186
212
187
213
echo "additional" >> file &&
@@ -217,7 +243,36 @@ test_expect_success "hook doesn't edit commit message (editor)" '
217
243
echo "more plus" > FAKE_MSG &&
218
244
GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify &&
219
245
commit_msg_is "more plus"
246
+ '
220
247
248
+ test_expect_success ' hook called in git-merge picks up commit message' '
249
+ test_when_finished "git branch -D newbranch" &&
250
+ test_when_finished "git checkout -f master" &&
251
+ git checkout --orphan newbranch &&
252
+ : >file2 &&
253
+ git add file2 &&
254
+ git commit --no-verify file2 -m in-side-branch &&
255
+ git merge --allow-unrelated-histories master &&
256
+ commit_msg_is "new message"
257
+ '
258
+
259
+ test_expect_failure ' merge --continue remembers --no-verify' '
260
+ test_when_finished "git branch -D newbranch" &&
261
+ test_when_finished "git checkout -f master" &&
262
+ git checkout master &&
263
+ echo a >file2 &&
264
+ git add file2 &&
265
+ git commit --no-verify -m "add file2 to master" &&
266
+ git checkout -b newbranch master^ &&
267
+ echo b >file2 &&
268
+ git add file2 &&
269
+ git commit --no-verify file2 -m in-side-branch &&
270
+ git merge --no-verify -m not-rewritten-by-hook master &&
271
+ # resolve conflict:
272
+ echo c >file2 &&
273
+ git add file2 &&
274
+ git merge --continue &&
275
+ commit_msg_is not-rewritten-by-hook
221
276
'
222
277
223
278
# set up fake editor to replace `pick` by `reword`
@@ -237,4 +292,5 @@ test_expect_success 'hook is called for reword during `rebase -i`' '
237
292
238
293
'
239
294
295
+
240
296
test_done
0 commit comments