t / t5510-fetch.shon commit Add tests for git push'es mirror mode (8e806ad)
   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_expect_success setup '
  13        echo >file original &&
  14        git add file &&
  15        git commit -a -m original'
  16
  17test_expect_success "clone and setup child repos" '
  18        git clone . one &&
  19        cd one &&
  20        echo >file updated by one &&
  21        git commit -a -m "updated by one" &&
  22        cd .. &&
  23        git clone . two &&
  24        cd two &&
  25        git config branch.master.remote one &&
  26        git config remote.one.url ../one/.git/ &&
  27        git config remote.one.fetch refs/heads/master:refs/heads/one &&
  28        cd .. &&
  29        git clone . three &&
  30        cd three &&
  31        git config branch.master.remote two &&
  32        git config branch.master.merge refs/heads/one &&
  33        mkdir -p .git/remotes &&
  34        {
  35                echo "URL: ../two/.git/"
  36                echo "Pull: refs/heads/master:refs/heads/two"
  37                echo "Pull: refs/heads/one:refs/heads/one"
  38        } >.git/remotes/two &&
  39        cd .. &&
  40        git clone . bundle
  41'
  42
  43test_expect_success "fetch test" '
  44        cd "$D" &&
  45        echo >file updated by origin &&
  46        git commit -a -m "updated by origin" &&
  47        cd two &&
  48        git fetch &&
  49        test -f .git/refs/heads/one &&
  50        mine=`git rev-parse refs/heads/one` &&
  51        his=`cd ../one && git rev-parse refs/heads/master` &&
  52        test "z$mine" = "z$his"
  53'
  54
  55test_expect_success "fetch test for-merge" '
  56        cd "$D" &&
  57        cd three &&
  58        git fetch &&
  59        test -f .git/refs/heads/two &&
  60        test -f .git/refs/heads/one &&
  61        master_in_two=`cd ../two && git rev-parse master` &&
  62        one_in_two=`cd ../two && git rev-parse one` &&
  63        {
  64                echo "$master_in_two    not-for-merge"
  65                echo "$one_in_two       "
  66        } >expected &&
  67        cut -f -2 .git/FETCH_HEAD >actual &&
  68        diff expected actual'
  69
  70test_expect_success 'fetch tags when there is no tags' '
  71
  72    cd "$D" &&
  73
  74    mkdir notags &&
  75    cd notags &&
  76    git init &&
  77
  78    git fetch -t ..
  79
  80'
  81
  82test_expect_success 'fetch following tags' '
  83
  84        cd "$D" &&
  85        git tag -a -m 'annotated' anno HEAD &&
  86        git tag light HEAD &&
  87
  88        mkdir four &&
  89        cd four &&
  90        git init &&
  91
  92        git fetch .. :track &&
  93        git show-ref --verify refs/tags/anno &&
  94        git show-ref --verify refs/tags/light
  95
  96'
  97
  98test_expect_success 'create bundle 1' '
  99        cd "$D" &&
 100        echo >file updated again by origin &&
 101        git commit -a -m "tip" &&
 102        git bundle create bundle1 master^..master
 103'
 104
 105test_expect_success 'header of bundle looks right' '
 106        head -n 1 "$D"/bundle1 | grep "^#" &&
 107        head -n 2 "$D"/bundle1 | grep "^-[0-9a-f]\{40\} " &&
 108        head -n 3 "$D"/bundle1 | grep "^[0-9a-f]\{40\} " &&
 109        head -n 4 "$D"/bundle1 | grep "^$"
 110'
 111
 112test_expect_success 'create bundle 2' '
 113        cd "$D" &&
 114        git bundle create bundle2 master~2..master
 115'
 116
 117test_expect_failure 'unbundle 1' '
 118        cd "$D/bundle" &&
 119        git checkout -b some-branch &&
 120        git fetch "$D/bundle1" master:master
 121'
 122
 123test_expect_success 'bundle 1 has only 3 files ' '
 124        cd "$D" &&
 125        (
 126                while read x && test -n "$x"
 127                do
 128                        :;
 129                done
 130                cat
 131        ) <bundle1 >bundle.pack &&
 132        git index-pack bundle.pack &&
 133        verify=$(git verify-pack -v bundle.pack) &&
 134        test 4 = $(echo "$verify" | wc -l)
 135'
 136
 137test_expect_success 'unbundle 2' '
 138        cd "$D/bundle" &&
 139        git fetch ../bundle2 master:master &&
 140        test "tip" = "$(git log -1 --pretty=oneline master | cut -b42-)"
 141'
 142
 143test_expect_success 'bundle does not prerequisite objects' '
 144        cd "$D" &&
 145        touch file2 &&
 146        git add file2 &&
 147        git commit -m add.file2 file2 &&
 148        git bundle create bundle3 -1 HEAD &&
 149        (
 150                while read x && test -n "$x"
 151                do
 152                        :;
 153                done
 154                cat
 155        ) <bundle3 >bundle.pack &&
 156        git index-pack bundle.pack &&
 157        test 4 = $(git verify-pack -v bundle.pack | wc -l)
 158'
 159
 160test_expect_success 'bundle should be able to create a full history' '
 161
 162        cd "$D" &&
 163        git tag -a -m '1.0' v1.0 master &&
 164        git bundle create bundle4 v1.0
 165
 166'
 167
 168test "$TEST_RSYNC" && {
 169test_expect_success 'fetch via rsync' '
 170        git pack-refs &&
 171        mkdir rsynced &&
 172        cd rsynced &&
 173        git init &&
 174        git fetch rsync://127.0.0.1$(pwd)/../.git master:refs/heads/master &&
 175        git gc --prune &&
 176        test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
 177        git fsck --full
 178'
 179
 180test_expect_success 'push via rsync' '
 181        mkdir ../rsynced2 &&
 182        (cd ../rsynced2 &&
 183         git init) &&
 184        git push rsync://127.0.0.1$(pwd)/../rsynced2/.git master &&
 185        cd ../rsynced2 &&
 186        git gc --prune &&
 187        test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
 188        git fsck --full
 189'
 190
 191test_expect_success 'push via rsync' '
 192        cd .. &&
 193        mkdir rsynced3 &&
 194        (cd rsynced3 &&
 195         git init) &&
 196        git push --all rsync://127.0.0.1$(pwd)/rsynced3/.git &&
 197        cd rsynced3 &&
 198        test $(git rev-parse master) = $(cd .. && git rev-parse master) &&
 199        git fsck --full
 200'
 201}
 202
 203test_expect_success 'fetch with a non-applying branch.<name>.merge' '
 204        git config branch.master.remote yeti &&
 205        git config branch.master.merge refs/heads/bigfoot &&
 206        git config remote.blub.url one &&
 207        git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
 208        git fetch blub
 209'
 210
 211# the strange name is: a\!'b
 212test_expect_success 'quoting of a strangely named repo' '
 213        ! git fetch "a\\!'\''b" > result 2>&1 &&
 214        cat result &&
 215        grep "fatal: '\''a\\\\!'\''b'\''" result
 216'
 217
 218test_done