t / t5551-http-fetch.shon commit fetch-pack: eliminate spurious error messages (5f0fc64)
   1#!/bin/sh
   2
   3test_description='test smart fetching over http via http-backend'
   4. ./test-lib.sh
   5
   6if test -n "$NO_CURL"; then
   7        skip_all='skipping test, git built without http support'
   8        test_done
   9fi
  10
  11LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5551'}
  12. "$TEST_DIRECTORY"/lib-httpd.sh
  13start_httpd
  14
  15test_expect_success 'setup repository' '
  16        echo content >file &&
  17        git add file &&
  18        git commit -m one
  19'
  20
  21test_expect_success 'create http-accessible bare repository' '
  22        mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  23        (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  24         git --bare init
  25        ) &&
  26        git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  27        git push public master:master
  28'
  29
  30setup_askpass_helper
  31
  32cat >exp <<EOF
  33> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
  34> Accept: */*
  35> Pragma: no-cache
  36< HTTP/1.1 200 OK
  37< Pragma: no-cache
  38< Cache-Control: no-cache, max-age=0, must-revalidate
  39< Content-Type: application/x-git-upload-pack-advertisement
  40> POST /smart/repo.git/git-upload-pack HTTP/1.1
  41> Accept-Encoding: deflate, gzip
  42> Content-Type: application/x-git-upload-pack-request
  43> Accept: application/x-git-upload-pack-result
  44> Content-Length: xxx
  45< HTTP/1.1 200 OK
  46< Pragma: no-cache
  47< Cache-Control: no-cache, max-age=0, must-revalidate
  48< Content-Type: application/x-git-upload-pack-result
  49EOF
  50test_expect_success 'clone http repository' '
  51        GIT_CURL_VERBOSE=1 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
  52        test_cmp file clone/file &&
  53        tr '\''\015'\'' Q <err |
  54        sed -e "
  55                s/Q\$//
  56                /^[*] /d
  57                /^$/d
  58                /^< $/d
  59
  60                /^[^><]/{
  61                        s/^/> /
  62                }
  63
  64                /^> User-Agent: /d
  65                /^> Host: /d
  66                /^> POST /,$ {
  67                        /^> Accept: [*]\\/[*]/d
  68                }
  69                s/^> Content-Length: .*/> Content-Length: xxx/
  70                /^> 00..want /d
  71                /^> 00.*done/d
  72
  73                /^< Server: /d
  74                /^< Expires: /d
  75                /^< Date: /d
  76                /^< Content-Length: /d
  77                /^< Transfer-Encoding: /d
  78        " >act &&
  79        test_cmp exp act
  80'
  81
  82test_expect_success 'fetch changes via http' '
  83        echo content >>file &&
  84        git commit -a -m two &&
  85        git push public
  86        (cd clone && git pull) &&
  87        test_cmp file clone/file
  88'
  89
  90cat >exp <<EOF
  91GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
  92POST /smart/repo.git/git-upload-pack HTTP/1.1 200
  93GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
  94POST /smart/repo.git/git-upload-pack HTTP/1.1 200
  95EOF
  96test_expect_success 'used upload-pack service' '
  97        sed -e "
  98                s/^.* \"//
  99                s/\"//
 100                s/ [1-9][0-9]*\$//
 101                s/^GET /GET  /
 102        " >act <"$HTTPD_ROOT_PATH"/access.log &&
 103        test_cmp exp act
 104'
 105
 106test_expect_success 'follow redirects (301)' '
 107        git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
 108'
 109
 110test_expect_success 'follow redirects (302)' '
 111        git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
 112'
 113
 114test_expect_success 'clone from password-protected repository' '
 115        echo two >expect &&
 116        set_askpass user@host &&
 117        git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
 118        expect_askpass both user@host &&
 119        git --git-dir=smart-auth log -1 --format=%s >actual &&
 120        test_cmp expect actual
 121'
 122
 123test_expect_success 'clone from auth-only-for-push repository' '
 124        echo two >expect &&
 125        set_askpass wrong &&
 126        git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
 127        expect_askpass none &&
 128        git --git-dir=smart-noauth log -1 --format=%s >actual &&
 129        test_cmp expect actual
 130'
 131
 132test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
 133
 134test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
 135        (
 136        cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
 137        for i in `test_seq 50000`
 138        do
 139                echo "commit refs/heads/too-many-refs"
 140                echo "mark :$i"
 141                echo "committer git <git@example.com> $i +0000"
 142                echo "data 0"
 143                echo "M 644 inline bla.txt"
 144                echo "data 4"
 145                echo "bla"
 146                # make every commit dangling by always
 147                # rewinding the branch after each commit
 148                echo "reset refs/heads/too-many-refs"
 149                echo "from :1"
 150        done | git fast-import --export-marks=marks &&
 151
 152        # now assign tags to all the dangling commits we created above
 153        tag=$("$PERL_PATH" -e "print \"bla\" x 30") &&
 154        sed -e "s/^:\(.\+\) \(.\+\)$/\2 refs\/tags\/$tag-\1/" <marks >>packed-refs
 155        )
 156'
 157
 158test_expect_success EXPENSIVE 'clone the 50,000 tag repo to check OS command line overflow' '
 159        git clone $HTTPD_URL/smart/repo.git too-many-refs 2>err &&
 160        test_line_count = 0 err
 161'
 162
 163stop_httpd
 164test_done