t / t5540-http-push.shon commit Merge branch 'jc/advice-doc' (184a541)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
   4#
   5
   6test_description='test WebDAV http-push
   7
   8This test runs various sanity checks on http-push.'
   9
  10. ./test-lib.sh
  11
  12if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
  13then
  14        skip_all="skipping test, USE_CURL_MULTI is not defined"
  15        test_done
  16fi
  17
  18LIB_HTTPD_DAV=t
  19LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'}
  20. "$TEST_DIRECTORY"/lib-httpd.sh
  21ROOT_PATH="$PWD"
  22start_httpd
  23
  24test_expect_success 'setup remote repository' '
  25        cd "$ROOT_PATH" &&
  26        mkdir test_repo &&
  27        cd test_repo &&
  28        git init &&
  29        : >path1 &&
  30        git add path1 &&
  31        test_tick &&
  32        git commit -m initial &&
  33        cd - &&
  34        git clone --bare test_repo test_repo.git &&
  35        cd test_repo.git &&
  36        git --bare update-server-info &&
  37        mv hooks/post-update.sample hooks/post-update &&
  38        ORIG_HEAD=$(git rev-parse --verify HEAD) &&
  39        cd - &&
  40        mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
  41'
  42
  43test_expect_success 'create password-protected repository' '
  44        mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb" &&
  45        cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
  46               "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git"
  47'
  48
  49test_expect_success 'setup askpass helper' '
  50        cat >askpass <<-\EOF &&
  51        #!/bin/sh
  52        echo user@host
  53        EOF
  54        chmod +x askpass &&
  55        GIT_ASKPASS="$PWD/askpass" &&
  56        export GIT_ASKPASS
  57'
  58
  59test_expect_success 'clone remote repository' '
  60        cd "$ROOT_PATH" &&
  61        git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone
  62'
  63
  64test_expect_success 'push to remote repository with packed refs' '
  65        cd "$ROOT_PATH"/test_repo_clone &&
  66        : >path2 &&
  67        git add path2 &&
  68        test_tick &&
  69        git commit -m path2 &&
  70        HEAD=$(git rev-parse --verify HEAD) &&
  71        git push &&
  72        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
  73         test $HEAD = $(git rev-parse --verify HEAD))
  74'
  75
  76test_expect_success 'push already up-to-date' '
  77        git push
  78'
  79
  80test_expect_success 'push to remote repository with unpacked refs' '
  81        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
  82         rm packed-refs &&
  83         git update-ref refs/heads/master $ORIG_HEAD &&
  84         git --bare update-server-info) &&
  85        git push &&
  86        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
  87         test $HEAD = $(git rev-parse --verify HEAD))
  88'
  89
  90test_expect_success 'http-push fetches unpacked objects' '
  91        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
  92                "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
  93
  94        git clone $HTTPD_URL/dumb/test_repo_unpacked.git \
  95                "$ROOT_PATH"/fetch_unpacked &&
  96
  97        # By reset, we force git to retrieve the object
  98        (cd "$ROOT_PATH"/fetch_unpacked &&
  99         git reset --hard HEAD^ &&
 100         git remote rm origin &&
 101         git reflog expire --expire=0 --all &&
 102         git prune &&
 103         git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master)
 104'
 105
 106test_expect_success 'http-push fetches packed objects' '
 107        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
 108                "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
 109
 110        git clone $HTTPD_URL/dumb/test_repo_packed.git \
 111                "$ROOT_PATH"/test_repo_clone_packed &&
 112
 113        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
 114         git --bare repack &&
 115         git --bare prune-packed) &&
 116
 117        # By reset, we force git to retrieve the packed object
 118        (cd "$ROOT_PATH"/test_repo_clone_packed &&
 119         git reset --hard HEAD^ &&
 120         git remote rm origin &&
 121         git reflog expire --expire=0 --all &&
 122         git prune &&
 123         git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master)
 124'
 125
 126test_expect_success 'create and delete remote branch' '
 127        cd "$ROOT_PATH"/test_repo_clone &&
 128        git checkout -b dev &&
 129        : >path3 &&
 130        git add path3 &&
 131        test_tick &&
 132        git commit -m dev &&
 133        git push origin dev &&
 134        git push origin :dev &&
 135        test_must_fail git show-ref --verify refs/remotes/origin/dev
 136'
 137
 138test_expect_success 'MKCOL sends directory names with trailing slashes' '
 139
 140        ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
 141
 142'
 143
 144x1="[0-9a-f]"
 145x2="$x1$x1"
 146x5="$x1$x1$x1$x1$x1"
 147x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"
 148x40="$x38$x2"
 149
 150test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
 151        sed \
 152                -e "s/PUT /OP /" \
 153                -e "s/MOVE /OP /" \
 154            -e "s|/objects/$x2/${x38}_$x40|WANTED_PATH_REQUEST|" \
 155                "$HTTPD_ROOT_PATH"/access.log |
 156        grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] "
 157
 158'
 159
 160test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
 161        "$ROOT_PATH"/test_repo_clone master
 162
 163test_expect_success 'push to password-protected repository (user in URL)' '
 164        test_commit pw-user &&
 165        git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
 166        git rev-parse --verify HEAD >expect &&
 167        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
 168                rev-parse --verify HEAD >actual &&
 169        test_cmp expect actual
 170'
 171
 172test_expect_failure 'push to password-protected repository (no user in URL)' '
 173        test_commit pw-nouser &&
 174        git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
 175        git rev-parse --verify HEAD >expect &&
 176        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
 177                rev-parse --verify HEAD >actual &&
 178        test_cmp expect actual
 179'
 180
 181stop_httpd
 182
 183test_done