t / t5541-http-push.shon commit Merge branch 'jh/update-ref-d-through-symref' into maint (ed20513)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
   4#
   5
   6test_description='test smart pushing over http via http-backend'
   7. ./test-lib.sh
   8
   9if test -n "$NO_CURL"; then
  10        skip_all='skipping test, git built without http support'
  11        test_done
  12fi
  13
  14ROOT_PATH="$PWD"
  15LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5541'}
  16. "$TEST_DIRECTORY"/lib-httpd.sh
  17. "$TEST_DIRECTORY"/lib-terminal.sh
  18start_httpd
  19
  20test_expect_success 'setup remote repository' '
  21        cd "$ROOT_PATH" &&
  22        mkdir test_repo &&
  23        cd test_repo &&
  24        git init &&
  25        : >path1 &&
  26        git add path1 &&
  27        test_tick &&
  28        git commit -m initial &&
  29        cd - &&
  30        git clone --bare test_repo test_repo.git &&
  31        cd test_repo.git &&
  32        git config http.receivepack true &&
  33        git config core.logallrefupdates true &&
  34        ORIG_HEAD=$(git rev-parse --verify HEAD) &&
  35        cd - &&
  36        mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
  37'
  38
  39setup_askpass_helper
  40
  41cat >exp <<EOF
  42GET  /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
  43POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
  44EOF
  45test_expect_success 'no empty path components' '
  46        # In the URL, add a trailing slash, and see if git appends yet another
  47        # slash.
  48        cd "$ROOT_PATH" &&
  49        git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
  50
  51        sed -e "
  52                s/^.* \"//
  53                s/\"//
  54                s/ [1-9][0-9]*\$//
  55                s/^GET /GET  /
  56        " >act <"$HTTPD_ROOT_PATH"/access.log &&
  57
  58        # Clear the log, so that it does not affect the "used receive-pack
  59        # service" test which reads the log too.
  60        #
  61        # We do this before the actual comparison to ensure the log is cleared.
  62        echo > "$HTTPD_ROOT_PATH"/access.log &&
  63
  64        test_cmp exp act
  65'
  66
  67test_expect_success 'clone remote repository' '
  68        rm -rf test_repo_clone &&
  69        git clone $HTTPD_URL/smart/test_repo.git test_repo_clone &&
  70        (
  71                cd test_repo_clone && git config push.default matching
  72        )
  73'
  74
  75test_expect_success 'push to remote repository (standard)' '
  76        cd "$ROOT_PATH"/test_repo_clone &&
  77        : >path2 &&
  78        git add path2 &&
  79        test_tick &&
  80        git commit -m path2 &&
  81        HEAD=$(git rev-parse --verify HEAD) &&
  82        GIT_CURL_VERBOSE=1 git push -v -v 2>err &&
  83        ! grep "Expect: 100-continue" err &&
  84        grep "POST git-receive-pack ([0-9]* bytes)" err &&
  85        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
  86         test $HEAD = $(git rev-parse --verify HEAD))
  87'
  88
  89test_expect_success 'push already up-to-date' '
  90        git push
  91'
  92
  93test_expect_success 'create and delete remote branch' '
  94        cd "$ROOT_PATH"/test_repo_clone &&
  95        git checkout -b dev &&
  96        : >path3 &&
  97        git add path3 &&
  98        test_tick &&
  99        git commit -m dev &&
 100        git push origin dev &&
 101        git push origin :dev &&
 102        test_must_fail git show-ref --verify refs/remotes/origin/dev
 103'
 104
 105cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
 106#!/bin/sh
 107exit 1
 108EOF
 109chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
 110
 111cat >exp <<EOF
 112remote: error: hook declined to update refs/heads/dev2
 113To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
 114 ! [remote rejected] dev2 -> dev2 (hook declined)
 115error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
 116EOF
 117
 118test_expect_success 'rejected update prints status' '
 119        cd "$ROOT_PATH"/test_repo_clone &&
 120        git checkout -b dev2 &&
 121        : >path4 &&
 122        git add path4 &&
 123        test_tick &&
 124        git commit -m dev2 &&
 125        test_must_fail git push origin dev2 2>act &&
 126        sed -e "/^remote: /s/ *$//" <act >cmp &&
 127        test_cmp exp cmp
 128'
 129rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
 130
 131cat >exp <<EOF
 132
 133GET  /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
 134POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
 135GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
 136POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
 137GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
 138GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
 139POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
 140GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
 141POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
 142GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
 143POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
 144EOF
 145test_expect_success 'used receive-pack service' '
 146        sed -e "
 147                s/^.* \"//
 148                s/\"//
 149                s/ [1-9][0-9]*\$//
 150                s/^GET /GET  /
 151        " >act <"$HTTPD_ROOT_PATH"/access.log &&
 152        test_cmp exp act
 153'
 154
 155test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
 156        "$ROOT_PATH"/test_repo_clone master
 157
 158test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
 159        # create a dissimilarly-named remote ref so that git is unable to match the
 160        # two refs (viz. local, remote) unless an explicit refspec is provided.
 161        git push origin master:retsam
 162
 163        echo "change changed" > path2 &&
 164        git commit -a -m path2 --amend &&
 165
 166        # push master too; this ensures there is at least one '"'push'"' command to
 167        # the remote helper and triggers interaction with the helper.
 168        test_must_fail git push -v origin +master master:retsam >output 2>&1'
 169
 170test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: remote output' '
 171        grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
 172        grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
 173'
 174
 175test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
 176        test_i18ngrep "Updates were rejected because" \
 177                output
 178'
 179
 180test_expect_success 'push (chunked)' '
 181        git checkout master &&
 182        test_commit commit path3 &&
 183        HEAD=$(git rev-parse --verify HEAD) &&
 184        git config http.postbuffer 4 &&
 185        test_when_finished "git config --unset http.postbuffer" &&
 186        git push -v -v origin $BRANCH 2>err &&
 187        grep "POST git-receive-pack (chunked)" err &&
 188        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
 189         test $HEAD = $(git rev-parse --verify HEAD))
 190'
 191
 192test_expect_success 'push --all can push to empty repo' '
 193        d=$HTTPD_DOCUMENT_ROOT_PATH/empty-all.git &&
 194        git init --bare "$d" &&
 195        git --git-dir="$d" config http.receivepack true &&
 196        git push --all "$HTTPD_URL"/smart/empty-all.git
 197'
 198
 199test_expect_success 'push --mirror can push to empty repo' '
 200        d=$HTTPD_DOCUMENT_ROOT_PATH/empty-mirror.git &&
 201        git init --bare "$d" &&
 202        git --git-dir="$d" config http.receivepack true &&
 203        git push --mirror "$HTTPD_URL"/smart/empty-mirror.git
 204'
 205
 206test_expect_success 'push --all to repo with alternates' '
 207        s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
 208        d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-all.git &&
 209        git clone --bare --shared "$s" "$d" &&
 210        git --git-dir="$d" config http.receivepack true &&
 211        git --git-dir="$d" repack -adl &&
 212        git push --all "$HTTPD_URL"/smart/alternates-all.git
 213'
 214
 215test_expect_success 'push --mirror to repo with alternates' '
 216        s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
 217        d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-mirror.git &&
 218        git clone --bare --shared "$s" "$d" &&
 219        git --git-dir="$d" config http.receivepack true &&
 220        git --git-dir="$d" repack -adl &&
 221        git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git
 222'
 223
 224test_expect_success TTY 'push shows progress when stderr is a tty' '
 225        cd "$ROOT_PATH"/test_repo_clone &&
 226        test_commit noisy &&
 227        test_terminal git push >output 2>&1 &&
 228        grep "^Writing objects" output
 229'
 230
 231test_expect_success TTY 'push --quiet silences status and progress' '
 232        cd "$ROOT_PATH"/test_repo_clone &&
 233        test_commit quiet &&
 234        test_terminal git push --quiet >output 2>&1 &&
 235        test_cmp /dev/null output
 236'
 237
 238test_expect_success TTY 'push --no-progress silences progress but not status' '
 239        cd "$ROOT_PATH"/test_repo_clone &&
 240        test_commit no-progress &&
 241        test_terminal git push --no-progress >output 2>&1 &&
 242        grep "^To http" output &&
 243        ! grep "^Writing objects"
 244'
 245
 246test_expect_success 'push --progress shows progress to non-tty' '
 247        cd "$ROOT_PATH"/test_repo_clone &&
 248        test_commit progress &&
 249        git push --progress >output 2>&1 &&
 250        grep "^To http" output &&
 251        grep "^Writing objects" output
 252'
 253
 254test_expect_success 'http push gives sane defaults to reflog' '
 255        cd "$ROOT_PATH"/test_repo_clone &&
 256        test_commit reflog-test &&
 257        git push "$HTTPD_URL"/smart/test_repo.git &&
 258        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
 259                log -g -1 --format="%gn <%ge>" >actual &&
 260        echo "anonymous <anonymous@http.127.0.0.1>" >expect &&
 261        test_cmp expect actual
 262'
 263
 264test_expect_success 'http push respects GIT_COMMITTER_* in reflog' '
 265        cd "$ROOT_PATH"/test_repo_clone &&
 266        test_commit custom-reflog-test &&
 267        git push "$HTTPD_URL"/smart_custom_env/test_repo.git &&
 268        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
 269                log -g -1 --format="%gn <%ge>" >actual &&
 270        echo "Custom User <custom@example.com>" >expect &&
 271        test_cmp expect actual
 272'
 273
 274test_expect_success 'push over smart http with auth' '
 275        cd "$ROOT_PATH/test_repo_clone" &&
 276        echo push-auth-test >expect &&
 277        test_commit push-auth-test &&
 278        set_askpass user@host &&
 279        git push "$HTTPD_URL"/auth/smart/test_repo.git &&
 280        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
 281                log -1 --format=%s >actual &&
 282        expect_askpass both user@host &&
 283        test_cmp expect actual
 284'
 285
 286test_expect_success 'push to auth-only-for-push repo' '
 287        cd "$ROOT_PATH/test_repo_clone" &&
 288        echo push-half-auth >expect &&
 289        test_commit push-half-auth &&
 290        set_askpass user@host &&
 291        git push "$HTTPD_URL"/auth-push/smart/test_repo.git &&
 292        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
 293                log -1 --format=%s >actual &&
 294        expect_askpass both user@host &&
 295        test_cmp expect actual
 296'
 297
 298stop_httpd
 299test_done