t / t5510-fetch.shon commit diff --stat: add a test for output with COLUMNS=40 (c4432d5)
   1#!/bin/sh
   2# Copyright (c) 2006, Junio C Hamano.
   3
   4test_description='Per branch config variables affects "git fetch".
   5
   6'
   7
   8. ./test-lib.sh
   9
  10D=`pwd`
  11
  12test_bundle_object_count () {
  13        git verify-pack -v "$1" >verify.out &&
  14        test "$2" = $(grep '^[0-9a-f]\{40\} ' verify.out | wc -l)
  15}
  16
  17test_expect_success setup '
  18        echo >file original &&
  19        git add file &&
  20        git commit -a -m original'
  21
  22test_expect_success "clone and setup child repos" '
  23        git clone . one &&
  24        (
  25                cd one &&
  26                echo >file updated by one &&
  27                git commit -a -m "updated by one"
  28        ) &&
  29        git clone . two &&
  30        (
  31                cd two &&
  32                git config branch.master.remote one &&
  33                git config remote.one.url ../one/.git/ &&
  34                git config remote.one.fetch refs/heads/master:refs/heads/one
  35        ) &&
  36        git clone . three &&
  37        (
  38                cd three &&
  39                git config branch.master.remote two &&
  40                git config branch.master.merge refs/heads/one &&
  41                mkdir -p .git/remotes &&
  42                {
  43                        echo "URL: ../two/.git/"
  44                        echo "Pull: refs/heads/master:refs/heads/two"
  45                        echo "Pull: refs/heads/one:refs/heads/one"
  46                } >.git/remotes/two
  47        ) &&
  48        git clone . bundle &&
  49        git clone . seven
  50'
  51
  52test_expect_success "fetch test" '
  53        cd "$D" &&
  54        echo >file updated by origin &&
  55        git commit -a -m "updated by origin" &&
  56        cd two &&
  57        git fetch &&
  58        test -f .git/refs/heads/one &&
  59        mine=`git rev-parse refs/heads/one` &&
  60        his=`cd ../one && git rev-parse refs/heads/master` &&
  61        test "z$mine" = "z$his"
  62'
  63
  64test_expect_success "fetch test for-merge" '
  65        cd "$D" &&
  66        cd three &&
  67        git fetch &&
  68        test -f .git/refs/heads/two &&
  69        test -f .git/refs/heads/one &&
  70        master_in_two=`cd ../two && git rev-parse master` &&
  71        one_in_two=`cd ../two && git rev-parse one` &&
  72        {
  73                echo "$one_in_two       "
  74                echo "$master_in_two    not-for-merge"
  75        } >expected &&
  76        cut -f -2 .git/FETCH_HEAD >actual &&
  77        test_cmp expected actual'
  78
  79test_expect_success 'fetch --prune on its own works as expected' '
  80        cd "$D" &&
  81        git clone . prune &&
  82        cd prune &&
  83        git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
  84
  85        git fetch --prune origin &&
  86        test_must_fail git rev-parse origin/extrabranch
  87'
  88
  89test_expect_success 'fetch --prune with a branch name keeps branches' '
  90        cd "$D" &&
  91        git clone . prune-branch &&
  92        cd prune-branch &&
  93        git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
  94
  95        git fetch --prune origin master &&
  96        git rev-parse origin/extrabranch
  97'
  98
  99test_expect_success 'fetch --prune with a namespace keeps other namespaces' '
 100        cd "$D" &&
 101        git clone . prune-namespace &&
 102        cd prune-namespace &&
 103
 104        git fetch --prune origin refs/heads/a/*:refs/remotes/origin/a/* &&
 105        git rev-parse origin/master
 106'
 107
 108test_expect_success 'fetch --prune --tags does not delete the remote-tracking branches' '
 109        cd "$D" &&
 110        git clone . prune-tags &&
 111        cd prune-tags &&
 112        git fetch origin refs/heads/master:refs/tags/sometag &&
 113
 114        git fetch --prune --tags origin &&
 115        git rev-parse origin/master &&
 116        test_must_fail git rev-parse somebranch
 117'
 118
 119test_expect_success 'fetch --prune --tags with branch does not delete other remote-tracking branches' '
 120        cd "$D" &&
 121        git clone . prune-tags-branch &&
 122        cd prune-tags-branch &&
 123        git fetch origin refs/heads/master:refs/remotes/origin/extrabranch &&
 124
 125        git fetch --prune --tags origin master &&
 126        git rev-parse origin/extrabranch
 127'
 128
 129test_expect_success 'fetch tags when there is no tags' '
 130
 131    cd "$D" &&
 132
 133    mkdir notags &&
 134    cd notags &&
 135    git init &&
 136
 137    git fetch -t ..
 138
 139'
 140
 141test_expect_success 'fetch following tags' '
 142
 143        cd "$D" &&
 144        git tag -a -m 'annotated' anno HEAD &&
 145        git tag light HEAD &&
 146
 147        mkdir four &&
 148        cd four &&
 149        git init &&
 150
 151        git fetch .. :track &&
 152        git show-ref --verify refs/tags/anno &&
 153        git show-ref --verify refs/tags/light
 154
 155'
 156
 157test_expect_success 'fetch must not resolve short tag name' '
 158
 159        cd "$D" &&
 160
 161        mkdir five &&
 162        cd five &&
 163        git init &&
 164
 165        test_must_fail git fetch .. anno:five
 166
 167'
 168
 169test_expect_success 'fetch can now resolve short remote name' '
 170
 171        cd "$D" &&
 172        git update-ref refs/remotes/six/HEAD HEAD &&
 173
 174        mkdir six &&
 175        cd six &&
 176        git init &&
 177
 178        git fetch .. six:six
 179'
 180
 181test_expect_success 'create bundle 1' '
 182        cd "$D" &&
 183        echo >file updated again by origin &&
 184        git commit -a -m "tip" &&
 185        git bundle create bundle1 master^..master
 186'
 187
 188test_expect_success 'header of bundle looks right' '
 189        head -n 1 "$D"/bundle1 | grep "^#" &&
 190        head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " &&
 191        head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " &&
 192        head -n 4 "$D"/bundle1 | grep "^$"
 193'
 194
 195test_expect_success 'create bundle 2' '
 196        cd "$D" &&
 197        git bundle create bundle2 master~2..master
 198'
 199
 200test_expect_success 'unbundle 1' '
 201        cd "$D/bundle" &&
 202        git checkout -b some-branch &&
 203        test_must_fail git fetch "$D/bundle1" master:master
 204'
 205
 206
 207test_expect_success 'bundle 1 has only 3 files ' '
 208        cd "$D" &&
 209        (
 210                while read x && test -n "$x"
 211                do
 212                        :;
 213                done
 214                cat
 215        ) <bundle1 >bundle.pack &&
 216        git index-pack bundle.pack &&
 217        test_bundle_object_count bundle.pack 3
 218'
 219
 220test_expect_success 'unbundle 2' '
 221        cd "$D/bundle" &&
 222        git fetch ../bundle2 master:master &&
 223        test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)"
 224'
 225
 226test_expect_success 'bundle does not prerequisite objects' '
 227        cd "$D" &&
 228        touch file2 &&
 229        git add file2 &&
 230        git commit -m add.file2 file2 &&
 231        git bundle create bundle3 -1 HEAD &&
 232        (
 233                while read x && test -n "$x"
 234                do
 235                        :;
 236                done
 237                cat
 238        ) <bundle3 >bundle.pack &&
 239        git index-pack bundle.pack &&
 240        test_bundle_object_count bundle.pack 3
 241'
 242
 243test_expect_success 'bundle should be able to create a full history' '
 244
 245        cd "$D" &&
 246        git tag -a -m '1.0' v1.0 master &&
 247        git bundle create bundle4 v1.0
 248
 249'
 250
 251! rsync --help > /dev/null 2> /dev/null &&
 252say 'Skipping rsync tests because rsync was not found' || {
 253test_expect_success 'fetch via rsync' '
 254        git pack-refs &&
 255        mkdir rsynced &&
 256        (cd rsynced &&
 257         git init --bare &&
 258         git fetch "rsync:$(pwd)/../.git" master:refs/heads/master &&
 259         git gc --prune &&
 260         test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
 261         git fsck --full)
 262'
 263
 264test_expect_success 'push via rsync' '
 265        mkdir rsynced2 &&
 266        (cd rsynced2 &&
 267         git init) &&
 268        (cd rsynced &&
 269         git push "rsync:$(pwd)/../rsynced2/.git" master) &&
 270        (cd rsynced2 &&
 271         git gc --prune &&
 272         test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
 273         git fsck --full)
 274'
 275
 276test_expect_success 'push via rsync' '
 277        mkdir rsynced3 &&
 278        (cd rsynced3 &&
 279         git init) &&
 280        git push --all "rsync:$(pwd)/rsynced3/.git" &&
 281        (cd rsynced3 &&
 282         test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
 283         git fsck --full)
 284'
 285}
 286
 287test_expect_success 'fetch with a non-applying branch.<name>.merge' '
 288        git config branch.master.remote yeti &&
 289        git config branch.master.merge refs/heads/bigfoot &&
 290        git config remote.blub.url one &&
 291        git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
 292        git fetch blub
 293'
 294
 295# URL supplied to fetch does not match the url of the configured branch's remote
 296test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [1]' '
 297        one_head=$(cd one && git rev-parse HEAD) &&
 298        this_head=$(git rev-parse HEAD) &&
 299        git update-ref -d FETCH_HEAD &&
 300        git fetch one &&
 301        test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
 302        test $this_head = "$(git rev-parse --verify HEAD)"
 303'
 304
 305# URL supplied to fetch matches the url of the configured branch's remote and
 306# the merge spec matches the branch the remote HEAD points to
 307test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [2]' '
 308        one_ref=$(cd one && git symbolic-ref HEAD) &&
 309        git config branch.master.remote blub &&
 310        git config branch.master.merge "$one_ref" &&
 311        git update-ref -d FETCH_HEAD &&
 312        git fetch one &&
 313        test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
 314        test $this_head = "$(git rev-parse --verify HEAD)"
 315'
 316
 317# URL supplied to fetch matches the url of the configured branch's remote, but
 318# the merge spec does not match the branch the remote HEAD points to
 319test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge [3]' '
 320        git config branch.master.merge "${one_ref}_not" &&
 321        git update-ref -d FETCH_HEAD &&
 322        git fetch one &&
 323        test $one_head = "$(git rev-parse --verify FETCH_HEAD)" &&
 324        test $this_head = "$(git rev-parse --verify HEAD)"
 325'
 326
 327# the strange name is: a\!'b
 328test_expect_success 'quoting of a strangely named repo' '
 329        test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
 330        cat result &&
 331        grep "fatal: '\''a\\\\!'\''b'\''" result
 332'
 333
 334test_expect_success 'bundle should record HEAD correctly' '
 335
 336        cd "$D" &&
 337        git bundle create bundle5 HEAD master &&
 338        git bundle list-heads bundle5 >actual &&
 339        for h in HEAD refs/heads/master
 340        do
 341                echo "$(git rev-parse --verify $h) $h"
 342        done >expect &&
 343        test_cmp expect actual
 344
 345'
 346
 347test_expect_success 'explicit fetch should not update tracking' '
 348
 349        cd "$D" &&
 350        git branch -f side &&
 351        (
 352                cd three &&
 353                o=$(git rev-parse --verify refs/remotes/origin/master) &&
 354                git fetch origin master &&
 355                n=$(git rev-parse --verify refs/remotes/origin/master) &&
 356                test "$o" = "$n" &&
 357                test_must_fail git rev-parse --verify refs/remotes/origin/side
 358        )
 359'
 360
 361test_expect_success 'explicit pull should not update tracking' '
 362
 363        cd "$D" &&
 364        git branch -f side &&
 365        (
 366                cd three &&
 367                o=$(git rev-parse --verify refs/remotes/origin/master) &&
 368                git pull origin master &&
 369                n=$(git rev-parse --verify refs/remotes/origin/master) &&
 370                test "$o" = "$n" &&
 371                test_must_fail git rev-parse --verify refs/remotes/origin/side
 372        )
 373'
 374
 375test_expect_success 'configured fetch updates tracking' '
 376
 377        cd "$D" &&
 378        git branch -f side &&
 379        (
 380                cd three &&
 381                o=$(git rev-parse --verify refs/remotes/origin/master) &&
 382                git fetch origin &&
 383                n=$(git rev-parse --verify refs/remotes/origin/master) &&
 384                test "$o" != "$n" &&
 385                git rev-parse --verify refs/remotes/origin/side
 386        )
 387'
 388
 389test_expect_success 'pushing nonexistent branch by mistake should not segv' '
 390
 391        cd "$D" &&
 392        test_must_fail git push seven no:no
 393
 394'
 395
 396test_expect_success 'auto tag following fetches minimum' '
 397
 398        cd "$D" &&
 399        git clone .git follow &&
 400        git checkout HEAD^0 &&
 401        (
 402                for i in 1 2 3 4 5 6 7
 403                do
 404                        echo $i >>file &&
 405                        git commit -m $i -a &&
 406                        git tag -a -m $i excess-$i || exit 1
 407                done
 408        ) &&
 409        git checkout master &&
 410        (
 411                cd follow &&
 412                git fetch
 413        )
 414'
 415
 416test_expect_success 'refuse to fetch into the current branch' '
 417
 418        test_must_fail git fetch . side:master
 419
 420'
 421
 422test_expect_success 'fetch into the current branch with --update-head-ok' '
 423
 424        git fetch --update-head-ok . side:master
 425
 426'
 427
 428test_expect_success 'fetch --dry-run' '
 429
 430        rm -f .git/FETCH_HEAD &&
 431        git fetch --dry-run . &&
 432        ! test -f .git/FETCH_HEAD
 433'
 434
 435test_expect_success "should be able to fetch with duplicate refspecs" '
 436        mkdir dups &&
 437        cd dups &&
 438        git init &&
 439        git config branch.master.remote three &&
 440        git config remote.three.url ../three/.git &&
 441        git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
 442        git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
 443        git fetch three
 444'
 445
 446test_done