t / t5540-http-push.shon commit t5540-http-push: remove redundant fetches (eeb3aed)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
   4#
   5
   6test_description='test http-push
   7
   8This test runs various sanity checks on http-push.'
   9
  10. ./test-lib.sh
  11
  12ROOT_PATH="$PWD"
  13LIB_HTTPD_DAV=t
  14LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'}
  15
  16if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
  17then
  18        say "skipping test, USE_CURL_MULTI is not defined"
  19        test_done
  20fi
  21
  22. "$TEST_DIRECTORY"/lib-httpd.sh
  23start_httpd
  24
  25test_expect_success 'setup remote repository' '
  26        cd "$ROOT_PATH" &&
  27        mkdir test_repo &&
  28        cd test_repo &&
  29        git init &&
  30        : >path1 &&
  31        git add path1 &&
  32        test_tick &&
  33        git commit -m initial &&
  34        cd - &&
  35        git clone --bare test_repo test_repo.git &&
  36        cd test_repo.git &&
  37        git --bare update-server-info &&
  38        mv hooks/post-update.sample hooks/post-update &&
  39        ORIG_HEAD=$(git rev-parse --verify HEAD) &&
  40        cd - &&
  41        mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
  42'
  43
  44test_expect_success 'clone remote repository' '
  45        cd "$ROOT_PATH" &&
  46        git clone $HTTPD_URL/test_repo.git test_repo_clone
  47'
  48
  49test_expect_success 'push to remote repository with packed refs' '
  50        cd "$ROOT_PATH"/test_repo_clone &&
  51        : >path2 &&
  52        git add path2 &&
  53        test_tick &&
  54        git commit -m path2 &&
  55        HEAD=$(git rev-parse --verify HEAD) &&
  56        git push &&
  57        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
  58         test $HEAD = $(git rev-parse --verify HEAD))
  59'
  60
  61test_expect_success 'push already up-to-date' '
  62        git push
  63'
  64
  65test_expect_success 'push to remote repository with unpacked refs' '
  66        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
  67         rm packed-refs &&
  68         git update-ref refs/heads/master $ORIG_HEAD &&
  69         git --bare update-server-info) &&
  70        git push &&
  71        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
  72         test $HEAD = $(git rev-parse --verify HEAD))
  73'
  74
  75test_expect_success 'http-push fetches unpacked objects' '
  76        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
  77                "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
  78
  79        git clone $HTTPD_URL/test_repo_unpacked.git \
  80                "$ROOT_PATH"/fetch_unpacked &&
  81
  82        # By reset, we force git to retrieve the object
  83        (cd "$ROOT_PATH"/fetch_unpacked &&
  84         git reset --hard HEAD^ &&
  85         git remote rm origin &&
  86         git reflog expire --expire=0 --all &&
  87         git prune &&
  88         git push -f -v $HTTPD_URL/test_repo_unpacked.git master)
  89'
  90
  91test_expect_success 'http-push fetches packed objects' '
  92        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
  93                "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
  94
  95        git clone $HTTPD_URL/test_repo_packed.git \
  96                "$ROOT_PATH"/test_repo_clone_packed &&
  97
  98        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
  99         git --bare repack &&
 100         git --bare prune-packed) &&
 101
 102        # By reset, we force git to retrieve the packed object
 103        (cd "$ROOT_PATH"/test_repo_clone_packed &&
 104         git reset --hard HEAD^ &&
 105         git remote rm origin &&
 106         git reflog expire --expire=0 --all &&
 107         git prune &&
 108         git push -f -v $HTTPD_URL/test_repo_packed.git master)
 109'
 110
 111test_expect_success 'create and delete remote branch' '
 112        cd "$ROOT_PATH"/test_repo_clone &&
 113        git checkout -b dev &&
 114        : >path3 &&
 115        git add path3 &&
 116        test_tick &&
 117        git commit -m dev &&
 118        git push origin dev &&
 119        git push origin :dev &&
 120        test_must_fail git show-ref --verify refs/remotes/origin/dev
 121'
 122
 123test_expect_success 'MKCOL sends directory names with trailing slashes' '
 124
 125        ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
 126
 127'
 128
 129x1="[0-9a-f]"
 130x2="$x1$x1"
 131x5="$x1$x1$x1$x1$x1"
 132x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"
 133x40="$x38$x2"
 134
 135test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
 136        sed -e "s/PUT /OP /" -e "s/MOVE /OP /" "$HTTPD_ROOT_PATH"/access.log |
 137        grep -e "\"OP .*/objects/$x2/${x38}_$x40 HTTP/[.0-9]*\" 20[0-9] "
 138
 139'
 140
 141stop_httpd
 142
 143test_done