t / t6200-fmt-merge-msg.shon commit test-reach: test get_merge_bases_many (324dec0)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006, Junio C Hamano
   4#
   5
   6test_description='fmt-merge-msg test'
   7
   8. ./test-lib.sh
   9
  10test_expect_success setup '
  11        echo one >one &&
  12        git add one &&
  13        test_tick &&
  14        git commit -m "Initial" &&
  15
  16        git clone . remote &&
  17
  18        echo uno >one &&
  19        echo dos >two &&
  20        git add two &&
  21        test_tick &&
  22        git commit -a -m "Second" &&
  23
  24        git checkout -b left &&
  25
  26        echo "c1" >one &&
  27        test_tick &&
  28        git commit -a -m "Common #1" &&
  29
  30        echo "c2" >one &&
  31        test_tick &&
  32        git commit -a -m "Common #2" &&
  33
  34        git branch right &&
  35
  36        echo "l3" >two &&
  37        test_tick &&
  38        GIT_COMMITTER_NAME="Another Committer" \
  39        GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #3" &&
  40
  41        echo "l4" >two &&
  42        test_tick &&
  43        GIT_COMMITTER_NAME="Another Committer" \
  44        GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #4" &&
  45
  46        echo "l5" >two &&
  47        test_tick &&
  48        GIT_COMMITTER_NAME="Another Committer" \
  49        GIT_AUTHOR_NAME="Another Author" git commit -a -m "Left #5" &&
  50        git tag tag-l5 &&
  51
  52        git checkout right &&
  53
  54        echo "r3" >three &&
  55        git add three &&
  56        test_tick &&
  57        git commit -a -m "Right #3" &&
  58        git tag tag-r3 &&
  59
  60        echo "r4" >three &&
  61        test_tick &&
  62        git commit -a -m "Right #4" &&
  63
  64        echo "r5" >three &&
  65        test_tick &&
  66        git commit -a -m "Right #5" &&
  67
  68        git checkout -b long &&
  69        i=0 &&
  70        while test $i -lt 30
  71        do
  72                test_commit $i one &&
  73                i=$(($i+1))
  74        done &&
  75
  76        git show-branch &&
  77
  78        apos="'\''"
  79'
  80
  81test_expect_success 'message for merging local branch' '
  82        echo "Merge branch ${apos}left${apos}" >expected &&
  83
  84        git checkout master &&
  85        git fetch . left &&
  86
  87        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
  88        test_cmp expected actual
  89'
  90
  91test_expect_success 'message for merging external branch' '
  92        echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
  93
  94        git checkout master &&
  95        git fetch "$(pwd)" left &&
  96
  97        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
  98        test_cmp expected actual
  99'
 100
 101test_expect_success '[merge] summary/log configuration' '
 102        cat >expected <<-EOF &&
 103        Merge branch ${apos}left${apos}
 104
 105        # By Another Author (3) and A U Thor (2)
 106        # Via Another Committer
 107        * left:
 108          Left #5
 109          Left #4
 110          Left #3
 111          Common #2
 112          Common #1
 113        EOF
 114
 115        test_config merge.log true &&
 116        test_unconfig merge.summary &&
 117
 118        git checkout master &&
 119        test_tick &&
 120        git fetch . left &&
 121
 122        git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
 123
 124        test_unconfig merge.log &&
 125        test_config merge.summary true &&
 126
 127        git checkout master &&
 128        test_tick &&
 129        git fetch . left &&
 130
 131        git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
 132
 133        test_cmp expected actual1 &&
 134        test_cmp expected actual2
 135'
 136
 137test_expect_success 'setup FETCH_HEAD' '
 138        git checkout master &&
 139        test_tick &&
 140        git fetch . left
 141'
 142
 143test_expect_success 'merge.log=3 limits shortlog length' '
 144        cat >expected <<-EOF &&
 145        Merge branch ${apos}left${apos}
 146
 147        # By Another Author (3) and A U Thor (2)
 148        # Via Another Committer
 149        * left: (5 commits)
 150          Left #5
 151          Left #4
 152          Left #3
 153          ...
 154        EOF
 155
 156        git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
 157        test_cmp expected actual
 158'
 159
 160test_expect_success 'merge.log=5 shows all 5 commits' '
 161        cat >expected <<-EOF &&
 162        Merge branch ${apos}left${apos}
 163
 164        # By Another Author (3) and A U Thor (2)
 165        # Via Another Committer
 166        * left:
 167          Left #5
 168          Left #4
 169          Left #3
 170          Common #2
 171          Common #1
 172        EOF
 173
 174        git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
 175        test_cmp expected actual
 176'
 177
 178test_expect_success '--log=5 with custom comment character' '
 179        cat >expected <<-EOF &&
 180        Merge branch ${apos}left${apos}
 181
 182        x By Another Author (3) and A U Thor (2)
 183        x Via Another Committer
 184        * left:
 185          Left #5
 186          Left #4
 187          Left #3
 188          Common #2
 189          Common #1
 190        EOF
 191
 192        git -c core.commentchar="x" fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
 193        test_cmp expected actual
 194'
 195
 196test_expect_success 'merge.log=0 disables shortlog' '
 197        echo "Merge branch ${apos}left${apos}" >expected &&
 198        git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
 199        test_cmp expected actual
 200'
 201
 202test_expect_success '--log=3 limits shortlog length' '
 203        cat >expected <<-EOF &&
 204        Merge branch ${apos}left${apos}
 205
 206        # By Another Author (3) and A U Thor (2)
 207        # Via Another Committer
 208        * left: (5 commits)
 209          Left #5
 210          Left #4
 211          Left #3
 212          ...
 213        EOF
 214
 215        git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
 216        test_cmp expected actual
 217'
 218
 219test_expect_success '--log=5 shows all 5 commits' '
 220        cat >expected <<-EOF &&
 221        Merge branch ${apos}left${apos}
 222
 223        # By Another Author (3) and A U Thor (2)
 224        # Via Another Committer
 225        * left:
 226          Left #5
 227          Left #4
 228          Left #3
 229          Common #2
 230          Common #1
 231        EOF
 232
 233        git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
 234        test_cmp expected actual
 235'
 236
 237test_expect_success '--no-log disables shortlog' '
 238        echo "Merge branch ${apos}left${apos}" >expected &&
 239        git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
 240        test_cmp expected actual
 241'
 242
 243test_expect_success '--log=0 disables shortlog' '
 244        echo "Merge branch ${apos}left${apos}" >expected &&
 245        git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
 246        test_cmp expected actual
 247'
 248
 249test_expect_success 'fmt-merge-msg -m' '
 250        echo "Sync with left" >expected &&
 251        cat >expected.log <<-EOF &&
 252        Sync with left
 253
 254        # By Another Author (3) and A U Thor (2)
 255        # Via Another Committer
 256        * ${apos}left${apos} of $(pwd):
 257          Left #5
 258          Left #4
 259          Left #3
 260          Common #2
 261          Common #1
 262        EOF
 263
 264        test_unconfig merge.log &&
 265        test_unconfig merge.summary &&
 266        git checkout master &&
 267        git fetch "$(pwd)" left &&
 268        git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
 269        git fmt-merge-msg --log -m "Sync with left" \
 270                                        <.git/FETCH_HEAD >actual.log &&
 271        test_config merge.log true &&
 272        git fmt-merge-msg -m "Sync with left" \
 273                                        <.git/FETCH_HEAD >actual.log-config &&
 274        git fmt-merge-msg --no-log -m "Sync with left" \
 275                                        <.git/FETCH_HEAD >actual.nolog &&
 276
 277        test_cmp expected actual &&
 278        test_cmp expected.log actual.log &&
 279        test_cmp expected.log actual.log-config &&
 280        test_cmp expected actual.nolog
 281'
 282
 283test_expect_success 'setup: expected shortlog for two branches' '
 284        cat >expected <<-EOF
 285        Merge branches ${apos}left${apos} and ${apos}right${apos}
 286
 287        # By Another Author (3) and A U Thor (2)
 288        # Via Another Committer
 289        * left:
 290          Left #5
 291          Left #4
 292          Left #3
 293          Common #2
 294          Common #1
 295
 296        * right:
 297          Right #5
 298          Right #4
 299          Right #3
 300          Common #2
 301          Common #1
 302        EOF
 303'
 304
 305test_expect_success 'shortlog for two branches' '
 306        test_config merge.log true &&
 307        test_unconfig merge.summary &&
 308        git checkout master &&
 309        test_tick &&
 310        git fetch . left right &&
 311        git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
 312
 313        test_unconfig merge.log &&
 314        test_config merge.summary true &&
 315        git checkout master &&
 316        test_tick &&
 317        git fetch . left right &&
 318        git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
 319
 320        test_config merge.log yes &&
 321        test_unconfig merge.summary &&
 322        git checkout master &&
 323        test_tick &&
 324        git fetch . left right &&
 325        git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
 326
 327        test_unconfig merge.log &&
 328        test_config merge.summary yes &&
 329        git checkout master &&
 330        test_tick &&
 331        git fetch . left right &&
 332        git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
 333
 334        test_cmp expected actual1 &&
 335        test_cmp expected actual2 &&
 336        test_cmp expected actual3 &&
 337        test_cmp expected actual4
 338'
 339
 340test_expect_success 'merge-msg -F' '
 341        test_unconfig merge.log &&
 342        test_config merge.summary yes &&
 343        git checkout master &&
 344        test_tick &&
 345        git fetch . left right &&
 346        git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
 347        test_cmp expected actual
 348'
 349
 350test_expect_success 'merge-msg -F in subdirectory' '
 351        test_unconfig merge.log &&
 352        test_config merge.summary yes &&
 353        git checkout master &&
 354        test_tick &&
 355        git fetch . left right &&
 356        mkdir sub &&
 357        cp .git/FETCH_HEAD sub/FETCH_HEAD &&
 358        (
 359                cd sub &&
 360                git fmt-merge-msg -F FETCH_HEAD >../actual
 361        ) &&
 362        test_cmp expected actual
 363'
 364
 365test_expect_success 'merge-msg with nothing to merge' '
 366        test_unconfig merge.log &&
 367        test_config merge.summary yes &&
 368
 369        >empty &&
 370
 371        (
 372                cd remote &&
 373                git checkout -b unrelated &&
 374                test_tick &&
 375                git fetch origin &&
 376                git fmt-merge-msg <.git/FETCH_HEAD >../actual
 377        ) &&
 378
 379        test_cmp empty actual
 380'
 381
 382test_expect_success 'merge-msg tag' '
 383        cat >expected <<-EOF &&
 384        Merge tag ${apos}tag-r3${apos}
 385
 386        * tag ${apos}tag-r3${apos}:
 387          Right #3
 388          Common #2
 389          Common #1
 390        EOF
 391
 392        test_unconfig merge.log &&
 393        test_config merge.summary yes &&
 394
 395        git checkout master &&
 396        test_tick &&
 397        git fetch . tag tag-r3 &&
 398
 399        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 400        test_cmp expected actual
 401'
 402
 403test_expect_success 'merge-msg two tags' '
 404        cat >expected <<-EOF &&
 405        Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
 406
 407        * tag ${apos}tag-r3${apos}:
 408          Right #3
 409          Common #2
 410          Common #1
 411
 412        # By Another Author (3) and A U Thor (2)
 413        # Via Another Committer
 414        * tag ${apos}tag-l5${apos}:
 415          Left #5
 416          Left #4
 417          Left #3
 418          Common #2
 419          Common #1
 420        EOF
 421
 422        test_unconfig merge.log &&
 423        test_config merge.summary yes &&
 424
 425        git checkout master &&
 426        test_tick &&
 427        git fetch . tag tag-r3 tag tag-l5 &&
 428
 429        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 430        test_cmp expected actual
 431'
 432
 433test_expect_success 'merge-msg tag and branch' '
 434        cat >expected <<-EOF &&
 435        Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
 436
 437        * tag ${apos}tag-r3${apos}:
 438          Right #3
 439          Common #2
 440          Common #1
 441
 442        # By Another Author (3) and A U Thor (2)
 443        # Via Another Committer
 444        * left:
 445          Left #5
 446          Left #4
 447          Left #3
 448          Common #2
 449          Common #1
 450        EOF
 451
 452        test_unconfig merge.log &&
 453        test_config merge.summary yes &&
 454
 455        git checkout master &&
 456        test_tick &&
 457        git fetch . tag tag-r3 left &&
 458
 459        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 460        test_cmp expected actual
 461'
 462
 463test_expect_success 'merge-msg lots of commits' '
 464        {
 465                cat <<-EOF &&
 466                Merge branch ${apos}long${apos}
 467
 468                * long: (35 commits)
 469                EOF
 470
 471                i=29 &&
 472                while test $i -gt 9
 473                do
 474                        echo "  $i" &&
 475                        i=$(($i-1))
 476                done &&
 477                echo "  ..."
 478        } >expected &&
 479
 480        test_config merge.summary yes &&
 481
 482        git checkout master &&
 483        test_tick &&
 484        git fetch . long &&
 485
 486        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 487        test_cmp expected actual
 488'
 489
 490test_expect_success 'merge-msg with "merging" an annotated tag' '
 491        test_config merge.log true &&
 492
 493        git checkout master^0 &&
 494        git commit --allow-empty -m "One step ahead" &&
 495        git tag -a -m "An annotated one" annote HEAD &&
 496
 497        git checkout master &&
 498        git fetch . annote &&
 499
 500        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 501        {
 502                cat <<-\EOF
 503                Merge tag '\''annote'\''
 504
 505                An annotated one
 506
 507                * tag '\''annote'\'':
 508                  One step ahead
 509                EOF
 510        } >expected &&
 511        test_cmp expected actual &&
 512
 513        test_when_finished "git reset --hard" &&
 514        annote=$(git rev-parse annote) &&
 515        git merge --no-commit --no-ff $annote &&
 516        {
 517                cat <<-EOF
 518                Merge tag '\''$annote'\''
 519
 520                An annotated one
 521
 522                * tag '\''$annote'\'':
 523                  One step ahead
 524                EOF
 525        } >expected &&
 526        test_cmp expected .git/MERGE_MSG
 527'
 528
 529test_done