t / t5516-fetch-push.shon commit Support a --quiet option in the test-suite. (1ece127)
   1#!/bin/sh
   2
   3test_description='fetching and pushing, with or without wildcard'
   4
   5. ./test-lib.sh
   6
   7D=`pwd`
   8
   9mk_empty () {
  10        rm -fr testrepo &&
  11        mkdir testrepo &&
  12        (
  13                cd testrepo &&
  14                git init &&
  15                mv .git/hooks .git/hooks-disabled
  16        )
  17}
  18
  19mk_test () {
  20        mk_empty &&
  21        (
  22                for ref in "$@"
  23                do
  24                        git push testrepo $the_first_commit:refs/$ref || {
  25                                echo "Oops, push refs/$ref failure"
  26                                exit 1
  27                        }
  28                done &&
  29                cd testrepo &&
  30                for ref in "$@"
  31                do
  32                        r=$(git show-ref -s --verify refs/$ref) &&
  33                        test "z$r" = "z$the_first_commit" || {
  34                                echo "Oops, refs/$ref is wrong"
  35                                exit 1
  36                        }
  37                done &&
  38                git fsck --full
  39        )
  40}
  41
  42check_push_result () {
  43        (
  44                cd testrepo &&
  45                it="$1" &&
  46                shift
  47                for ref in "$@"
  48                do
  49                        r=$(git show-ref -s --verify refs/$ref) &&
  50                        test "z$r" = "z$it" || {
  51                                echo "Oops, refs/$ref is wrong"
  52                                exit 1
  53                        }
  54                done &&
  55                git fsck --full
  56        )
  57}
  58
  59test_expect_success setup '
  60
  61        : >path1 &&
  62        git add path1 &&
  63        test_tick &&
  64        git commit -a -m repo &&
  65        the_first_commit=$(git show-ref -s --verify refs/heads/master) &&
  66
  67        : >path2 &&
  68        git add path2 &&
  69        test_tick &&
  70        git commit -a -m second &&
  71        the_commit=$(git show-ref -s --verify refs/heads/master)
  72
  73'
  74
  75test_expect_success 'fetch without wildcard' '
  76        mk_empty &&
  77        (
  78                cd testrepo &&
  79                git fetch .. refs/heads/master:refs/remotes/origin/master &&
  80
  81                r=$(git show-ref -s --verify refs/remotes/origin/master) &&
  82                test "z$r" = "z$the_commit" &&
  83
  84                test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
  85        )
  86'
  87
  88test_expect_success 'fetch with wildcard' '
  89        mk_empty &&
  90        (
  91                cd testrepo &&
  92                git config remote.up.url .. &&
  93                git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
  94                git fetch up &&
  95
  96                r=$(git show-ref -s --verify refs/remotes/origin/master) &&
  97                test "z$r" = "z$the_commit" &&
  98
  99                test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
 100        )
 101'
 102
 103test_expect_success 'push without wildcard' '
 104        mk_empty &&
 105
 106        git push testrepo refs/heads/master:refs/remotes/origin/master &&
 107        (
 108                cd testrepo &&
 109                r=$(git show-ref -s --verify refs/remotes/origin/master) &&
 110                test "z$r" = "z$the_commit" &&
 111
 112                test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
 113        )
 114'
 115
 116test_expect_success 'push with wildcard' '
 117        mk_empty &&
 118
 119        git push testrepo "refs/heads/*:refs/remotes/origin/*" &&
 120        (
 121                cd testrepo &&
 122                r=$(git show-ref -s --verify refs/remotes/origin/master) &&
 123                test "z$r" = "z$the_commit" &&
 124
 125                test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
 126        )
 127'
 128
 129test_expect_success 'push with matching heads' '
 130
 131        mk_test heads/master &&
 132        git push testrepo &&
 133        check_push_result $the_commit heads/master
 134
 135'
 136
 137test_expect_success 'push with no ambiguity (1)' '
 138
 139        mk_test heads/master &&
 140        git push testrepo master:master &&
 141        check_push_result $the_commit heads/master
 142
 143'
 144
 145test_expect_success 'push with no ambiguity (2)' '
 146
 147        mk_test remotes/origin/master &&
 148        git push testrepo master:master &&
 149        check_push_result $the_commit remotes/origin/master
 150
 151'
 152
 153test_expect_success 'push with weak ambiguity (1)' '
 154
 155        mk_test heads/master remotes/origin/master &&
 156        git push testrepo master:master &&
 157        check_push_result $the_commit heads/master &&
 158        check_push_result $the_first_commit remotes/origin/master
 159
 160'
 161
 162test_expect_success 'push with weak ambiguity (2)' '
 163
 164        mk_test heads/master remotes/origin/master remotes/another/master &&
 165        git push testrepo master:master &&
 166        check_push_result $the_commit heads/master &&
 167        check_push_result $the_first_commit remotes/origin/master remotes/another/master
 168
 169'
 170
 171test_expect_success 'push with ambiguity (1)' '
 172
 173        mk_test remotes/origin/master remotes/frotz/master &&
 174        if git push testrepo master:master
 175        then
 176                echo "Oops, should have failed"
 177                false
 178        else
 179                check_push_result $the_first_commit remotes/origin/master remotes/frotz/master
 180        fi
 181'
 182
 183test_expect_success 'push with ambiguity (2)' '
 184
 185        mk_test heads/frotz tags/frotz &&
 186        if git push testrepo master:frotz
 187        then
 188                echo "Oops, should have failed"
 189                false
 190        else
 191                check_push_result $the_first_commit heads/frotz tags/frotz
 192        fi
 193
 194'
 195
 196test_expect_success 'push with colon-less refspec (1)' '
 197
 198        mk_test heads/frotz tags/frotz &&
 199        git branch -f frotz master &&
 200        git push testrepo frotz &&
 201        check_push_result $the_commit heads/frotz &&
 202        check_push_result $the_first_commit tags/frotz
 203
 204'
 205
 206test_expect_success 'push with colon-less refspec (2)' '
 207
 208        mk_test heads/frotz tags/frotz &&
 209        if git show-ref --verify -q refs/heads/frotz
 210        then
 211                git branch -D frotz
 212        fi &&
 213        git tag -f frotz &&
 214        git push testrepo frotz &&
 215        check_push_result $the_commit tags/frotz &&
 216        check_push_result $the_first_commit heads/frotz
 217
 218'
 219
 220test_expect_success 'push with colon-less refspec (3)' '
 221
 222        mk_test &&
 223        if git show-ref --verify -q refs/tags/frotz
 224        then
 225                git tag -d frotz
 226        fi &&
 227        git branch -f frotz master &&
 228        git push testrepo frotz &&
 229        check_push_result $the_commit heads/frotz &&
 230        test 1 = $( cd testrepo && git show-ref | wc -l )
 231'
 232
 233test_expect_success 'push with colon-less refspec (4)' '
 234
 235        mk_test &&
 236        if git show-ref --verify -q refs/heads/frotz
 237        then
 238                git branch -D frotz
 239        fi &&
 240        git tag -f frotz &&
 241        git push testrepo frotz &&
 242        check_push_result $the_commit tags/frotz &&
 243        test 1 = $( cd testrepo && git show-ref | wc -l )
 244
 245'
 246
 247test_expect_success 'push with dry-run' '
 248
 249        mk_test heads/master &&
 250        cd testrepo &&
 251        old_commit=$(git show-ref -s --verify refs/heads/master) &&
 252        cd .. &&
 253        git push --dry-run testrepo &&
 254        check_push_result $old_commit heads/master
 255'
 256
 257test_done