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