t / t6200-fmt-merge-msg.shon commit Merge branch 'ch/maint-cannot-create-bundle-error' (d42cb58)
   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 'fmt-merge-msg -m' '
 133        echo "Sync with left" >expected &&
 134        cat >expected.log <<-EOF &&
 135        Sync with left
 136
 137        * ${apos}left${apos} of $(pwd):
 138          Left #5
 139          Left #4
 140          Left #3
 141          Common #2
 142          Common #1
 143        EOF
 144
 145        test_might_fail git config --unset merge.log &&
 146        test_might_fail git config --unset merge.summary &&
 147        git checkout master &&
 148        git fetch "$(pwd)" left &&
 149        git fmt-merge-msg -m "Sync with left" <.git/FETCH_HEAD >actual &&
 150        git fmt-merge-msg --log -m "Sync with left" \
 151                                        <.git/FETCH_HEAD >actual.log &&
 152        git config merge.log true &&
 153        git fmt-merge-msg -m "Sync with left" \
 154                                        <.git/FETCH_HEAD >actual.log-config &&
 155        git fmt-merge-msg --no-log -m "Sync with left" \
 156                                        <.git/FETCH_HEAD >actual.nolog &&
 157
 158        test_cmp expected actual &&
 159        test_cmp expected.log actual.log &&
 160        test_cmp expected.log actual.log-config &&
 161        test_cmp expected actual.nolog
 162'
 163
 164test_expect_success 'setup: expected shortlog for two branches' '
 165        cat >expected <<-EOF
 166        Merge branches ${apos}left${apos} and ${apos}right${apos}
 167
 168        * left:
 169          Left #5
 170          Left #4
 171          Left #3
 172          Common #2
 173          Common #1
 174
 175        * right:
 176          Right #5
 177          Right #4
 178          Right #3
 179          Common #2
 180          Common #1
 181        EOF
 182'
 183
 184test_expect_success 'shortlog for two branches' '
 185        git config merge.log true &&
 186        test_might_fail git config --unset-all merge.summary &&
 187        git checkout master &&
 188        test_tick &&
 189        git fetch . left right &&
 190        git fmt-merge-msg <.git/FETCH_HEAD >actual1 &&
 191
 192        test_might_fail git config --unset-all merge.log &&
 193        git config merge.summary true &&
 194        git checkout master &&
 195        test_tick &&
 196        git fetch . left right &&
 197        git fmt-merge-msg <.git/FETCH_HEAD >actual2 &&
 198
 199        git config merge.log yes &&
 200        test_might_fail git config --unset-all merge.summary &&
 201        git checkout master &&
 202        test_tick &&
 203        git fetch . left right &&
 204        git fmt-merge-msg <.git/FETCH_HEAD >actual3 &&
 205
 206        test_might_fail git config --unset-all merge.log &&
 207        git config merge.summary yes &&
 208        git checkout master &&
 209        test_tick &&
 210        git fetch . left right &&
 211        git fmt-merge-msg <.git/FETCH_HEAD >actual4 &&
 212
 213        test_cmp expected actual1 &&
 214        test_cmp expected actual2 &&
 215        test_cmp expected actual3 &&
 216        test_cmp expected actual4
 217'
 218
 219test_expect_success 'merge-msg -F' '
 220        test_might_fail git config --unset-all merge.log &&
 221        git config merge.summary yes &&
 222        git checkout master &&
 223        test_tick &&
 224        git fetch . left right &&
 225        git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
 226        test_cmp expected actual
 227'
 228
 229test_expect_success 'merge-msg -F in subdirectory' '
 230        test_might_fail git config --unset-all merge.log &&
 231        git config merge.summary yes &&
 232        git checkout master &&
 233        test_tick &&
 234        git fetch . left right &&
 235        mkdir sub &&
 236        cp .git/FETCH_HEAD sub/FETCH_HEAD &&
 237        (
 238                cd sub &&
 239                git fmt-merge-msg -F FETCH_HEAD >../actual
 240        ) &&
 241        test_cmp expected actual
 242'
 243
 244test_expect_success 'merge-msg with nothing to merge' '
 245        test_might_fail git config --unset-all merge.log &&
 246        git config merge.summary yes &&
 247
 248        >empty &&
 249
 250        (
 251                cd remote &&
 252                git checkout -b unrelated &&
 253                test_tick &&
 254                git fetch origin &&
 255                git fmt-merge-msg <.git/FETCH_HEAD >../actual
 256        ) &&
 257
 258        test_cmp empty actual
 259'
 260
 261test_expect_success 'merge-msg tag' '
 262        cat >expected <<-EOF &&
 263        Merge tag ${apos}tag-r3${apos}
 264
 265        * tag ${apos}tag-r3${apos}:
 266          Right #3
 267          Common #2
 268          Common #1
 269        EOF
 270
 271        test_might_fail git config --unset-all merge.log &&
 272        git config merge.summary yes &&
 273
 274        git checkout master &&
 275        test_tick &&
 276        git fetch . tag tag-r3 &&
 277
 278        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 279        test_cmp expected actual
 280'
 281
 282test_expect_success 'merge-msg two tags' '
 283        cat >expected <<-EOF &&
 284        Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos}
 285
 286        * tag ${apos}tag-r3${apos}:
 287          Right #3
 288          Common #2
 289          Common #1
 290
 291        * tag ${apos}tag-l5${apos}:
 292          Left #5
 293          Left #4
 294          Left #3
 295          Common #2
 296          Common #1
 297        EOF
 298
 299        test_might_fail git config --unset-all merge.log &&
 300        git config merge.summary yes &&
 301
 302        git checkout master &&
 303        test_tick &&
 304        git fetch . tag tag-r3 tag tag-l5 &&
 305
 306        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 307        test_cmp expected actual
 308'
 309
 310test_expect_success 'merge-msg tag and branch' '
 311        cat >expected <<-EOF &&
 312        Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos}
 313
 314        * tag ${apos}tag-r3${apos}:
 315          Right #3
 316          Common #2
 317          Common #1
 318
 319        * left:
 320          Left #5
 321          Left #4
 322          Left #3
 323          Common #2
 324          Common #1
 325        EOF
 326
 327        test_might_fail git config --unset-all merge.log &&
 328        git config merge.summary yes &&
 329
 330        git checkout master &&
 331        test_tick &&
 332        git fetch . tag tag-r3 left &&
 333
 334        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 335        test_cmp expected actual
 336'
 337
 338test_expect_success 'merge-msg lots of commits' '
 339        {
 340                cat <<-EOF &&
 341                Merge branch ${apos}long${apos}
 342
 343                * long: (35 commits)
 344                EOF
 345
 346                i=29 &&
 347                while test $i -gt 9
 348                do
 349                        echo "  $i" &&
 350                        i=$(($i-1))
 351                done &&
 352                echo "  ..."
 353        } >expected &&
 354
 355        git checkout master &&
 356        test_tick &&
 357        git fetch . long &&
 358
 359        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
 360        test_cmp expected actual
 361'
 362
 363test_done