9b600a8717aaafca9fb8308c461e441af83e367b
   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 'fmt-merge-msg -m' '
 181        echo "Sync with left" >expected &&
 182        cat >expected.log <<-EOF &&
 183        Sync with left
 184
 185        * ${apos}left${apos} of $(pwd):
 186          Left #5
 187          Left #4
 188          Left #3
 189          Common #2
 190          Common #1
 191        EOF
 192
 193        test_might_fail git config --unset merge.log &&
 194        test_might_fail git config --unset merge.summary &&
 195        git checkout master &&
 196        git fetch "$(pwd)" left &&
 197        git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
 198        git fmt-merge-msg --log -m "Sync with left" \
 199                                        <.git/FETCH_HEAD >actual.log &&
 200        git config merge.log true &&
 201        git fmt-merge-msg -m "Sync with left" \
 202                                        <.git/FETCH_HEAD >actual.log-config &&
 203        git fmt-merge-msg --no-log -m "Sync with left" \
 204                                        <.git/FETCH_HEAD >actual.nolog &&
 205
 206        test_cmp expected actual &&
 207        test_cmp expected.log actual.log &&
 208        test_cmp expected.log actual.log-config &&
 209        test_cmp expected actual.nolog
 210'
 211
 212test_expect_success 'setup: expected shortlog for two branches' '
 213        cat >expected <<-EOF
 214        Merge branches ${apos}left${apos} and ${apos}right${apos}
 215
 216        * left:
 217          Left #5
 218          Left #4
 219          Left #3
 220          Common #2
 221          Common #1
 222
 223        * right:
 224          Right #5
 225          Right #4
 226          Right #3
 227          Common #2
 228          Common #1
 229        EOF
 230'
 231
 232test_expect_success 'shortlog for two branches' '
 233        git config merge.log true &&
 234        test_might_fail git config --unset-all merge.summary &&
 235        git checkout master &&
 236        test_tick &&
 237        git fetch . left right &&
 238        git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
 239
 240        test_might_fail git config --unset-all merge.log &&
 241        git config merge.summary true &&
 242        git checkout master &&
 243        test_tick &&
 244        git fetch . left right &&
 245        git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
 246
 247        git config merge.log yes &&
 248        test_might_fail git config --unset-all merge.summary &&
 249        git checkout master &&
 250        test_tick &&
 251        git fetch . left right &&
 252        git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
 253
 254        test_might_fail git config --unset-all merge.log &&
 255        git config merge.summary yes &&
 256        git checkout master &&
 257        test_tick &&
 258        git fetch . left right &&
 259        git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
 260
 261        test_cmp expected actual1 &&
 262        test_cmp expected actual2 &&
 263        test_cmp expected actual3 &&
 264        test_cmp expected actual4
 265'
 266
 267test_expect_success 'merge-msg -F' '
 268        test_might_fail git config --unset-all merge.log &&
 269        git config merge.summary yes &&
 270        git checkout master &&
 271        test_tick &&
 272        git fetch . left right &&
 273        git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
 274        test_cmp expected actual
 275'
 276
 277test_expect_success 'merge-msg -F in subdirectory' '
 278        test_might_fail git config --unset-all merge.log &&
 279        git config merge.summary yes &&
 280        git checkout master &&
 281        test_tick &&
 282        git fetch . left right &&
 283        mkdir sub &&
 284        cp .git/FETCH_HEAD sub/FETCH_HEAD &&
 285        (
 286                cd sub &&
 287                git fmt-merge-msg -F FETCH_HEAD >../actual
 288        ) &&
 289        test_cmp expected actual
 290'
 291
 292test_expect_success 'merge-msg with nothing to merge' '
 293        test_might_fail git config --unset-all merge.log &&
 294        git config merge.summary yes &&
 295
 296        >empty &&
 297
 298        (
 299                cd remote &&
 300                git checkout -b unrelated &&
 301                test_tick &&
 302                git fetch origin &&
 303                git fmt-merge-msg <.git/FETCH_HEAD >../actual
 304        ) &&
 305
 306        test_cmp empty actual
 307'
 308
 309test_expect_success 'merge-msg tag' '
 310        cat >expected <<-EOF &&
 311        Merge tag ${apos}tag-r3${apos}
 312
 313        * tag ${apos}tag-r3${apos}:
 314          Right #3
 315          Common #2
 316          Common #1
 317        EOF
 318
 319        test_might_fail git config --unset-all merge.log &&
 320        git config merge.summary yes &&
 321
 322        git checkout master &&
 323        test_tick &&
 324        git fetch . tag tag-r3 &&
 325
 326        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 327        test_cmp expected actual
 328'
 329
 330test_expect_success 'merge-msg two tags' '
 331        cat >expected <<-EOF &&
 332        Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
 333
 334        * tag ${apos}tag-r3${apos}:
 335          Right #3
 336          Common #2
 337          Common #1
 338
 339        * tag ${apos}tag-l5${apos}:
 340          Left #5
 341          Left #4
 342          Left #3
 343          Common #2
 344          Common #1
 345        EOF
 346
 347        test_might_fail git config --unset-all merge.log &&
 348        git config merge.summary yes &&
 349
 350        git checkout master &&
 351        test_tick &&
 352        git fetch . tag tag-r3 tag tag-l5 &&
 353
 354        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 355        test_cmp expected actual
 356'
 357
 358test_expect_success 'merge-msg tag and branch' '
 359        cat >expected <<-EOF &&
 360        Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
 361
 362        * tag ${apos}tag-r3${apos}:
 363          Right #3
 364          Common #2
 365          Common #1
 366
 367        * left:
 368          Left #5
 369          Left #4
 370          Left #3
 371          Common #2
 372          Common #1
 373        EOF
 374
 375        test_might_fail git config --unset-all merge.log &&
 376        git config merge.summary yes &&
 377
 378        git checkout master &&
 379        test_tick &&
 380        git fetch . tag tag-r3 left &&
 381
 382        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 383        test_cmp expected actual
 384'
 385
 386test_expect_success 'merge-msg lots of commits' '
 387        {
 388                cat <<-EOF &&
 389                Merge branch ${apos}long${apos}
 390
 391                * long: (35 commits)
 392                EOF
 393
 394                i=29 &&
 395                while test $i -gt 9
 396                do
 397                        echo "  $i" &&
 398                        i=$(($i-1))
 399                done &&
 400                echo "  ..."
 401        } >expected &&
 402
 403        git checkout master &&
 404        test_tick &&
 405        git fetch . long &&
 406
 407        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 408        test_cmp expected actual
 409'
 410
 411test_done