1#!/bin/sh
   2#
   3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
   4#
   5test_description='test WebDAV http-push
   7This test runs various sanity checks on http-push.'
   9. ./test-lib.sh
  11if 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
  17LIB_HTTPD_DAV=t
  19LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'}
  20. "$TEST_DIRECTORY"/lib-httpd.sh
  21ROOT_PATH="$PWD"
  22start_httpd
  23test_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'
  42test_expect_success 'clone remote repository' '
  44        cd "$ROOT_PATH" &&
  45        git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone
  46'
  47test_expect_success 'push to remote repository with packed refs' '
  49        cd "$ROOT_PATH"/test_repo_clone &&
  50        : >path2 &&
  51        git add path2 &&
  52        test_tick &&
  53        git commit -m path2 &&
  54        HEAD=$(git rev-parse --verify HEAD) &&
  55        git push &&
  56        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
  57         test $HEAD = $(git rev-parse --verify HEAD))
  58'
  59test_expect_success 'push already up-to-date' '
  61        git push
  62'
  63test_expect_success 'push to remote repository with unpacked refs' '
  65        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
  66         rm packed-refs &&
  67         git update-ref refs/heads/master $ORIG_HEAD &&
  68         git --bare update-server-info) &&
  69        git push &&
  70        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
  71         test $HEAD = $(git rev-parse --verify HEAD))
  72'
  73test_expect_success 'http-push fetches unpacked objects' '
  75        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
  76                "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
  77        git clone $HTTPD_URL/dumb/test_repo_unpacked.git \
  79                "$ROOT_PATH"/fetch_unpacked &&
  80        # By reset, we force git to retrieve the object
  82        (cd "$ROOT_PATH"/fetch_unpacked &&
  83         git reset --hard HEAD^ &&
  84         git remote rm origin &&
  85         git reflog expire --expire=0 --all &&
  86         git prune &&
  87         git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master)
  88'
  89test_expect_success 'http-push fetches packed objects' '
  91        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
  92                "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
  93        git clone $HTTPD_URL/dumb/test_repo_packed.git \
  95                "$ROOT_PATH"/test_repo_clone_packed &&
  96        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
  98         git --bare repack &&
  99         git --bare prune-packed) &&
 100        # By reset, we force git to retrieve the packed object
 102        (cd "$ROOT_PATH"/test_repo_clone_packed &&
 103         git reset --hard HEAD^ &&
 104         git remote rm origin &&
 105         git reflog expire --expire=0 --all &&
 106         git prune &&
 107         git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master)
 108'
 109test_expect_success 'create and delete remote branch' '
 111        cd "$ROOT_PATH"/test_repo_clone &&
 112        git checkout -b dev &&
 113        : >path3 &&
 114        git add path3 &&
 115        test_tick &&
 116        git commit -m dev &&
 117        git push origin dev &&
 118        git push origin :dev &&
 119        test_must_fail git show-ref --verify refs/remotes/origin/dev
 120'
 121test_expect_success 'MKCOL sends directory names with trailing slashes' '
 123        ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
 125'
 127x1="[0-9a-f]"
 129x2="$x1$x1"
 130x5="$x1$x1$x1$x1$x1"
 131x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"
 132x40="$x38$x2"
 133test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
 135        sed -e "s/PUT /OP /" -e "s/MOVE /OP /" "$HTTPD_ROOT_PATH"/access.log |
 136        grep -e "\"OP .*/objects/$x2/${x38}_$x40 HTTP/[.0-9]*\" 20[0-9] "
 137'
 139test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
 141        "$ROOT_PATH"/test_repo_clone master
 142stop_httpd
 144test_done