t / t5510-fetch.shon commit t1302 (core.repositoryversion): style tweaks (8fe5aed)
   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 "$master_in_two    not-for-merge"
  74                echo "$one_in_two       "
  75        } >expected &&
  76        cut -f -2 .git/FETCH_HEAD >actual &&
  77        test_cmp expected actual'
  78
  79test_expect_success 'fetch tags when there is no tags' '
  80
  81    cd "$D" &&
  82
  83    mkdir notags &&
  84    cd notags &&
  85    git init &&
  86
  87    git fetch -t ..
  88
  89'
  90
  91test_expect_success 'fetch following tags' '
  92
  93        cd "$D" &&
  94        git tag -a -m 'annotated' anno HEAD &&
  95        git tag light HEAD &&
  96
  97        mkdir four &&
  98        cd four &&
  99        git init &&
 100
 101        git fetch .. :track &&
 102        git show-ref --verify refs/tags/anno &&
 103        git show-ref --verify refs/tags/light
 104
 105'
 106
 107test_expect_success 'fetch must not resolve short tag name' '
 108
 109        cd "$D" &&
 110
 111        mkdir five &&
 112        cd five &&
 113        git init &&
 114
 115        test_must_fail git fetch .. anno:five
 116
 117'
 118
 119test_expect_success 'fetch must not resolve short remote name' '
 120
 121        cd "$D" &&
 122        git update-ref refs/remotes/six/HEAD HEAD
 123
 124        mkdir six &&
 125        cd six &&
 126        git init &&
 127
 128        test_must_fail git fetch .. six:six
 129
 130'
 131
 132test_expect_success 'create bundle 1' '
 133        cd "$D" &&
 134        echo >file updated again by origin &&
 135        git commit -a -m "tip" &&
 136        git bundle create bundle1 master^..master
 137'
 138
 139test_expect_success 'header of bundle looks right' '
 140        head -n 1 "$D"/bundle1 | grep "^#" &&
 141        head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " &&
 142        head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " &&
 143        head -n 4 "$D"/bundle1 | grep "^$"
 144'
 145
 146test_expect_success 'create bundle 2' '
 147        cd "$D" &&
 148        git bundle create bundle2 master~2..master
 149'
 150
 151test_expect_success 'unbundle 1' '
 152        cd "$D/bundle" &&
 153        git checkout -b some-branch &&
 154        test_must_fail git fetch "$D/bundle1" master:master
 155'
 156
 157
 158test_expect_success 'bundle 1 has only 3 files ' '
 159        cd "$D" &&
 160        (
 161                while read x && test -n "$x"
 162                do
 163                        :;
 164                done
 165                cat
 166        ) <bundle1 >bundle.pack &&
 167        git index-pack bundle.pack &&
 168        test_bundle_object_count bundle.pack 3
 169'
 170
 171test_expect_success 'unbundle 2' '
 172        cd "$D/bundle" &&
 173        git fetch ../bundle2 master:master &&
 174        test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)"
 175'
 176
 177test_expect_success 'bundle does not prerequisite objects' '
 178        cd "$D" &&
 179        touch file2 &&
 180        git add file2 &&
 181        git commit -m add.file2 file2 &&
 182        git bundle create bundle3 -1 HEAD &&
 183        (
 184                while read x && test -n "$x"
 185                do
 186                        :;
 187                done
 188                cat
 189        ) <bundle3 >bundle.pack &&
 190        git index-pack bundle.pack &&
 191        test_bundle_object_count bundle.pack 3
 192'
 193
 194test_expect_success 'bundle should be able to create a full history' '
 195
 196        cd "$D" &&
 197        git tag -a -m '1.0' v1.0 master &&
 198        git bundle create bundle4 v1.0
 199
 200'
 201
 202! rsync --help > /dev/null 2> /dev/null &&
 203say 'Skipping rsync tests because rsync was not found' || {
 204test_expect_success 'fetch via rsync' '
 205        git pack-refs &&
 206        mkdir rsynced &&
 207        (cd rsynced &&
 208         git init --bare &&
 209         git fetch "rsync:$(pwd)/../.git" master:refs/heads/master &&
 210         git gc --prune &&
 211         test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
 212         git fsck --full)
 213'
 214
 215test_expect_success 'push via rsync' '
 216        mkdir rsynced2 &&
 217        (cd rsynced2 &&
 218         git init) &&
 219        (cd rsynced &&
 220         git push "rsync:$(pwd)/../rsynced2/.git" master) &&
 221        (cd rsynced2 &&
 222         git gc --prune &&
 223         test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
 224         git fsck --full)
 225'
 226
 227test_expect_success 'push via rsync' '
 228        mkdir rsynced3 &&
 229        (cd rsynced3 &&
 230         git init) &&
 231        git push --all "rsync:$(pwd)/rsynced3/.git" &&
 232        (cd rsynced3 &&
 233         test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
 234         git fsck --full)
 235'
 236}
 237
 238test_expect_success 'fetch with a non-applying branch.<name>.merge' '
 239        git config branch.master.remote yeti &&
 240        git config branch.master.merge refs/heads/bigfoot &&
 241        git config remote.blub.url one &&
 242        git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
 243        git fetch blub
 244'
 245
 246# the strange name is: a\!'b
 247test_expect_success 'quoting of a strangely named repo' '
 248        test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
 249        cat result &&
 250        grep "fatal: '\''a\\\\!'\''b'\''" result
 251'
 252
 253test_expect_success 'bundle should record HEAD correctly' '
 254
 255        cd "$D" &&
 256        git bundle create bundle5 HEAD master &&
 257        git bundle list-heads bundle5 >actual &&
 258        for h in HEAD refs/heads/master
 259        do
 260                echo "$(git rev-parse --verify $h) $h"
 261        done >expect &&
 262        test_cmp expect actual
 263
 264'
 265
 266test_expect_success 'explicit fetch should not update tracking' '
 267
 268        cd "$D" &&
 269        git branch -f side &&
 270        (
 271                cd three &&
 272                o=$(git rev-parse --verify refs/remotes/origin/master) &&
 273                git fetch origin master &&
 274                n=$(git rev-parse --verify refs/remotes/origin/master) &&
 275                test "$o" = "$n" &&
 276                test_must_fail git rev-parse --verify refs/remotes/origin/side
 277        )
 278'
 279
 280test_expect_success 'explicit pull should not update tracking' '
 281
 282        cd "$D" &&
 283        git branch -f side &&
 284        (
 285                cd three &&
 286                o=$(git rev-parse --verify refs/remotes/origin/master) &&
 287                git pull origin master &&
 288                n=$(git rev-parse --verify refs/remotes/origin/master) &&
 289                test "$o" = "$n" &&
 290                test_must_fail git rev-parse --verify refs/remotes/origin/side
 291        )
 292'
 293
 294test_expect_success 'configured fetch updates tracking' '
 295
 296        cd "$D" &&
 297        git branch -f side &&
 298        (
 299                cd three &&
 300                o=$(git rev-parse --verify refs/remotes/origin/master) &&
 301                git fetch origin &&
 302                n=$(git rev-parse --verify refs/remotes/origin/master) &&
 303                test "$o" != "$n" &&
 304                git rev-parse --verify refs/remotes/origin/side
 305        )
 306'
 307
 308test_expect_success 'pushing nonexistent branch by mistake should not segv' '
 309
 310        cd "$D" &&
 311        test_must_fail git push seven no:no
 312
 313'
 314
 315test_expect_success 'auto tag following fetches minimum' '
 316
 317        cd "$D" &&
 318        git clone .git follow &&
 319        git checkout HEAD^0 &&
 320        (
 321                for i in 1 2 3 4 5 6 7
 322                do
 323                        echo $i >>file &&
 324                        git commit -m $i -a &&
 325                        git tag -a -m $i excess-$i || exit 1
 326                done
 327        ) &&
 328        git checkout master &&
 329        (
 330                cd follow &&
 331                git fetch
 332        )
 333'
 334
 335test_expect_success 'refuse to fetch into the current branch' '
 336
 337        test_must_fail git fetch . side:master
 338
 339'
 340
 341test_expect_success 'fetch into the current branch with --update-head-ok' '
 342
 343        git fetch --update-head-ok . side:master
 344
 345'
 346
 347test_expect_success 'fetch --dry-run' '
 348
 349        rm -f .git/FETCH_HEAD &&
 350        git fetch --dry-run . &&
 351        ! test -f .git/FETCH_HEAD
 352'
 353
 354test_expect_success "should be able to fetch with duplicate refspecs" '
 355        mkdir dups &&
 356        cd dups &&
 357        git init &&
 358        git config branch.master.remote three &&
 359        git config remote.three.url ../three/.git &&
 360        git config remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
 361        git config --add remote.three.fetch +refs/heads/*:refs/remotes/origin/* &&
 362        git fetch three
 363'
 364
 365test_done