1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
|
#!/bin/sh
test_description='commit-msg hook'
. ./test-lib.sh
stg init
# set up fake editor for interactive editing
cat > fake-editor <<'EOF'
#!/bin/sh
cp FAKE_MSG "$1"
exit 0
EOF
chmod +x fake-editor
## Not using test_set_editor here so we can easily ensure the editor variable
## is only set for the editor tests
FAKE_EDITOR="$(pwd)/fake-editor"
export FAKE_EDITOR
test_expect_success 'new --no-verify with no hook' '
stg new --no-verify -m "bar" new-nv-no-hook
'
test_expect_success 'new --no-verify with no hook (editor)' '
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg new --no-verify new-nv-no-hook-edit
'
# now install hook
HOOKDIR="$(git rev-parse --git-dir)/hooks"
HOOK="$HOOKDIR/commit-msg"
mkdir -p "$HOOKDIR"
cat > "$HOOK" <<EOF
#!/bin/sh
exit 0
EOF
chmod +x "$HOOK"
test_expect_success 'new with succeeding hook' '
stg new -m "more" more
'
test_expect_success 'edit with succeeding hook' '
stg edit -m "mmore" more
'
test_expect_success 'refresh with succeeding hook' '
echo "more" >> file &&
git add file &&
stg refresh -m "mmmore"
'
test_expect_success 'squash with succeeding hook' '
stg squash -n more -m "mmmmore" new-nv-no-hook-edit more
'
test_expect_success 'new with succeeding hook (editor)' '
echo "more more" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg new more-more
'
test_expect_success 'edit with succeeding hook (editor)' '
echo "mmore more" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg edit more-more
'
test_expect_success 'refresh with succeeding hook (editor)' '
echo "more more more" >> file &&
echo "more more more" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg refresh -e
'
test_expect_success 'squash with succeeding hook (editor)' '
echo "more more" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg squash -n more-more more more-more
'
test_expect_success 'new --no-verify with succeeding hook' '
stg new --no-verify -m "even more" even-more
'
test_expect_success 'edit --no-verify with succeeding hook' '
stg edit --no-verify -m "even mmore"
'
test_expect_success 'refresh --no-verify with succeeding hook' '
echo "even more" >> file &&
stg refresh --no-verify -m "even mmmore"
'
test_expect_success 'squash --no-verify with succeeding hook' '
stg squash --no-verify -m "even mmmmore" -n e-m more-more even-more
'
test_expect_success 'new --no-verify with succeeding hook (editor)' '
echo "even more more" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg new --no-verify e-m-m
'
test_expect_success 'edit --no-verify with succeeding hook (editor)' '
echo "even mmore more" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg edit --no-verify
'
test_expect_success 'refresh --no-verify with succeeding hook (editor)' '
echo "even more more" >> file &&
echo "even mmore mmore" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg refresh -e --no-verify
'
test_expect_success 'squash --no-verify with succeeding hook (editor)' '
echo "even more more" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg squash --no-verify -n mo e-m e-m-m
'
# now a hook that fails
cat > "$HOOK" <<EOF
#!/bin/sh
exit 1
EOF
test_expect_success 'new with failing hook' '
! stg new -m "another" another
'
test_expect_success 'edit with failing hook' '
! stg edit -m "another"
'
test_expect_success 'refresh with failing hook' '
! stg refresh -m "another" &&
stg delete refresh-temp
'
test_expect_success 'squash with failing hook' '
! stg squash -m "another" -n another new-nv-no-hook mo
'
test_expect_success 'new with failing hook (editor)' '
echo "more another" > FAKE_MSG &&
! (GIT_EDITOR="\"\$FAKE_EDITOR\"" stg new more-another)
'
test_expect_success 'edit with failing hook (editor)' '
echo "more another" > FAKE_MSG &&
! (GIT_EDITOR="\"\$FAKE_EDITOR\"" stg edit)
'
test_expect_success 'refresh with failing hook (editor)' '
echo "more another" >> file &&
echo "more another" > FAKE_MSG &&
! (GIT_EDITOR="\"\$FAKE_EDITOR\"" stg refresh -e) &&
stg delete refresh-temp
'
test_expect_success 'squash with failing hook (editor)' '
echo "more another" > FAKE_MSG &&
! (GIT_EDITOR="\"\$FAKE_EDITOR\"" stg squash new-nv-no-hook mo)
'
test_expect_success 'new --no-verify with failing hook' '
stg new --no-verify -m "stuff" stuff
'
test_expect_success 'edit --no-verify with failing hook' '
stg edit --no-verify -m "sstuff" stuff
'
test_expect_success 'refresh --no-verify with failing hook' '
echo "stuff" >> file &&
stg refresh --no-verify -m "ssstuff"
'
test_expect_success 'squash --no-verify with failing hook' '
stg squash --no-verify -m "stuff" -n s mo stuff
'
test_expect_success 'new --no-verify with failing hook (editor)' '
echo "more stuff" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg new --no-verify m-s
'
test_expect_success 'edit --no-verify with failing hook (editor)' '
echo "mmore stuff" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg edit --no-verify m-s
'
test_expect_success 'refresh --no-verify with failing hook (editor)' '
echo "more stuff" >> file &&
echo "mmmore stuff" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg refresh -e --no-verify
'
test_expect_success 'squash --no-verify with failing hook (editor)' '
echo "more stuff" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg squash --no-verify -n m-s s m-s
'
chmod -x "$HOOK"
test_expect_success 'refresh with non-executable hook' '
echo "content" >> file &&
stg refresh -m "content"
'
test_expect_success 'refresh with non-executable hook (editor)' '
echo "content again" >> file &&
echo "content again" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg refresh -e
'
test_expect_success 'refresh --no-verify with non-executable hook' '
echo "more content" >> file &&
stg refresh --no-verify -m "more content"
'
test_expect_success 'refresh --no-verify with non-executable hook (editor)' '
echo "even more content" >> file &&
echo "even more content" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg refresh -e --no-verify
'
# now a hook that edits the commit message
cat > "$HOOK" <<'EOF'
#!/bin/sh
echo "new message" > "$1"
exit 0
EOF
chmod +x "$HOOK"
commit_msg_is () {
test "$(git log --pretty=format:%s%b -1)" = "$1"
}
test_expect_success 'new hook edits commit message' '
stg new -m "additional" additional &&
commit_msg_is "new message"
'
test_expect_success "new hook doesn't edit commit message" '
stg new --no-verify -m "plus" plus &&
commit_msg_is "plus"
'
test_expect_success 'new hook edits commit message (editor)' '
echo "additional content" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg new additional-content &&
commit_msg_is "new message"
'
test_expect_success "new hook doesn't edit commit message (editor)" '
echo "more plus" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg new --no-verify more-plus &&
commit_msg_is "more plus"
'
test_expect_success 'edit hook edits commit message' '
stg edit -m "additional" &&
commit_msg_is "new message"
'
test_expect_success "edit hook doesn't edit commit message" '
stg edit --no-verify -m "plus" &&
commit_msg_is "plus"
'
test_expect_success 'edit hook edits commit message (editor)' '
echo "additional content" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg edit &&
commit_msg_is "new message"
'
test_expect_success "edit hook doesn't edit commit message (editor)" '
echo "more plus" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg edit --no-verify &&
commit_msg_is "more plus"
'
test_expect_success 'refresh hook edits commit message' '
echo "additional" >> file &&
stg refresh -m "additional" &&
commit_msg_is "new message"
'
test_expect_success "refresh hook doesn't edit commit message" '
echo "plus" >> file &&
stg refresh --no-verify -m "plus" &&
commit_msg_is "plus"
'
test_expect_success 'refresh hook edits commit message (editor)' '
echo "additional content" >> file &&
echo "additional content" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg refresh -e &&
commit_msg_is "new message"
'
test_expect_success "refresh hook doesn't edit commit message (editor)" '
echo "more plus" >> file &&
echo "more plus" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg refresh -e --no-verify &&
commit_msg_is "more plus"
'
test_expect_success 'squash hook edits commit message' '
stg squash -m "additional" -n add-plus additional-content more-plus &&
commit_msg_is "new message"
'
test_expect_success "squash hook doesn't edit commit message" '
stg squash --no-verify -m "plus" -n plusplus plus add-plus &&
commit_msg_is "plus"
'
test_expect_success 'squash hook edits commit message (editor)' '
echo "additional content" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg squash -n app additional plusplus &&
commit_msg_is "new message"
'
test_expect_success "squash hook doesn't edit commit message (editor)" '
echo "more plus" > FAKE_MSG &&
GIT_EDITOR="\"\$FAKE_EDITOR\"" stg squash --no-verify m-s app &&
commit_msg_is "more plus"
'
test_done
|