t / t5550-http-fetch.shon commit Merge branch 'jk/pager-per-command' (23778ae)
   1#!/bin/sh
   2
   3test_description='test dumb fetching over http via static file'
   4. ./test-lib.sh
   5
   6if test -n "$NO_CURL"; then
   7        skip_all='skipping test, git built without http support'
   8        test_done
   9fi
  10
  11. "$TEST_DIRECTORY"/lib-httpd.sh
  12LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5550'}
  13start_httpd
  14
  15test_expect_success 'setup repository' '
  16        echo content >file &&
  17        git add file &&
  18        git commit -m one
  19'
  20
  21test_expect_success 'create http-accessible bare repository' '
  22        mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  23        (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  24         git --bare init &&
  25         echo "exec git update-server-info" >hooks/post-update &&
  26         chmod +x hooks/post-update
  27        ) &&
  28        git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  29        git push public master:master
  30'
  31
  32test_expect_success 'clone http repository' '
  33        git clone $HTTPD_URL/dumb/repo.git clone &&
  34        test_cmp file clone/file
  35'
  36
  37test_expect_success 'clone http repository with authentication' '
  38        mkdir "$HTTPD_DOCUMENT_ROOT_PATH/auth/" &&
  39        cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" "$HTTPD_DOCUMENT_ROOT_PATH/auth/repo.git" &&
  40        git clone $AUTH_HTTPD_URL/auth/repo.git clone-auth &&
  41        test_cmp file clone-auth/file
  42'
  43
  44test_expect_success 'fetch changes via http' '
  45        echo content >>file &&
  46        git commit -a -m two &&
  47        git push public
  48        (cd clone && git pull) &&
  49        test_cmp file clone/file
  50'
  51
  52test_expect_success 'http remote detects correct HEAD' '
  53        git push public master:other &&
  54        (cd clone &&
  55         git remote set-head origin -d &&
  56         git remote set-head origin -a &&
  57         git symbolic-ref refs/remotes/origin/HEAD > output &&
  58         echo refs/remotes/origin/master > expect &&
  59         test_cmp expect output
  60        )
  61'
  62
  63test_expect_success 'fetch packed objects' '
  64        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
  65        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
  66         git --bare repack &&
  67         git --bare prune-packed
  68        ) &&
  69        git clone $HTTPD_URL/dumb/repo_pack.git
  70'
  71
  72test_expect_success 'fetch notices corrupt pack' '
  73        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
  74        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
  75         p=`ls objects/pack/pack-*.pack` &&
  76         chmod u+w $p &&
  77         printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
  78        ) &&
  79        mkdir repo_bad1.git &&
  80        (cd repo_bad1.git &&
  81         git --bare init &&
  82         test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
  83         test 0 = `ls objects/pack/pack-*.pack | wc -l`
  84        )
  85'
  86
  87test_expect_success 'fetch notices corrupt idx' '
  88        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
  89        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
  90         p=`ls objects/pack/pack-*.idx` &&
  91         chmod u+w $p &&
  92         printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
  93        ) &&
  94        mkdir repo_bad2.git &&
  95        (cd repo_bad2.git &&
  96         git --bare init &&
  97         test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
  98         test 0 = `ls objects/pack | wc -l`
  99        )
 100'
 101
 102test_expect_success 'did not use upload-pack service' '
 103        grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act
 104        : >exp
 105        test_cmp exp act
 106'
 107
 108stop_httpd
 109test_done