t / t5541-http-push-smart.shon commit userdiff: add a builtin pattern for dts files (3c81760)
   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
   9ROOT_PATH="$PWD"
  10. "$TEST_DIRECTORY"/lib-gpg.sh
  11. "$TEST_DIRECTORY"/lib-httpd.sh
  12. "$TEST_DIRECTORY"/lib-terminal.sh
  13start_httpd
  14
  15test_expect_success 'setup remote repository' '
  16        cd "$ROOT_PATH" &&
  17        mkdir test_repo &&
  18        cd test_repo &&
  19        git init &&
  20        : >path1 &&
  21        git add path1 &&
  22        test_tick &&
  23        git commit -m initial &&
  24        cd - &&
  25        git clone --bare test_repo test_repo.git &&
  26        cd test_repo.git &&
  27        git config http.receivepack true &&
  28        git config core.logallrefupdates true &&
  29        ORIG_HEAD=$(git rev-parse --verify HEAD) &&
  30        cd - &&
  31        mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
  32'
  33
  34setup_askpass_helper
  35
  36cat >exp <<EOF
  37GET  /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
  38POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
  39EOF
  40test_expect_success 'no empty path components' '
  41        # Clear the log, so that it does not affect the "used receive-pack
  42        # service" test which reads the log too.
  43        test_when_finished ">\"\$HTTPD_ROOT_PATH\"/access.log" &&
  44
  45        # In the URL, add a trailing slash, and see if git appends yet another
  46        # slash.
  47        cd "$ROOT_PATH" &&
  48        git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
  49
  50        # NEEDSWORK: If the overspecification of the expected result is reduced, we
  51        # might be able to run this test in all protocol versions.
  52        if test -z "$GIT_TEST_PROTOCOL_VERSION"
  53        then
  54                check_access_log exp
  55        fi
  56'
  57
  58test_expect_success 'clone remote repository' '
  59        rm -rf test_repo_clone &&
  60        git clone $HTTPD_URL/smart/test_repo.git test_repo_clone &&
  61        (
  62                cd test_repo_clone && git config push.default matching
  63        )
  64'
  65
  66test_expect_success 'push to remote repository (standard)' '
  67        cd "$ROOT_PATH"/test_repo_clone &&
  68        : >path2 &&
  69        git add path2 &&
  70        test_tick &&
  71        git commit -m path2 &&
  72        HEAD=$(git rev-parse --verify HEAD) &&
  73        GIT_TRACE_CURL=true git push -v -v 2>err &&
  74        ! grep "Expect: 100-continue" err &&
  75        grep "POST git-receive-pack ([0-9]* bytes)" err &&
  76        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
  77         test $HEAD = $(git rev-parse --verify HEAD))
  78'
  79
  80test_expect_success 'push already up-to-date' '
  81        git push
  82'
  83
  84test_expect_success 'create and delete remote branch' '
  85        cd "$ROOT_PATH"/test_repo_clone &&
  86        git checkout -b dev &&
  87        : >path3 &&
  88        git add path3 &&
  89        test_tick &&
  90        git commit -m dev &&
  91        git push origin dev &&
  92        git push origin :dev &&
  93        test_must_fail git show-ref --verify refs/remotes/origin/dev
  94'
  95
  96cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
  97#!/bin/sh
  98exit 1
  99EOF
 100chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
 101
 102cat >exp <<EOF
 103remote: error: hook declined to update refs/heads/dev2
 104To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
 105 ! [remote rejected] dev2 -> dev2 (hook declined)
 106error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
 107EOF
 108
 109test_expect_success 'rejected update prints status' '
 110        cd "$ROOT_PATH"/test_repo_clone &&
 111        git checkout -b dev2 &&
 112        : >path4 &&
 113        git add path4 &&
 114        test_tick &&
 115        git commit -m dev2 &&
 116        test_must_fail git push origin dev2 2>act &&
 117        sed -e "/^remote: /s/ *$//" <act >cmp &&
 118        test_i18ncmp exp cmp
 119'
 120rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
 121
 122cat >exp <<EOF
 123GET  /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
 124POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
 125GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
 126POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
 127GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
 128GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
 129POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
 130GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
 131POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
 132GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
 133POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
 134EOF
 135test_expect_success 'used receive-pack service' '
 136        # NEEDSWORK: If the overspecification of the expected result is reduced, we
 137        # might be able to run this test in all protocol versions.
 138        if test -z "$GIT_TEST_PROTOCOL_VERSION"
 139        then
 140                check_access_log exp
 141        fi
 142'
 143
 144test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
 145        "$ROOT_PATH"/test_repo_clone master             success
 146
 147test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
 148        # create a dissimilarly-named remote ref so that git is unable to match the
 149        # two refs (viz. local, remote) unless an explicit refspec is provided.
 150        git push origin master:retsam &&
 151
 152        echo "change changed" > path2 &&
 153        git commit -a -m path2 --amend &&
 154
 155        # push master too; this ensures there is at least one '"'push'"' command to
 156        # the remote helper and triggers interaction with the helper.
 157        test_must_fail git push -v origin +master master:retsam >output 2>&1'
 158
 159test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: remote output' '
 160        grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
 161        grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
 162'
 163
 164test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
 165        test_i18ngrep "Updates were rejected because" \
 166                output
 167'
 168
 169test_expect_success 'push (chunked)' '
 170        git checkout master &&
 171        test_commit commit path3 &&
 172        HEAD=$(git rev-parse --verify HEAD) &&
 173        test_config http.postbuffer 4 &&
 174        git push -v -v origin $BRANCH 2>err &&
 175        grep "POST git-receive-pack (chunked)" err &&
 176        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
 177         test $HEAD = $(git rev-parse --verify HEAD))
 178'
 179
 180test_expect_success 'push --atomic also prevents branch creation, reports collateral' '
 181        # Setup upstream repo - empty for now
 182        d=$HTTPD_DOCUMENT_ROOT_PATH/atomic-branches.git &&
 183        git init --bare "$d" &&
 184        test_config -C "$d" http.receivepack true &&
 185        up="$HTTPD_URL"/smart/atomic-branches.git &&
 186
 187        # Tell "$up" about two branches for now
 188        test_commit atomic1 &&
 189        test_commit atomic2 &&
 190        git branch collateral &&
 191        git push "$up" master collateral &&
 192
 193        # collateral is a valid push, but should be failed by atomic push
 194        git checkout collateral &&
 195        test_commit collateral1 &&
 196
 197        # Make master incompatible with upstream to provoke atomic
 198        git checkout master &&
 199        git reset --hard HEAD^ &&
 200
 201        # Add a new branch which should be failed by atomic push. This is a
 202        # regression case.
 203        git branch atomic &&
 204
 205        # --atomic should cause entire push to be rejected
 206        test_must_fail git push --atomic "$up" master atomic collateral 2>output &&
 207
 208        # the new branch should not have been created upstream
 209        test_must_fail git -C "$d" show-ref --verify refs/heads/atomic &&
 210
 211        # upstream should still reflect atomic2, the last thing we pushed
 212        # successfully
 213        git rev-parse atomic2 >expected &&
 214        # on master...
 215        git -C "$d" rev-parse refs/heads/master >actual &&
 216        test_cmp expected actual &&
 217        # ...and collateral.
 218        git -C "$d" rev-parse refs/heads/collateral >actual &&
 219        test_cmp expected actual &&
 220
 221        # the failed refs should be indicated to the user
 222        grep "^ ! .*rejected.* master -> master" output &&
 223
 224        # the collateral failure refs should be indicated to the user
 225        grep "^ ! .*rejected.* atomic -> atomic .*atomic push failed" output &&
 226        grep "^ ! .*rejected.* collateral -> collateral .*atomic push failed" output
 227'
 228
 229test_expect_success 'push --all can push to empty repo' '
 230        d=$HTTPD_DOCUMENT_ROOT_PATH/empty-all.git &&
 231        git init --bare "$d" &&
 232        git --git-dir="$d" config http.receivepack true &&
 233        git push --all "$HTTPD_URL"/smart/empty-all.git
 234'
 235
 236test_expect_success 'push --mirror can push to empty repo' '
 237        d=$HTTPD_DOCUMENT_ROOT_PATH/empty-mirror.git &&
 238        git init --bare "$d" &&
 239        git --git-dir="$d" config http.receivepack true &&
 240        git push --mirror "$HTTPD_URL"/smart/empty-mirror.git
 241'
 242
 243test_expect_success 'push --all to repo with alternates' '
 244        s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
 245        d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-all.git &&
 246        git clone --bare --shared "$s" "$d" &&
 247        git --git-dir="$d" config http.receivepack true &&
 248        git --git-dir="$d" repack -adl &&
 249        git push --all "$HTTPD_URL"/smart/alternates-all.git
 250'
 251
 252test_expect_success 'push --mirror to repo with alternates' '
 253        s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
 254        d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-mirror.git &&
 255        git clone --bare --shared "$s" "$d" &&
 256        git --git-dir="$d" config http.receivepack true &&
 257        git --git-dir="$d" repack -adl &&
 258        git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git
 259'
 260
 261test_expect_success TTY 'push shows progress when stderr is a tty' '
 262        cd "$ROOT_PATH"/test_repo_clone &&
 263        test_commit noisy &&
 264        test_terminal git push >output 2>&1 &&
 265        test_i18ngrep "Writing objects" output
 266'
 267
 268test_expect_success TTY 'push --quiet silences status and progress' '
 269        cd "$ROOT_PATH"/test_repo_clone &&
 270        test_commit quiet &&
 271        test_terminal git push --quiet >output 2>&1 &&
 272        test_must_be_empty output
 273'
 274
 275test_expect_success TTY 'push --no-progress silences progress but not status' '
 276        cd "$ROOT_PATH"/test_repo_clone &&
 277        test_commit no-progress &&
 278        test_terminal git push --no-progress >output 2>&1 &&
 279        test_i18ngrep "^To http" output &&
 280        test_i18ngrep ! "Writing objects" output
 281'
 282
 283test_expect_success 'push --progress shows progress to non-tty' '
 284        cd "$ROOT_PATH"/test_repo_clone &&
 285        test_commit progress &&
 286        git push --progress >output 2>&1 &&
 287        test_i18ngrep "^To http" output &&
 288        test_i18ngrep "Writing objects" output
 289'
 290
 291test_expect_success 'http push gives sane defaults to reflog' '
 292        cd "$ROOT_PATH"/test_repo_clone &&
 293        test_commit reflog-test &&
 294        git push "$HTTPD_URL"/smart/test_repo.git &&
 295        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
 296                log -g -1 --format="%gn <%ge>" >actual &&
 297        echo "anonymous <anonymous@http.127.0.0.1>" >expect &&
 298        test_cmp expect actual
 299'
 300
 301test_expect_success 'http push respects GIT_COMMITTER_* in reflog' '
 302        cd "$ROOT_PATH"/test_repo_clone &&
 303        test_commit custom-reflog-test &&
 304        git push "$HTTPD_URL"/smart_custom_env/test_repo.git &&
 305        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
 306                log -g -1 --format="%gn <%ge>" >actual &&
 307        echo "Custom User <custom@example.com>" >expect &&
 308        test_cmp expect actual
 309'
 310
 311test_expect_success 'push over smart http with auth' '
 312        cd "$ROOT_PATH/test_repo_clone" &&
 313        echo push-auth-test >expect &&
 314        test_commit push-auth-test &&
 315        set_askpass user@host pass@host &&
 316        git push "$HTTPD_URL"/auth/smart/test_repo.git &&
 317        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
 318                log -1 --format=%s >actual &&
 319        expect_askpass both user@host &&
 320        test_cmp expect actual
 321'
 322
 323test_expect_success 'push to auth-only-for-push repo' '
 324        cd "$ROOT_PATH/test_repo_clone" &&
 325        echo push-half-auth >expect &&
 326        test_commit push-half-auth &&
 327        set_askpass user@host pass@host &&
 328        git push "$HTTPD_URL"/auth-push/smart/test_repo.git &&
 329        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
 330                log -1 --format=%s >actual &&
 331        expect_askpass both user@host &&
 332        test_cmp expect actual
 333'
 334
 335test_expect_success 'create repo without http.receivepack set' '
 336        cd "$ROOT_PATH" &&
 337        git init half-auth &&
 338        (
 339                cd half-auth &&
 340                test_commit one
 341        ) &&
 342        git clone --bare half-auth "$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git"
 343'
 344
 345test_expect_success 'clone via half-auth-complete does not need password' '
 346        cd "$ROOT_PATH" &&
 347        set_askpass wrong &&
 348        git clone "$HTTPD_URL"/half-auth-complete/smart/half-auth.git \
 349                half-auth-clone &&
 350        expect_askpass none
 351'
 352
 353test_expect_success 'push into half-auth-complete requires password' '
 354        cd "$ROOT_PATH/half-auth-clone" &&
 355        echo two >expect &&
 356        test_commit two &&
 357        set_askpass user@host pass@host &&
 358        git push "$HTTPD_URL/half-auth-complete/smart/half-auth.git" &&
 359        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git" \
 360                log -1 --format=%s >actual &&
 361        expect_askpass both user@host &&
 362        test_cmp expect actual
 363'
 364
 365test_expect_success CMDLINE_LIMIT 'push 2000 tags over http' '
 366        sha1=$(git rev-parse HEAD) &&
 367        test_seq 2000 |
 368          sort |
 369          sed "s|.*|$sha1 refs/tags/really-long-tag-name-&|" \
 370          >.git/packed-refs &&
 371        run_with_limited_cmdline git push --mirror
 372'
 373
 374test_expect_success GPG 'push with post-receive to inspect certificate' '
 375        (
 376                cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
 377                mkdir -p hooks &&
 378                write_script hooks/post-receive <<-\EOF &&
 379                # discard the update list
 380                cat >/dev/null
 381                # record the push certificate
 382                if test -n "${GIT_PUSH_CERT-}"
 383                then
 384                        git cat-file blob $GIT_PUSH_CERT >../push-cert
 385                fi &&
 386                cat >../push-cert-status <<E_O_F
 387                SIGNER=${GIT_PUSH_CERT_SIGNER-nobody}
 388                KEY=${GIT_PUSH_CERT_KEY-nokey}
 389                STATUS=${GIT_PUSH_CERT_STATUS-nostatus}
 390                NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus}
 391                NONCE=${GIT_PUSH_CERT_NONCE-nononce}
 392                E_O_F
 393                EOF
 394
 395                git config receive.certnonceseed sekrit &&
 396                git config receive.certnonceslop 30
 397        ) &&
 398        cd "$ROOT_PATH/test_repo_clone" &&
 399        test_commit cert-test &&
 400        git push --signed "$HTTPD_URL/smart/test_repo.git" &&
 401        (
 402                cd "$HTTPD_DOCUMENT_ROOT_PATH" &&
 403                cat <<-\EOF &&
 404                SIGNER=C O Mitter <committer@example.com>
 405                KEY=13B6F51ECDDE430D
 406                STATUS=G
 407                NONCE_STATUS=OK
 408                EOF
 409                sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" push-cert
 410        ) >expect &&
 411        test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH/push-cert-status"
 412'
 413
 414test_expect_success 'push status output scrubs password' '
 415        cd "$ROOT_PATH/test_repo_clone" &&
 416        git push --porcelain \
 417                "$HTTPD_URL_USER_PASS/smart/test_repo.git" \
 418                +HEAD:scrub >status &&
 419        # should have been scrubbed down to vanilla URL
 420        grep "^To $HTTPD_URL/smart/test_repo.git" status
 421'
 422
 423test_expect_success 'colorize errors/hints' '
 424        cd "$ROOT_PATH"/test_repo_clone &&
 425        test_must_fail git -c color.transport=always -c color.advice=always \
 426                -c color.push=always \
 427                push origin origin/master^:master 2>act &&
 428        test_decode_color <act >decoded &&
 429        test_i18ngrep "<RED>.*rejected.*<RESET>" decoded &&
 430        test_i18ngrep "<RED>error: failed to push some refs" decoded &&
 431        test_i18ngrep "<YELLOW>hint: " decoded &&
 432        test_i18ngrep ! "^hint: " decoded
 433'
 434
 435test_done