t / t6200-fmt-merge-msg.shon commit show: use streaming API for showing blobs (74775a0)
   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 commit -a -m "Left #3" &&
  39
  40        echo "l4" >two &&
  41        test_tick &&
  42        git commit -a -m "Left #4" &&
  43
  44        echo "l5" >two &&
  45        test_tick &&
  46        git commit -a -m "Left #5" &&
  47        git tag tag-l5 &&
  48
  49        git checkout right &&
  50
  51        echo "r3" >three &&
  52        git add three &&
  53        test_tick &&
  54        git commit -a -m "Right #3" &&
  55        git tag tag-r3 &&
  56
  57        echo "r4" >three &&
  58        test_tick &&
  59        git commit -a -m "Right #4" &&
  60
  61        echo "r5" >three &&
  62        test_tick &&
  63        git commit -a -m "Right #5" &&
  64
  65        git checkout -b long &&
  66        i=0 &&
  67        while test $i -lt 30
  68        do
  69                test_commit $i one &&
  70                i=$(($i+1))
  71        done &&
  72
  73        git show-branch &&
  74
  75        apos="'\''"
  76'
  77
  78test_expect_success 'message for merging local branch' '
  79        echo "Merge branch ${apos}left${apos}" >expected &&
  80
  81        git checkout master &&
  82        git fetch . left &&
  83
  84        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
  85        test_cmp expected actual
  86'
  87
  88test_expect_success 'message for merging external branch' '
  89        echo "Merge branch ${apos}left${apos} of $(pwd)" >expected &&
  90
  91        git checkout master &&
  92        git fetch "$(pwd)" left &&
  93
  94        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
  95        test_cmp expected actual
  96'
  97
  98test_expect_success '[merge] summary/log configuration' '
  99        cat >expected <<-EOF &&
 100        Merge branch ${apos}left${apos}
 101
 102        * left:
 103          Left #5
 104          Left #4
 105          Left #3
 106          Common #2
 107          Common #1
 108        EOF
 109
 110        git config merge.log true &&
 111        test_might_fail git config --unset-all 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_might_fail git config --unset-all merge.log &&
 120        git 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: clear [merge] configuration' '
 133        test_might_fail git config --unset-all merge.log &&
 134        test_might_fail git config --unset-all merge.summary
 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        * left: (5 commits)
 148          Left #5
 149          Left #4
 150          Left #3
 151          ...
 152        EOF
 153
 154        git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual &&
 155        test_cmp expected actual
 156'
 157
 158test_expect_success 'merge.log=5 shows all 5 commits' '
 159        cat >expected <<-EOF &&
 160        Merge branch ${apos}left${apos}
 161
 162        * left:
 163          Left #5
 164          Left #4
 165          Left #3
 166          Common #2
 167          Common #1
 168        EOF
 169
 170        git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual &&
 171        test_cmp expected actual
 172'
 173
 174test_expect_success 'merge.log=0 disables shortlog' '
 175        echo "Merge branch ${apos}left${apos}" >expected
 176        git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual &&
 177        test_cmp expected actual
 178'
 179
 180test_expect_success '--log=3 limits shortlog length' '
 181        cat >expected <<-EOF &&
 182        Merge branch ${apos}left${apos}
 183
 184        * left: (5 commits)
 185          Left #5
 186          Left #4
 187          Left #3
 188          ...
 189        EOF
 190
 191        git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual &&
 192        test_cmp expected actual
 193'
 194
 195test_expect_success '--log=5 shows all 5 commits' '
 196        cat >expected <<-EOF &&
 197        Merge branch ${apos}left${apos}
 198
 199        * left:
 200          Left #5
 201          Left #4
 202          Left #3
 203          Common #2
 204          Common #1
 205        EOF
 206
 207        git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual &&
 208        test_cmp expected actual
 209'
 210
 211test_expect_success '--no-log disables shortlog' '
 212        echo "Merge branch ${apos}left${apos}" >expected &&
 213        git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
 214        test_cmp expected actual
 215'
 216
 217test_expect_success '--log=0 disables shortlog' '
 218        echo "Merge branch ${apos}left${apos}" >expected &&
 219        git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual &&
 220        test_cmp expected actual
 221'
 222
 223test_expect_success 'fmt-merge-msg -m' '
 224        echo "Sync with left" >expected &&
 225        cat >expected.log <<-EOF &&
 226        Sync with left
 227
 228        * ${apos}left${apos} of $(pwd):
 229          Left #5
 230          Left #4
 231          Left #3
 232          Common #2
 233          Common #1
 234        EOF
 235
 236        test_might_fail git config --unset merge.log &&
 237        test_might_fail git config --unset merge.summary &&
 238        git checkout master &&
 239        git fetch "$(pwd)" left &&
 240        git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
 241        git fmt-merge-msg --log -m "Sync with left" \
 242                                        <.git/FETCH_HEAD >actual.log &&
 243        git config merge.log true &&
 244        git fmt-merge-msg -m "Sync with left" \
 245                                        <.git/FETCH_HEAD >actual.log-config &&
 246        git fmt-merge-msg --no-log -m "Sync with left" \
 247                                        <.git/FETCH_HEAD >actual.nolog &&
 248
 249        test_cmp expected actual &&
 250        test_cmp expected.log actual.log &&
 251        test_cmp expected.log actual.log-config &&
 252        test_cmp expected actual.nolog
 253'
 254
 255test_expect_success 'setup: expected shortlog for two branches' '
 256        cat >expected <<-EOF
 257        Merge branches ${apos}left${apos} and ${apos}right${apos}
 258
 259        * left:
 260          Left #5
 261          Left #4
 262          Left #3
 263          Common #2
 264          Common #1
 265
 266        * right:
 267          Right #5
 268          Right #4
 269          Right #3
 270          Common #2
 271          Common #1
 272        EOF
 273'
 274
 275test_expect_success 'shortlog for two branches' '
 276        git config merge.log true &&
 277        test_might_fail git config --unset-all merge.summary &&
 278        git checkout master &&
 279        test_tick &&
 280        git fetch . left right &&
 281        git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
 282
 283        test_might_fail git config --unset-all merge.log &&
 284        git config merge.summary true &&
 285        git checkout master &&
 286        test_tick &&
 287        git fetch . left right &&
 288        git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
 289
 290        git config merge.log yes &&
 291        test_might_fail git config --unset-all merge.summary &&
 292        git checkout master &&
 293        test_tick &&
 294        git fetch . left right &&
 295        git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
 296
 297        test_might_fail git config --unset-all merge.log &&
 298        git config merge.summary yes &&
 299        git checkout master &&
 300        test_tick &&
 301        git fetch . left right &&
 302        git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
 303
 304        test_cmp expected actual1 &&
 305        test_cmp expected actual2 &&
 306        test_cmp expected actual3 &&
 307        test_cmp expected actual4
 308'
 309
 310test_expect_success 'merge-msg -F' '
 311        test_might_fail git config --unset-all merge.log &&
 312        git config merge.summary yes &&
 313        git checkout master &&
 314        test_tick &&
 315        git fetch . left right &&
 316        git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
 317        test_cmp expected actual
 318'
 319
 320test_expect_success 'merge-msg -F in subdirectory' '
 321        test_might_fail git config --unset-all merge.log &&
 322        git config merge.summary yes &&
 323        git checkout master &&
 324        test_tick &&
 325        git fetch . left right &&
 326        mkdir sub &&
 327        cp .git/FETCH_HEAD sub/FETCH_HEAD &&
 328        (
 329                cd sub &&
 330                git fmt-merge-msg -F FETCH_HEAD >../actual
 331        ) &&
 332        test_cmp expected actual
 333'
 334
 335test_expect_success 'merge-msg with nothing to merge' '
 336        test_might_fail git config --unset-all merge.log &&
 337        git config merge.summary yes &&
 338
 339        >empty &&
 340
 341        (
 342                cd remote &&
 343                git checkout -b unrelated &&
 344                test_tick &&
 345                git fetch origin &&
 346                git fmt-merge-msg <.git/FETCH_HEAD >../actual
 347        ) &&
 348
 349        test_cmp empty actual
 350'
 351
 352test_expect_success 'merge-msg tag' '
 353        cat >expected <<-EOF &&
 354        Merge tag ${apos}tag-r3${apos}
 355
 356        * tag ${apos}tag-r3${apos}:
 357          Right #3
 358          Common #2
 359          Common #1
 360        EOF
 361
 362        test_might_fail git config --unset-all merge.log &&
 363        git config merge.summary yes &&
 364
 365        git checkout master &&
 366        test_tick &&
 367        git fetch . tag tag-r3 &&
 368
 369        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 370        test_cmp expected actual
 371'
 372
 373test_expect_success 'merge-msg two tags' '
 374        cat >expected <<-EOF &&
 375        Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
 376
 377        * tag ${apos}tag-r3${apos}:
 378          Right #3
 379          Common #2
 380          Common #1
 381
 382        * tag ${apos}tag-l5${apos}:
 383          Left #5
 384          Left #4
 385          Left #3
 386          Common #2
 387          Common #1
 388        EOF
 389
 390        test_might_fail git config --unset-all merge.log &&
 391        git config merge.summary yes &&
 392
 393        git checkout master &&
 394        test_tick &&
 395        git fetch . tag tag-r3 tag tag-l5 &&
 396
 397        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 398        test_cmp expected actual
 399'
 400
 401test_expect_success 'merge-msg tag and branch' '
 402        cat >expected <<-EOF &&
 403        Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
 404
 405        * tag ${apos}tag-r3${apos}:
 406          Right #3
 407          Common #2
 408          Common #1
 409
 410        * left:
 411          Left #5
 412          Left #4
 413          Left #3
 414          Common #2
 415          Common #1
 416        EOF
 417
 418        test_might_fail git config --unset-all merge.log &&
 419        git config merge.summary yes &&
 420
 421        git checkout master &&
 422        test_tick &&
 423        git fetch . tag tag-r3 left &&
 424
 425        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 426        test_cmp expected actual
 427'
 428
 429test_expect_success 'merge-msg lots of commits' '
 430        {
 431                cat <<-EOF &&
 432                Merge branch ${apos}long${apos}
 433
 434                * long: (35 commits)
 435                EOF
 436
 437                i=29 &&
 438                while test $i -gt 9
 439                do
 440                        echo "  $i" &&
 441                        i=$(($i-1))
 442                done &&
 443                echo "  ..."
 444        } >expected &&
 445
 446        git checkout master &&
 447        test_tick &&
 448        git fetch . long &&
 449
 450        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 451        test_cmp expected actual
 452'
 453
 454test_done