Merge branch 'jd/prompt-upstream-mark'
[alt-git.git] / t / t5540-http-push-webdav.sh
blobb0dbacf0b9b5ee8300368c1defe54cf87ce3ee05
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-lib.sh
15 if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
16 then
17 skip_all="skipping test, USE_CURL_MULTI is not defined"
18 test_done
21 if test_have_prereq !REFFILES
22 then
23 skip_all='skipping test; dumb HTTP protocol not supported with reftable.'
24 test_done
27 LIB_HTTPD_DAV=t
28 . "$TEST_DIRECTORY"/lib-httpd.sh
29 ROOT_PATH="$PWD"
30 start_httpd
32 test_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 mv hooks/post-update.sample hooks/post-update &&
46 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
47 cd - &&
48 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
51 test_expect_success 'create password-protected repository' '
52 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb" &&
53 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
54 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git"
57 setup_askpass_helper
59 test_expect_success 'clone remote repository' '
60 cd "$ROOT_PATH" &&
61 git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone
64 test_expect_success 'push to remote repository with packed refs' '
65 cd "$ROOT_PATH"/test_repo_clone &&
66 : >path2 &&
67 git add path2 &&
68 test_tick &&
69 git commit -m path2 &&
70 HEAD=$(git rev-parse --verify HEAD) &&
71 git push &&
72 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
73 test $HEAD = $(git rev-parse --verify HEAD))
76 test_expect_success 'push already up-to-date' '
77 git push
80 test_expect_success 'push to remote repository with unpacked refs' '
81 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
82 rm packed-refs &&
83 git update-ref refs/heads/main $ORIG_HEAD &&
84 git --bare update-server-info) &&
85 git push &&
86 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
87 test $HEAD = $(git rev-parse --verify HEAD))
90 test_expect_success 'http-push fetches unpacked objects' '
91 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
92 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
94 git clone $HTTPD_URL/dumb/test_repo_unpacked.git \
95 "$ROOT_PATH"/fetch_unpacked &&
97 # By reset, we force git to retrieve the object
98 (cd "$ROOT_PATH"/fetch_unpacked &&
99 git reset --hard HEAD^ &&
100 git remote rm origin &&
101 git reflog expire --expire=0 --all &&
102 git prune &&
103 git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git main)
106 test_expect_success 'http-push fetches packed objects' '
107 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
108 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
110 git clone $HTTPD_URL/dumb/test_repo_packed.git \
111 "$ROOT_PATH"/test_repo_clone_packed &&
113 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
114 git --bare repack &&
115 git --bare prune-packed) &&
117 # By reset, we force git to retrieve the packed object
118 (cd "$ROOT_PATH"/test_repo_clone_packed &&
119 git reset --hard HEAD^ &&
120 git remote remove origin &&
121 git reflog expire --expire=0 --all &&
122 git prune &&
123 git push -f -v $HTTPD_URL/dumb/test_repo_packed.git main)
126 test_expect_success 'create and delete remote branch' '
127 cd "$ROOT_PATH"/test_repo_clone &&
128 git checkout -b dev &&
129 : >path3 &&
130 git add path3 &&
131 test_tick &&
132 git commit -m dev &&
133 git push origin dev &&
134 git push origin :dev &&
135 test_must_fail git show-ref --verify refs/remotes/origin/dev
138 test_expect_success 'non-force push fails if not up to date' '
139 git init --bare "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_conflict.git &&
140 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_conflict.git update-server-info &&
141 git clone $HTTPD_URL/dumb/test_repo_conflict.git "$ROOT_PATH"/c1 &&
142 git clone $HTTPD_URL/dumb/test_repo_conflict.git "$ROOT_PATH"/c2 &&
143 test_commit -C "$ROOT_PATH/c1" path1 &&
144 git -C "$ROOT_PATH/c1" push origin HEAD &&
145 git -C "$ROOT_PATH/c2" pull &&
146 test_commit -C "$ROOT_PATH/c1" path2 &&
147 git -C "$ROOT_PATH/c1" push origin HEAD &&
148 test_commit -C "$ROOT_PATH/c2" path3 &&
149 git -C "$ROOT_PATH/c1" log --graph --all &&
150 git -C "$ROOT_PATH/c2" log --graph --all &&
151 test_must_fail git -C "$ROOT_PATH/c2" push origin HEAD
154 test_expect_success 'MKCOL sends directory names with trailing slashes' '
156 ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
160 x1="[0-9a-f]"
161 x2="$x1$x1"
162 xtrunc=$(echo $OID_REGEX | sed -e "s/\[0-9a-f\]\[0-9a-f\]//")
164 test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
165 sed \
166 -e "s/PUT /OP /" \
167 -e "s/MOVE /OP /" \
168 -e "s|/objects/$x2/${xtrunc}_$OID_REGEX|WANTED_PATH_REQUEST|" \
169 "$HTTPD_ROOT_PATH"/access.log |
170 grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] "
174 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
175 "$ROOT_PATH"/test_repo_clone main
177 test_expect_success 'push to password-protected repository (user in URL)' '
178 test_commit pw-user &&
179 set_askpass user@host pass@host &&
180 git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
181 git rev-parse --verify HEAD >expect &&
182 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
183 rev-parse --verify HEAD >actual &&
184 test_cmp expect actual
187 test_expect_failure 'user was prompted only once for password' '
188 expect_askpass pass user@host
191 test_expect_failure 'push to password-protected repository (no user in URL)' '
192 test_commit pw-nouser &&
193 set_askpass user@host pass@host &&
194 git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
195 expect_askpass both user@host &&
196 git rev-parse --verify HEAD >expect &&
197 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
198 rev-parse --verify HEAD >actual &&
199 test_cmp expect actual
202 test_done