3 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
6 test_description
='test WebDAV http-push
8 This test runs various sanity checks on http-push.'
10 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
11 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
13 TEST_PASSES_SANITIZE_LEAK
=true
16 if git http-push
> /dev
/null
2>&1 ||
[ $?
-eq 128 ]
18 skip_all
="skipping test, USE_CURL_MULTI is not defined"
22 if test_have_prereq
!REFFILES
24 skip_all
='skipping test; dumb HTTP protocol not supported with reftable.'
29 .
"$TEST_DIRECTORY"/lib-httpd.sh
33 test_expect_success
'setup remote repository' '
41 git commit -m initial &&
43 git clone --bare test_repo test_repo.git &&
45 git --bare update-server-info &&
46 test_hook --setup post-update <<-\EOF &&
47 exec git update-server-info
49 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
51 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
54 test_expect_success
'create password-protected repository' '
55 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb" &&
56 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
57 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git"
62 test_expect_success
'clone remote repository' '
64 git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone
67 test_expect_success
'push to remote repository with packed refs' '
68 cd "$ROOT_PATH"/test_repo_clone &&
72 git commit -m path2 &&
73 HEAD=$(git rev-parse --verify HEAD) &&
75 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
76 test $HEAD = $(git rev-parse --verify HEAD))
79 test_expect_success
'push already up-to-date' '
83 test_expect_success
'push to remote repository with unpacked refs' '
84 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
86 git update-ref refs/heads/main $ORIG_HEAD &&
87 git --bare update-server-info) &&
89 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
90 test $HEAD = $(git rev-parse --verify HEAD))
93 test_expect_success
'http-push fetches unpacked objects' '
94 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
95 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
97 git clone $HTTPD_URL/dumb/test_repo_unpacked.git \
98 "$ROOT_PATH"/fetch_unpacked &&
100 # By reset, we force git to retrieve the object
101 (cd "$ROOT_PATH"/fetch_unpacked &&
102 git reset --hard HEAD^ &&
103 git remote rm origin &&
104 git reflog expire --expire=0 --all &&
106 git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git main)
109 test_expect_success
'http-push fetches packed objects' '
110 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
111 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
113 git clone $HTTPD_URL/dumb/test_repo_packed.git \
114 "$ROOT_PATH"/test_repo_clone_packed &&
116 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
118 git --bare prune-packed) &&
120 # By reset, we force git to retrieve the packed object
121 (cd "$ROOT_PATH"/test_repo_clone_packed &&
122 git reset --hard HEAD^ &&
123 git remote remove origin &&
124 git reflog expire --expire=0 --all &&
126 git push -f -v $HTTPD_URL/dumb/test_repo_packed.git main)
129 test_expect_success
'create and delete remote branch' '
130 cd "$ROOT_PATH"/test_repo_clone &&
131 git checkout -b dev &&
136 git push origin dev &&
137 git push origin :dev &&
138 test_must_fail git show-ref --verify refs/remotes/origin/dev
141 test_expect_success
'non-force push fails if not up to date' '
142 git init --bare "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_conflict.git &&
143 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_conflict.git update-server-info &&
144 git clone $HTTPD_URL/dumb/test_repo_conflict.git "$ROOT_PATH"/c1 &&
145 git clone $HTTPD_URL/dumb/test_repo_conflict.git "$ROOT_PATH"/c2 &&
146 test_commit -C "$ROOT_PATH/c1" path1 &&
147 git -C "$ROOT_PATH/c1" push origin HEAD &&
148 git -C "$ROOT_PATH/c2" pull &&
149 test_commit -C "$ROOT_PATH/c1" path2 &&
150 git -C "$ROOT_PATH/c1" push origin HEAD &&
151 test_commit -C "$ROOT_PATH/c2" path3 &&
152 git -C "$ROOT_PATH/c1" log --graph --all &&
153 git -C "$ROOT_PATH/c2" log --graph --all &&
154 test_must_fail git -C "$ROOT_PATH/c2" push origin HEAD
157 test_expect_success
'MKCOL sends directory names with trailing slashes' '
159 ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
165 xtrunc
=$
(echo $OID_REGEX |
sed -e "s/\[0-9a-f\]\[0-9a-f\]//")
167 test_expect_success
'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
171 -e "s|/objects/$x2/${xtrunc}_$OID_REGEX|WANTED_PATH_REQUEST|" \
172 "$HTTPD_ROOT_PATH"/access.log |
173 grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] "
177 test_http_push_nonff
"$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
178 "$ROOT_PATH"/test_repo_clone main
180 test_expect_success
'push to password-protected repository (user in URL)' '
181 test_commit pw-user &&
182 set_askpass user@host pass@host &&
183 git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
184 git rev-parse --verify HEAD >expect &&
185 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
186 rev-parse --verify HEAD >actual &&
187 test_cmp expect actual
190 test_expect_failure
'user was prompted only once for password' '
191 expect_askpass pass user@host
194 test_expect_failure
'push to password-protected repository (no user in URL)' '
195 test_commit pw-nouser &&
196 set_askpass user@host pass@host &&
197 git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
198 expect_askpass both user@host &&
199 git rev-parse --verify HEAD >expect &&
200 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
201 rev-parse --verify HEAD >actual &&
202 test_cmp expect actual