| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2006, Junio C Hamano |
| 4 | # |
| 5 | |
| 6 | test_description='fmt-merge-msg test' |
| 7 | |
| 8 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 9 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 10 | |
| 11 | . ./test-lib.sh |
| 12 | . "$TEST_DIRECTORY/lib-gpg.sh" |
| 13 | |
| 14 | test_expect_success setup ' |
| 15 | echo one >one && |
| 16 | git add one && |
| 17 | test_tick && |
| 18 | git commit -m "Initial" && |
| 19 | |
| 20 | git clone . remote && |
| 21 | |
| 22 | echo uno >one && |
| 23 | echo dos >two && |
| 24 | git add two && |
| 25 | test_tick && |
| 26 | git commit -a -m "Second" && |
| 27 | |
| 28 | git checkout -b left && |
| 29 | |
| 30 | echo "c1" >one && |
| 31 | test_tick && |
| 32 | git commit -a -m "Common #1" && |
| 33 | |
| 34 | echo "c2" >one && |
| 35 | test_tick && |
| 36 | git commit -a -m "Common #2" && |
| 37 | |
| 38 | git branch right && |
| 39 | |
| 40 | echo "l3" >two && |
| 41 | test_tick && |
| 42 | GIT_COMMITTER_NAME="Another Committer" \ |
| 43 | GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" && |
| 44 | |
| 45 | echo "l4" >two && |
| 46 | test_tick && |
| 47 | GIT_COMMITTER_NAME="Another Committer" \ |
| 48 | GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" && |
| 49 | |
| 50 | echo "l5" >two && |
| 51 | test_tick && |
| 52 | GIT_COMMITTER_NAME="Another Committer" \ |
| 53 | GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" && |
| 54 | git tag tag-l5 && |
| 55 | |
| 56 | git checkout right && |
| 57 | |
| 58 | echo "r3" >three && |
| 59 | git add three && |
| 60 | test_tick && |
| 61 | git commit -a -m "Right #3" && |
| 62 | git tag tag-r3 && |
| 63 | |
| 64 | echo "r4" >three && |
| 65 | test_tick && |
| 66 | git commit -a -m "Right #4" && |
| 67 | |
| 68 | echo "r5" >three && |
| 69 | test_tick && |
| 70 | git commit -a -m "Right #5" && |
| 71 | |
| 72 | git checkout -b long && |
| 73 | test_commit_bulk --start=0 --message=%s --filename=one 30 && |
| 74 | |
| 75 | git show-branch && |
| 76 | |
| 77 | apos="'\''" |
| 78 | ' |
| 79 | |
| 80 | test_expect_success GPG 'set up a signed tag' ' |
| 81 | git tag -s -m signed-tag-msg signed-good-tag left |
| 82 | ' |
| 83 | |
| 84 | test_expect_success GPGSSH 'created ssh signed commit and tag' ' |
| 85 | test_config gpg.format ssh && |
| 86 | git checkout -b signed-ssh && |
| 87 | touch file && |
| 88 | git add file && |
| 89 | git commit -m "ssh signed" -S"${GPGSSH_KEY_PRIMARY}" && |
| 90 | git tag -s -u"${GPGSSH_KEY_PRIMARY}" -m signed-ssh-tag-msg signed-good-ssh-tag left && |
| 91 | git tag -s -u"${GPGSSH_KEY_UNTRUSTED}" -m signed-ssh-tag-msg-untrusted signed-untrusted-ssh-tag left |
| 92 | ' |
| 93 | |
| 94 | test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'create signed tags with keys having defined lifetimes' ' |
| 95 | test_when_finished "test_unconfig commit.gpgsign" && |
| 96 | test_config gpg.format ssh && |
| 97 | git checkout -b signed-expiry-ssh && |
| 98 | touch file && |
| 99 | git add file && |
| 100 | |
| 101 | echo expired >file && test_tick && git commit -a -m expired -S"${GPGSSH_KEY_EXPIRED}" && |
| 102 | git tag -s -u "${GPGSSH_KEY_EXPIRED}" -m expired-signed expired-signed && |
| 103 | |
| 104 | echo notyetvalid >file && test_tick && git commit -a -m notyetvalid -S"${GPGSSH_KEY_NOTYETVALID}" && |
| 105 | git tag -s -u "${GPGSSH_KEY_NOTYETVALID}" -m notyetvalid-signed notyetvalid-signed && |
| 106 | |
| 107 | echo timeboxedvalid >file && test_tick && git commit -a -m timeboxedvalid -S"${GPGSSH_KEY_TIMEBOXEDVALID}" && |
| 108 | git tag -s -u "${GPGSSH_KEY_TIMEBOXEDVALID}" -m timeboxedvalid-signed timeboxedvalid-signed && |
| 109 | |
| 110 | echo timeboxedinvalid >file && test_tick && git commit -a -m timeboxedinvalid -S"${GPGSSH_KEY_TIMEBOXEDINVALID}" && |
| 111 | git tag -s -u "${GPGSSH_KEY_TIMEBOXEDINVALID}" -m timeboxedinvalid-signed timeboxedinvalid-signed |
| 112 | ' |
| 113 | |
| 114 | test_expect_success 'message for merging local branch' ' |
| 115 | echo "Merge branch ${apos}left${apos}" >expected && |
| 116 | |
| 117 | git checkout main && |
| 118 | git fetch . left && |
| 119 | |
| 120 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 121 | test_cmp expected actual |
| 122 | ' |
| 123 | |
| 124 | test_expect_success GPG 'message for merging local tag signed by good key' ' |
| 125 | git checkout main && |
| 126 | git fetch . signed-good-tag && |
| 127 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 128 | test_grep "^Merge tag ${apos}signed-good-tag${apos}" actual && |
| 129 | test_grep "^signed-tag-msg" actual && |
| 130 | test_grep "^# gpg: Signature made" actual && |
| 131 | test_grep "^# gpg: Good signature from" actual |
| 132 | ' |
| 133 | |
| 134 | test_expect_success GPG 'message for merging local tag signed by unknown key' ' |
| 135 | git checkout main && |
| 136 | git fetch . signed-good-tag && |
| 137 | GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 138 | test_grep "^Merge tag ${apos}signed-good-tag${apos}" actual && |
| 139 | test_grep "^signed-tag-msg" actual && |
| 140 | test_grep "^# gpg: Signature made" actual && |
| 141 | test_grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual |
| 142 | ' |
| 143 | |
| 144 | test_expect_success GPGSSH 'message for merging local tag signed by good ssh key' ' |
| 145 | test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && |
| 146 | git checkout main && |
| 147 | git fetch . signed-good-ssh-tag && |
| 148 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 149 | test_grep "^Merge tag ${apos}signed-good-ssh-tag${apos}" actual && |
| 150 | test_grep "^signed-ssh-tag-msg" actual && |
| 151 | test_grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && |
| 152 | test_grep ! "${GPGSSH_BAD_SIGNATURE}" actual |
| 153 | ' |
| 154 | |
| 155 | test_expect_success GPGSSH 'message for merging local tag signed by unknown ssh key' ' |
| 156 | test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && |
| 157 | git checkout main && |
| 158 | git fetch . signed-untrusted-ssh-tag && |
| 159 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 160 | test_grep "^Merge tag ${apos}signed-untrusted-ssh-tag${apos}" actual && |
| 161 | test_grep "^signed-ssh-tag-msg-untrusted" actual && |
| 162 | test_grep "${GPGSSH_GOOD_SIGNATURE_UNTRUSTED}" actual && |
| 163 | test_grep ! "${GPGSSH_BAD_SIGNATURE}" actual && |
| 164 | test_grep "${GPGSSH_KEY_NOT_TRUSTED}" actual |
| 165 | ' |
| 166 | |
| 167 | test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by expired ssh key' ' |
| 168 | test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && |
| 169 | git checkout main && |
| 170 | git fetch . expired-signed && |
| 171 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 172 | test_grep "^Merge tag ${apos}expired-signed${apos}" actual && |
| 173 | test_grep "^expired-signed" actual && |
| 174 | test_grep ! "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual |
| 175 | ' |
| 176 | |
| 177 | test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by not yet valid ssh key' ' |
| 178 | test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && |
| 179 | git checkout main && |
| 180 | git fetch . notyetvalid-signed && |
| 181 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 182 | test_grep "^Merge tag ${apos}notyetvalid-signed${apos}" actual && |
| 183 | test_grep "^notyetvalid-signed" actual && |
| 184 | test_grep ! "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual |
| 185 | ' |
| 186 | |
| 187 | test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by valid timeboxed ssh key' ' |
| 188 | test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && |
| 189 | git checkout main && |
| 190 | git fetch . timeboxedvalid-signed && |
| 191 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 192 | test_grep "^Merge tag ${apos}timeboxedvalid-signed${apos}" actual && |
| 193 | test_grep "^timeboxedvalid-signed" actual && |
| 194 | test_grep "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual && |
| 195 | test_grep ! "${GPGSSH_BAD_SIGNATURE}" actual |
| 196 | ' |
| 197 | |
| 198 | test_expect_success GPGSSH,GPGSSH_VERIFYTIME 'message for merging local tag signed by invalid timeboxed ssh key' ' |
| 199 | test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && |
| 200 | git checkout main && |
| 201 | git fetch . timeboxedinvalid-signed && |
| 202 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 203 | test_grep "^Merge tag ${apos}timeboxedinvalid-signed${apos}" actual && |
| 204 | test_grep "^timeboxedinvalid-signed" actual && |
| 205 | test_grep ! "${GPGSSH_GOOD_SIGNATURE_TRUSTED}" actual |
| 206 | ' |
| 207 | |
| 208 | test_expect_success 'message for merging external branch' ' |
| 209 | echo "Merge branch ${apos}left${apos} of $(pwd)" >expected && |
| 210 | |
| 211 | git checkout main && |
| 212 | git fetch "$(pwd)" left && |
| 213 | |
| 214 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 215 | test_cmp expected actual |
| 216 | ' |
| 217 | |
| 218 | test_expect_success '[merge] summary/log configuration' ' |
| 219 | cat >expected <<-EOF && |
| 220 | Merge branch ${apos}left${apos} |
| 221 | |
| 222 | # By Another Author (3) and A U Thor (2) |
| 223 | # Via Another Committer |
| 224 | * left: |
| 225 | Left #5 |
| 226 | Left #4 |
| 227 | Left #3 |
| 228 | Common #2 |
| 229 | Common #1 |
| 230 | EOF |
| 231 | |
| 232 | test_config merge.log true && |
| 233 | test_unconfig merge.summary && |
| 234 | |
| 235 | git checkout main && |
| 236 | test_tick && |
| 237 | git fetch . left && |
| 238 | |
| 239 | git fmt-merge-msg <.git/FETCH_HEAD >actual1 && |
| 240 | |
| 241 | test_unconfig merge.log && |
| 242 | test_config merge.summary true && |
| 243 | |
| 244 | git checkout main && |
| 245 | test_tick && |
| 246 | git fetch . left && |
| 247 | |
| 248 | git fmt-merge-msg <.git/FETCH_HEAD >actual2 && |
| 249 | |
| 250 | test_cmp expected actual1 && |
| 251 | test_cmp expected actual2 |
| 252 | ' |
| 253 | |
| 254 | test_expect_success 'setup FETCH_HEAD' ' |
| 255 | git checkout main && |
| 256 | test_tick && |
| 257 | git fetch . left |
| 258 | ' |
| 259 | |
| 260 | test_expect_success 'merge.log=3 limits shortlog length' ' |
| 261 | cat >expected <<-EOF && |
| 262 | Merge branch ${apos}left${apos} |
| 263 | |
| 264 | # By Another Author (3) and A U Thor (2) |
| 265 | # Via Another Committer |
| 266 | * left: (5 commits) |
| 267 | Left #5 |
| 268 | Left #4 |
| 269 | Left #3 |
| 270 | ... |
| 271 | EOF |
| 272 | |
| 273 | git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 274 | test_cmp expected actual |
| 275 | ' |
| 276 | |
| 277 | test_expect_success 'merge.log=5 shows all 5 commits' ' |
| 278 | cat >expected <<-EOF && |
| 279 | Merge branch ${apos}left${apos} |
| 280 | |
| 281 | # By Another Author (3) and A U Thor (2) |
| 282 | # Via Another Committer |
| 283 | * left: |
| 284 | Left #5 |
| 285 | Left #4 |
| 286 | Left #3 |
| 287 | Common #2 |
| 288 | Common #1 |
| 289 | EOF |
| 290 | |
| 291 | git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 292 | test_cmp expected actual |
| 293 | ' |
| 294 | |
| 295 | test_expect_success '--log=5 with custom comment character' ' |
| 296 | cat >expected <<-EOF && |
| 297 | Merge branch ${apos}left${apos} |
| 298 | |
| 299 | x By Another Author (3) and A U Thor (2) |
| 300 | x Via Another Committer |
| 301 | * left: |
| 302 | Left #5 |
| 303 | Left #4 |
| 304 | Left #3 |
| 305 | Common #2 |
| 306 | Common #1 |
| 307 | EOF |
| 308 | |
| 309 | git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual && |
| 310 | test_cmp expected actual |
| 311 | ' |
| 312 | |
| 313 | test_expect_success 'merge.log=0 disables shortlog' ' |
| 314 | echo "Merge branch ${apos}left${apos}" >expected && |
| 315 | git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 316 | test_cmp expected actual |
| 317 | ' |
| 318 | |
| 319 | test_expect_success '--log=3 limits shortlog length' ' |
| 320 | cat >expected <<-EOF && |
| 321 | Merge branch ${apos}left${apos} |
| 322 | |
| 323 | # By Another Author (3) and A U Thor (2) |
| 324 | # Via Another Committer |
| 325 | * left: (5 commits) |
| 326 | Left #5 |
| 327 | Left #4 |
| 328 | Left #3 |
| 329 | ... |
| 330 | EOF |
| 331 | |
| 332 | git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual && |
| 333 | test_cmp expected actual |
| 334 | ' |
| 335 | |
| 336 | test_expect_success '--log=5 shows all 5 commits' ' |
| 337 | cat >expected <<-EOF && |
| 338 | Merge branch ${apos}left${apos} |
| 339 | |
| 340 | # By Another Author (3) and A U Thor (2) |
| 341 | # Via Another Committer |
| 342 | * left: |
| 343 | Left #5 |
| 344 | Left #4 |
| 345 | Left #3 |
| 346 | Common #2 |
| 347 | Common #1 |
| 348 | EOF |
| 349 | |
| 350 | git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual && |
| 351 | test_cmp expected actual |
| 352 | ' |
| 353 | |
| 354 | test_expect_success '--no-log disables shortlog' ' |
| 355 | echo "Merge branch ${apos}left${apos}" >expected && |
| 356 | git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual && |
| 357 | test_cmp expected actual |
| 358 | ' |
| 359 | |
| 360 | test_expect_success '--log=0 disables shortlog' ' |
| 361 | echo "Merge branch ${apos}left${apos}" >expected && |
| 362 | git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual && |
| 363 | test_cmp expected actual |
| 364 | ' |
| 365 | |
| 366 | test_expect_success 'fmt-merge-msg -m' ' |
| 367 | echo "Sync with left" >expected && |
| 368 | cat >expected.log <<-EOF && |
| 369 | Sync with left |
| 370 | |
| 371 | # By Another Author (3) and A U Thor (2) |
| 372 | # Via Another Committer |
| 373 | * ${apos}left${apos} of $(pwd): |
| 374 | Left #5 |
| 375 | Left #4 |
| 376 | Left #3 |
| 377 | Common #2 |
| 378 | Common #1 |
| 379 | EOF |
| 380 | |
| 381 | test_unconfig merge.log && |
| 382 | test_unconfig merge.summary && |
| 383 | git checkout main && |
| 384 | git fetch "$(pwd)" left && |
| 385 | git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual && |
| 386 | git fmt-merge-msg --log -m "Sync with left" \ |
| 387 | <.git/FETCH_HEAD >actual.log && |
| 388 | test_config merge.log true && |
| 389 | git fmt-merge-msg -m "Sync with left" \ |
| 390 | <.git/FETCH_HEAD >actual.log-config && |
| 391 | git fmt-merge-msg --no-log -m "Sync with left" \ |
| 392 | <.git/FETCH_HEAD >actual.nolog && |
| 393 | |
| 394 | test_cmp expected actual && |
| 395 | test_cmp expected.log actual.log && |
| 396 | test_cmp expected.log actual.log-config && |
| 397 | test_cmp expected actual.nolog |
| 398 | ' |
| 399 | |
| 400 | test_expect_success 'setup: expected shortlog for two branches' ' |
| 401 | cat >expected <<-EOF |
| 402 | Merge branches ${apos}left${apos} and ${apos}right${apos} |
| 403 | |
| 404 | # By Another Author (3) and A U Thor (2) |
| 405 | # Via Another Committer |
| 406 | * left: |
| 407 | Left #5 |
| 408 | Left #4 |
| 409 | Left #3 |
| 410 | Common #2 |
| 411 | Common #1 |
| 412 | |
| 413 | * right: |
| 414 | Right #5 |
| 415 | Right #4 |
| 416 | Right #3 |
| 417 | Common #2 |
| 418 | Common #1 |
| 419 | EOF |
| 420 | ' |
| 421 | |
| 422 | test_expect_success 'shortlog for two branches' ' |
| 423 | test_config merge.log true && |
| 424 | test_unconfig merge.summary && |
| 425 | git checkout main && |
| 426 | test_tick && |
| 427 | git fetch . left right && |
| 428 | git fmt-merge-msg <.git/FETCH_HEAD >actual1 && |
| 429 | |
| 430 | test_unconfig merge.log && |
| 431 | test_config merge.summary true && |
| 432 | git checkout main && |
| 433 | test_tick && |
| 434 | git fetch . left right && |
| 435 | git fmt-merge-msg <.git/FETCH_HEAD >actual2 && |
| 436 | |
| 437 | test_config merge.log yes && |
| 438 | test_unconfig merge.summary && |
| 439 | git checkout main && |
| 440 | test_tick && |
| 441 | git fetch . left right && |
| 442 | git fmt-merge-msg <.git/FETCH_HEAD >actual3 && |
| 443 | |
| 444 | test_unconfig merge.log && |
| 445 | test_config merge.summary yes && |
| 446 | git checkout main && |
| 447 | test_tick && |
| 448 | git fetch . left right && |
| 449 | git fmt-merge-msg <.git/FETCH_HEAD >actual4 && |
| 450 | |
| 451 | test_cmp expected actual1 && |
| 452 | test_cmp expected actual2 && |
| 453 | test_cmp expected actual3 && |
| 454 | test_cmp expected actual4 |
| 455 | ' |
| 456 | |
| 457 | test_expect_success 'merge-msg -F' ' |
| 458 | test_unconfig merge.log && |
| 459 | test_config merge.summary yes && |
| 460 | git checkout main && |
| 461 | test_tick && |
| 462 | git fetch . left right && |
| 463 | git fmt-merge-msg -F .git/FETCH_HEAD >actual && |
| 464 | test_cmp expected actual |
| 465 | ' |
| 466 | |
| 467 | test_expect_success 'merge-msg -F in subdirectory' ' |
| 468 | test_unconfig merge.log && |
| 469 | test_config merge.summary yes && |
| 470 | git checkout main && |
| 471 | test_tick && |
| 472 | git fetch . left right && |
| 473 | mkdir sub && |
| 474 | cp .git/FETCH_HEAD sub/FETCH_HEAD && |
| 475 | ( |
| 476 | cd sub && |
| 477 | git fmt-merge-msg -F FETCH_HEAD >../actual |
| 478 | ) && |
| 479 | test_cmp expected actual |
| 480 | ' |
| 481 | |
| 482 | test_expect_success 'merge-msg with nothing to merge' ' |
| 483 | test_unconfig merge.log && |
| 484 | test_config merge.summary yes && |
| 485 | |
| 486 | ( |
| 487 | cd remote && |
| 488 | git checkout -b unrelated && |
| 489 | test_tick && |
| 490 | git fetch origin && |
| 491 | git fmt-merge-msg <.git/FETCH_HEAD >../actual |
| 492 | ) && |
| 493 | |
| 494 | test_must_be_empty actual |
| 495 | ' |
| 496 | |
| 497 | test_expect_success 'merge-msg tag' ' |
| 498 | cat >expected <<-EOF && |
| 499 | Merge tag ${apos}tag-r3${apos} |
| 500 | |
| 501 | * tag ${apos}tag-r3${apos}: |
| 502 | Right #3 |
| 503 | Common #2 |
| 504 | Common #1 |
| 505 | EOF |
| 506 | |
| 507 | test_unconfig merge.log && |
| 508 | test_config merge.summary yes && |
| 509 | |
| 510 | git checkout main && |
| 511 | test_tick && |
| 512 | git fetch . tag tag-r3 && |
| 513 | |
| 514 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 515 | test_cmp expected actual |
| 516 | ' |
| 517 | |
| 518 | test_expect_success 'merge-msg two tags' ' |
| 519 | cat >expected <<-EOF && |
| 520 | Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos} |
| 521 | |
| 522 | * tag ${apos}tag-r3${apos}: |
| 523 | Right #3 |
| 524 | Common #2 |
| 525 | Common #1 |
| 526 | |
| 527 | # By Another Author (3) and A U Thor (2) |
| 528 | # Via Another Committer |
| 529 | * tag ${apos}tag-l5${apos}: |
| 530 | Left #5 |
| 531 | Left #4 |
| 532 | Left #3 |
| 533 | Common #2 |
| 534 | Common #1 |
| 535 | EOF |
| 536 | |
| 537 | test_unconfig merge.log && |
| 538 | test_config merge.summary yes && |
| 539 | |
| 540 | git checkout main && |
| 541 | test_tick && |
| 542 | git fetch . tag tag-r3 tag tag-l5 && |
| 543 | |
| 544 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 545 | test_cmp expected actual |
| 546 | ' |
| 547 | |
| 548 | test_expect_success 'merge-msg tag and branch' ' |
| 549 | cat >expected <<-EOF && |
| 550 | Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos} |
| 551 | |
| 552 | * tag ${apos}tag-r3${apos}: |
| 553 | Right #3 |
| 554 | Common #2 |
| 555 | Common #1 |
| 556 | |
| 557 | # By Another Author (3) and A U Thor (2) |
| 558 | # Via Another Committer |
| 559 | * left: |
| 560 | Left #5 |
| 561 | Left #4 |
| 562 | Left #3 |
| 563 | Common #2 |
| 564 | Common #1 |
| 565 | EOF |
| 566 | |
| 567 | test_unconfig merge.log && |
| 568 | test_config merge.summary yes && |
| 569 | |
| 570 | git checkout main && |
| 571 | test_tick && |
| 572 | git fetch . tag tag-r3 left && |
| 573 | |
| 574 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 575 | test_cmp expected actual |
| 576 | ' |
| 577 | |
| 578 | test_expect_success 'merge-msg lots of commits' ' |
| 579 | { |
| 580 | cat <<-EOF && |
| 581 | Merge branch ${apos}long${apos} |
| 582 | |
| 583 | * long: (35 commits) |
| 584 | EOF |
| 585 | |
| 586 | i=29 && |
| 587 | while test $i -gt 9 |
| 588 | do |
| 589 | echo " $i" && |
| 590 | i=$(($i-1)) || return 1 |
| 591 | done && |
| 592 | echo " ..." |
| 593 | } >expected && |
| 594 | |
| 595 | test_config merge.summary yes && |
| 596 | |
| 597 | git checkout main && |
| 598 | test_tick && |
| 599 | git fetch . long && |
| 600 | |
| 601 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 602 | test_cmp expected actual |
| 603 | ' |
| 604 | |
| 605 | test_expect_success 'merge-msg with "merging" an annotated tag' ' |
| 606 | test_config merge.log true && |
| 607 | |
| 608 | git checkout main^0 && |
| 609 | git commit --allow-empty -m "One step ahead" && |
| 610 | git tag -a -m "An annotated one" annotate HEAD && |
| 611 | |
| 612 | git checkout main && |
| 613 | git fetch . annotate && |
| 614 | |
| 615 | git fmt-merge-msg <.git/FETCH_HEAD >actual && |
| 616 | { |
| 617 | cat <<-\EOF |
| 618 | Merge tag '\''annotate'\'' |
| 619 | |
| 620 | An annotated one |
| 621 | |
| 622 | * tag '\''annotate'\'': |
| 623 | One step ahead |
| 624 | EOF |
| 625 | } >expected && |
| 626 | test_cmp expected actual && |
| 627 | |
| 628 | test_when_finished "git reset --hard" && |
| 629 | annotate=$(git rev-parse annotate) && |
| 630 | git merge --no-commit --no-ff $annotate && |
| 631 | { |
| 632 | cat <<-EOF |
| 633 | Merge tag '\''$annotate'\'' |
| 634 | |
| 635 | An annotated one |
| 636 | |
| 637 | * tag '\''$annotate'\'': |
| 638 | One step ahead |
| 639 | EOF |
| 640 | } >expected && |
| 641 | test_cmp expected .git/MERGE_MSG |
| 642 | ' |
| 643 | |
| 644 | test_expect_success 'merge --into-name=<name>' ' |
| 645 | test_when_finished "git checkout main" && |
| 646 | git checkout -B side main && |
| 647 | git commit --allow-empty -m "One step ahead" && |
| 648 | |
| 649 | git checkout --detach main && |
| 650 | git merge --no-ff side && |
| 651 | git show -s --format="%s" >full.0 && |
| 652 | head -n1 full.0 >actual && |
| 653 | # expect that HEAD is shown as-is |
| 654 | test_grep -e "Merge branch .side. into HEAD$" actual && |
| 655 | |
| 656 | git reset --hard main && |
| 657 | git merge --no-ff --into-name=main side && |
| 658 | git show -s --format="%s" >full.1 && |
| 659 | head -n1 full.1 >actual && |
| 660 | # expect that we pretend to be merging to main, that is suppressed |
| 661 | test_grep -e "Merge branch .side.$" actual && |
| 662 | |
| 663 | git checkout -b throwaway main && |
| 664 | git merge --no-ff --into-name=main side && |
| 665 | git show -s --format="%s" >full.2 && |
| 666 | head -n1 full.2 >actual && |
| 667 | # expect that we pretend to be merging to main, that is suppressed |
| 668 | test_grep -e "Merge branch .side.$" actual |
| 669 | ' |
| 670 | |
| 671 | test_expect_success 'merge.suppressDest configuration' ' |
| 672 | test_when_finished "git checkout main" && |
| 673 | git checkout -B side main && |
| 674 | git commit --allow-empty -m "One step ahead" && |
| 675 | git checkout main && |
| 676 | git fetch . side && |
| 677 | |
| 678 | git -c merge.suppressDest="" fmt-merge-msg <.git/FETCH_HEAD >full.1 && |
| 679 | head -n1 full.1 >actual && |
| 680 | test_grep -e "Merge branch .side. into main" actual && |
| 681 | |
| 682 | git -c merge.suppressDest="mast" fmt-merge-msg <.git/FETCH_HEAD >full.2 && |
| 683 | head -n1 full.2 >actual && |
| 684 | test_grep -e "Merge branch .side. into main$" actual && |
| 685 | |
| 686 | git -c merge.suppressDest="ma?*[rn]" fmt-merge-msg <.git/FETCH_HEAD >full.3 && |
| 687 | head -n1 full.3 >actual && |
| 688 | test_grep -e "Merge branch .side." actual && |
| 689 | test_grep ! -e " into main$" actual && |
| 690 | |
| 691 | git checkout --detach HEAD && |
| 692 | git -c merge.suppressDest="main" fmt-merge-msg <.git/FETCH_HEAD >full.4 && |
| 693 | head -n1 full.4 >actual && |
| 694 | test_grep -e "Merge branch .side. into HEAD$" actual && |
| 695 | |
| 696 | git -c merge.suppressDest="main" fmt-merge-msg \ |
| 697 | --into-name=main <.git/FETCH_HEAD >full.5 && |
| 698 | head -n1 full.5 >actual && |
| 699 | test_grep -e "Merge branch .side." actual && |
| 700 | test_grep ! -e " into main$" actual && |
| 701 | test_grep ! -e " into HEAD$" actual |
| 702 | ' |
| 703 | |
| 704 | test_done |