Git fork
at reftables-rust 214 lines 6.3 kB view raw
1#!/bin/sh 2# 3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at> 4# 5 6test_description='test WebDAV http-push 7 8This test runs various sanity checks on http-push.' 9 10GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 11export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 12 13. ./test-lib.sh 14 15if git http-push > /dev/null 2>&1 || [ $? -eq 128 ] 16then 17 skip_all="skipping test, USE_CURL_MULTI is not defined" 18 test_done 19fi 20 21if test_have_prereq !REFFILES 22then 23 skip_all='skipping test; dumb HTTP protocol not supported with reftable.' 24 test_done 25fi 26 27LIB_HTTPD_DAV=t 28. "$TEST_DIRECTORY"/lib-httpd.sh 29ROOT_PATH="$PWD" 30start_httpd 31 32test_expect_success 'setup remote repository' ' 33 cd "$ROOT_PATH" && 34 mkdir test_repo && 35 cd test_repo && 36 git init && 37 : >path1 && 38 git add path1 && 39 test_tick && 40 git commit -m initial && 41 cd - && 42 git clone --bare test_repo test_repo.git && 43 cd test_repo.git && 44 git --bare update-server-info && 45 test_hook --setup post-update <<-\EOF && 46 exec git update-server-info 47 EOF 48 ORIG_HEAD=$(git rev-parse --verify HEAD) && 49 cd - && 50 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH" 51' 52 53test_expect_success 'create password-protected repository' ' 54 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb" && 55 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \ 56 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" 57' 58 59setup_askpass_helper 60 61test_expect_success 'clone remote repository' ' 62 cd "$ROOT_PATH" && 63 git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone 64' 65 66test_expect_success 'push to remote repository with packed refs' ' 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 push && 74 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && 75 test $HEAD = $(git rev-parse --verify HEAD)) 76' 77 78test_expect_success 'push already up-to-date' ' 79 git push 80' 81 82test_expect_success 'push to remote repository with unpacked refs' ' 83 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && 84 rm packed-refs && 85 git update-ref refs/heads/main $ORIG_HEAD && 86 git --bare update-server-info) && 87 git push && 88 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && 89 test $HEAD = $(git rev-parse --verify HEAD)) 90' 91 92test_expect_success 'http-push fetches unpacked objects' ' 93 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ 94 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git && 95 96 git clone $HTTPD_URL/dumb/test_repo_unpacked.git \ 97 "$ROOT_PATH"/fetch_unpacked && 98 99 # By reset, we force git to retrieve the object 100 (cd "$ROOT_PATH"/fetch_unpacked && 101 git reset --hard HEAD^ && 102 git remote rm origin && 103 git reflog expire --expire=0 --all && 104 git prune && 105 git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git main) 106' 107 108test_expect_success 'http-push fetches packed objects' ' 109 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ 110 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && 111 112 git clone $HTTPD_URL/dumb/test_repo_packed.git \ 113 "$ROOT_PATH"/test_repo_clone_packed && 114 115 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && 116 git --bare repack && 117 git --bare prune-packed) && 118 119 # By reset, we force git to retrieve the packed object 120 (cd "$ROOT_PATH"/test_repo_clone_packed && 121 git reset --hard HEAD^ && 122 git remote remove origin && 123 git reflog expire --expire=0 --all && 124 git prune && 125 git push -f -v $HTTPD_URL/dumb/test_repo_packed.git main) 126' 127 128test_expect_success 'create and delete remote branch' ' 129 cd "$ROOT_PATH"/test_repo_clone && 130 git checkout -b dev && 131 : >path3 && 132 git add path3 && 133 test_tick && 134 git commit -m dev && 135 git push origin dev && 136 git push origin :dev && 137 test_must_fail git show-ref --verify refs/remotes/origin/dev 138' 139 140test_expect_success 'non-force push fails if not up to date' ' 141 git init --bare "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_conflict.git && 142 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_conflict.git update-server-info && 143 git clone $HTTPD_URL/dumb/test_repo_conflict.git "$ROOT_PATH"/c1 && 144 git clone $HTTPD_URL/dumb/test_repo_conflict.git "$ROOT_PATH"/c2 && 145 test_commit -C "$ROOT_PATH/c1" path1 && 146 git -C "$ROOT_PATH/c1" push origin HEAD && 147 git -C "$ROOT_PATH/c2" pull && 148 test_commit -C "$ROOT_PATH/c1" path2 && 149 git -C "$ROOT_PATH/c1" push origin HEAD && 150 test_commit -C "$ROOT_PATH/c2" path3 && 151 git -C "$ROOT_PATH/c1" log --graph --all && 152 git -C "$ROOT_PATH/c2" log --graph --all && 153 test_must_fail git -C "$ROOT_PATH/c2" push origin HEAD 154' 155 156test_expect_success 'MKCOL sends directory names with trailing slashes' ' 157 158 ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log 159 160' 161 162x1="[0-9a-f]" 163x2="$x1$x1" 164xtrunc=$(echo $OID_REGEX | sed -e "s/\[0-9a-f\]\[0-9a-f\]//") 165 166test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' ' 167 sed \ 168 -e "s/PUT /OP /" \ 169 -e "s/MOVE /OP /" \ 170 -e "s|/objects/$x2/${xtrunc}_$OID_REGEX|WANTED_PATH_REQUEST|" \ 171 "$HTTPD_ROOT_PATH"/access.log | 172 grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] " 173 174' 175 176test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ 177 "$ROOT_PATH"/test_repo_clone main 178 179test_expect_success 'push to password-protected repository (user in URL)' ' 180 test_commit pw-user && 181 set_askpass user@host pass@host && 182 git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD && 183 git rev-parse --verify HEAD >expect && 184 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \ 185 rev-parse --verify HEAD >actual && 186 test_cmp expect actual 187' 188 189test_expect_failure 'user was prompted only once for password' ' 190 expect_askpass pass user@host 191' 192 193test_expect_failure 'push to password-protected repository (no user in URL)' ' 194 test_commit pw-nouser && 195 set_askpass user@host pass@host && 196 git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD && 197 expect_askpass both user@host && 198 git rev-parse --verify HEAD >expect && 199 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \ 200 rev-parse --verify HEAD >actual && 201 test_cmp expect actual 202' 203 204test_expect_success 'push to password-protected repository (netrc)' ' 205 test_commit pw-netrc && 206 echo "default login user@host password pass@host" >"$HOME/.netrc" && 207 GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD && 208 git rev-parse --verify HEAD >expect && 209 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \ 210 rev-parse --verify HEAD >actual && 211 test_cmp expect actual 212' 213 214test_done