t / t6200-fmt-merge-msg.shon commit Merge branch 'ap/combine-diff-coalesce-lost' (a15696b)
   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 'merge.log=0 disables shortlog' '
 179        echo "Merge branch ${apos}left${apos}" >expected
 180        git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
 181        test_cmp expected actual
 182'
 183
 184test_expect_success '--log=3 limits shortlog length' '
 185        cat >expected <<-EOF &&
 186        Merge branch ${apos}left${apos}
 187
 188        # By Another Author (3) and A U Thor (2)
 189        # Via Another Committer
 190        * left: (5 commits)
 191          Left #5
 192          Left #4
 193          Left #3
 194          ...
 195        EOF
 196
 197        git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
 198        test_cmp expected actual
 199'
 200
 201test_expect_success '--log=5 shows all 5 commits' '
 202        cat >expected <<-EOF &&
 203        Merge branch ${apos}left${apos}
 204
 205        # By Another Author (3) and A U Thor (2)
 206        # Via Another Committer
 207        * left:
 208          Left #5
 209          Left #4
 210          Left #3
 211          Common #2
 212          Common #1
 213        EOF
 214
 215        git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
 216        test_cmp expected actual
 217'
 218
 219test_expect_success '--no-log disables shortlog' '
 220        echo "Merge branch ${apos}left${apos}" >expected &&
 221        git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
 222        test_cmp expected actual
 223'
 224
 225test_expect_success '--log=0 disables shortlog' '
 226        echo "Merge branch ${apos}left${apos}" >expected &&
 227        git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
 228        test_cmp expected actual
 229'
 230
 231test_expect_success 'fmt-merge-msg -m' '
 232        echo "Sync with left" >expected &&
 233        cat >expected.log <<-EOF &&
 234        Sync with left
 235
 236        # By Another Author (3) and A U Thor (2)
 237        # Via Another Committer
 238        * ${apos}left${apos} of $(pwd):
 239          Left #5
 240          Left #4
 241          Left #3
 242          Common #2
 243          Common #1
 244        EOF
 245
 246        test_unconfig merge.log &&
 247        test_unconfig merge.summary &&
 248        git checkout master &&
 249        git fetch "$(pwd)" left &&
 250        git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
 251        git fmt-merge-msg --log -m "Sync with left" \
 252                                        <.git/FETCH_HEAD >actual.log &&
 253        test_config merge.log true &&
 254        git fmt-merge-msg -m "Sync with left" \
 255                                        <.git/FETCH_HEAD >actual.log-config &&
 256        git fmt-merge-msg --no-log -m "Sync with left" \
 257                                        <.git/FETCH_HEAD >actual.nolog &&
 258
 259        test_cmp expected actual &&
 260        test_cmp expected.log actual.log &&
 261        test_cmp expected.log actual.log-config &&
 262        test_cmp expected actual.nolog
 263'
 264
 265test_expect_success 'setup: expected shortlog for two branches' '
 266        cat >expected <<-EOF
 267        Merge branches ${apos}left${apos} and ${apos}right${apos}
 268
 269        # By Another Author (3) and A U Thor (2)
 270        # Via Another Committer
 271        * left:
 272          Left #5
 273          Left #4
 274          Left #3
 275          Common #2
 276          Common #1
 277
 278        * right:
 279          Right #5
 280          Right #4
 281          Right #3
 282          Common #2
 283          Common #1
 284        EOF
 285'
 286
 287test_expect_success 'shortlog for two branches' '
 288        test_config merge.log true &&
 289        test_unconfig merge.summary &&
 290        git checkout master &&
 291        test_tick &&
 292        git fetch . left right &&
 293        git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
 294
 295        test_unconfig merge.log &&
 296        test_config merge.summary true &&
 297        git checkout master &&
 298        test_tick &&
 299        git fetch . left right &&
 300        git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
 301
 302        test_config merge.log yes &&
 303        test_unconfig merge.summary &&
 304        git checkout master &&
 305        test_tick &&
 306        git fetch . left right &&
 307        git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
 308
 309        test_unconfig merge.log &&
 310        test_config merge.summary yes &&
 311        git checkout master &&
 312        test_tick &&
 313        git fetch . left right &&
 314        git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
 315
 316        test_cmp expected actual1 &&
 317        test_cmp expected actual2 &&
 318        test_cmp expected actual3 &&
 319        test_cmp expected actual4
 320'
 321
 322test_expect_success 'merge-msg -F' '
 323        test_unconfig merge.log &&
 324        test_config merge.summary yes &&
 325        git checkout master &&
 326        test_tick &&
 327        git fetch . left right &&
 328        git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
 329        test_cmp expected actual
 330'
 331
 332test_expect_success 'merge-msg -F in subdirectory' '
 333        test_unconfig merge.log &&
 334        test_config merge.summary yes &&
 335        git checkout master &&
 336        test_tick &&
 337        git fetch . left right &&
 338        mkdir sub &&
 339        cp .git/FETCH_HEAD sub/FETCH_HEAD &&
 340        (
 341                cd sub &&
 342                git fmt-merge-msg -F FETCH_HEAD >../actual
 343        ) &&
 344        test_cmp expected actual
 345'
 346
 347test_expect_success 'merge-msg with nothing to merge' '
 348        test_unconfig merge.log &&
 349        test_config merge.summary yes &&
 350
 351        >empty &&
 352
 353        (
 354                cd remote &&
 355                git checkout -b unrelated &&
 356                test_tick &&
 357                git fetch origin &&
 358                git fmt-merge-msg <.git/FETCH_HEAD >../actual
 359        ) &&
 360
 361        test_cmp empty actual
 362'
 363
 364test_expect_success 'merge-msg tag' '
 365        cat >expected <<-EOF &&
 366        Merge tag ${apos}tag-r3${apos}
 367
 368        * tag ${apos}tag-r3${apos}:
 369          Right #3
 370          Common #2
 371          Common #1
 372        EOF
 373
 374        test_unconfig merge.log &&
 375        test_config merge.summary yes &&
 376
 377        git checkout master &&
 378        test_tick &&
 379        git fetch . tag tag-r3 &&
 380
 381        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 382        test_cmp expected actual
 383'
 384
 385test_expect_success 'merge-msg two tags' '
 386        cat >expected <<-EOF &&
 387        Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
 388
 389        * tag ${apos}tag-r3${apos}:
 390          Right #3
 391          Common #2
 392          Common #1
 393
 394        # By Another Author (3) and A U Thor (2)
 395        # Via Another Committer
 396        * tag ${apos}tag-l5${apos}:
 397          Left #5
 398          Left #4
 399          Left #3
 400          Common #2
 401          Common #1
 402        EOF
 403
 404        test_unconfig merge.log &&
 405        test_config merge.summary yes &&
 406
 407        git checkout master &&
 408        test_tick &&
 409        git fetch . tag tag-r3 tag tag-l5 &&
 410
 411        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 412        test_cmp expected actual
 413'
 414
 415test_expect_success 'merge-msg tag and branch' '
 416        cat >expected <<-EOF &&
 417        Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
 418
 419        * tag ${apos}tag-r3${apos}:
 420          Right #3
 421          Common #2
 422          Common #1
 423
 424        # By Another Author (3) and A U Thor (2)
 425        # Via Another Committer
 426        * left:
 427          Left #5
 428          Left #4
 429          Left #3
 430          Common #2
 431          Common #1
 432        EOF
 433
 434        test_unconfig merge.log &&
 435        test_config merge.summary yes &&
 436
 437        git checkout master &&
 438        test_tick &&
 439        git fetch . tag tag-r3 left &&
 440
 441        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 442        test_cmp expected actual
 443'
 444
 445test_expect_success 'merge-msg lots of commits' '
 446        {
 447                cat <<-EOF &&
 448                Merge branch ${apos}long${apos}
 449
 450                * long: (35 commits)
 451                EOF
 452
 453                i=29 &&
 454                while test $i -gt 9
 455                do
 456                        echo "  $i" &&
 457                        i=$(($i-1))
 458                done &&
 459                echo "  ..."
 460        } >expected &&
 461
 462        test_config merge.summary yes &&
 463
 464        git checkout master &&
 465        test_tick &&
 466        git fetch . long &&
 467
 468        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 469        test_cmp expected actual
 470'
 471
 472test_expect_success 'merge-msg with "merging" an annotated tag' '
 473        test_config merge.log true &&
 474
 475        git checkout master^0 &&
 476        git commit --allow-empty -m "One step ahead" &&
 477        git tag -a -m "An annotated one" annote HEAD &&
 478
 479        git checkout master &&
 480        git fetch . annote &&
 481
 482        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 483        {
 484                cat <<-\EOF
 485                Merge tag '\''annote'\''
 486
 487                An annotated one
 488
 489                * tag '\''annote'\'':
 490                  One step ahead
 491                EOF
 492        } >expected &&
 493        test_cmp expected actual &&
 494
 495        test_when_finished "git reset --hard" &&
 496        annote=$(git rev-parse annote) &&
 497        git merge --no-commit $annote &&
 498        {
 499                cat <<-EOF
 500                Merge tag '\''$annote'\''
 501
 502                An annotated one
 503
 504                * tag '\''$annote'\'':
 505                  One step ahead
 506                EOF
 507        } >expected &&
 508        test_cmp expected .git/MERGE_MSG
 509'
 510
 511test_done