gitlab-ci: exercise Git on Windows
[git/gitster.git] / t / t5540-http-push-webdav.sh
blob27389b09081fbe46fe700bfcf117188303ed1753
1 #!/bin/sh
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
14 . ./test-lib.sh
16 if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
17 then
18 skip_all="skipping test, USE_CURL_MULTI is not defined"
19 test_done
22 if test_have_prereq !REFFILES
23 then
24 skip_all='skipping test; dumb HTTP protocol not supported with reftable.'
25 test_done
28 LIB_HTTPD_DAV=t
29 . "$TEST_DIRECTORY"/lib-httpd.sh
30 ROOT_PATH="$PWD"
31 start_httpd
33 test_expect_success 'setup remote repository' '
34 cd "$ROOT_PATH" &&
35 mkdir test_repo &&
36 cd test_repo &&
37 git init &&
38 : >path1 &&
39 git add path1 &&
40 test_tick &&
41 git commit -m initial &&
42 cd - &&
43 git clone --bare test_repo test_repo.git &&
44 cd test_repo.git &&
45 git --bare update-server-info &&
46 test_hook --setup post-update <<-\EOF &&
47 exec git update-server-info
48 EOF
49 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
50 cd - &&
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"
60 setup_askpass_helper
62 test_expect_success 'clone remote repository' '
63 cd "$ROOT_PATH" &&
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 &&
69 : >path2 &&
70 git add path2 &&
71 test_tick &&
72 git commit -m path2 &&
73 HEAD=$(git rev-parse --verify HEAD) &&
74 git push &&
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' '
80 git push
83 test_expect_success 'push to remote repository with unpacked refs' '
84 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
85 rm packed-refs &&
86 git update-ref refs/heads/main $ORIG_HEAD &&
87 git --bare update-server-info) &&
88 git push &&
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 &&
105 git prune &&
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 &&
117 git --bare repack &&
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 &&
125 git prune &&
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 &&
132 : >path3 &&
133 git add path3 &&
134 test_tick &&
135 git commit -m 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
163 x1="[0-9a-f]"
164 x2="$x1$x1"
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' '
168 sed \
169 -e "s/PUT /OP /" \
170 -e "s/MOVE /OP /" \
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
205 test_done