unit-tests: do not mistake `.pdb` files for being executable
[git.git] / t / t5540-http-push-webdav.sh
blob37db3dec0c5b3939c9cb6f2e6f6e383c80045c87
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 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"
53 test_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"
59 setup_askpass_helper
61 test_expect_success 'clone remote repository' '
62 cd "$ROOT_PATH" &&
63 git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone
66 test_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))
78 test_expect_success 'push already up-to-date' '
79 git push
82 test_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))
92 test_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 &&
96 git clone $HTTPD_URL/dumb/test_repo_unpacked.git \
97 "$ROOT_PATH"/fetch_unpacked &&
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)
108 test_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 &&
112 git clone $HTTPD_URL/dumb/test_repo_packed.git \
113 "$ROOT_PATH"/test_repo_clone_packed &&
115 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
116 git --bare repack &&
117 git --bare prune-packed) &&
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)
128 test_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
140 test_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
156 test_expect_success 'MKCOL sends directory names with trailing slashes' '
158 ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
162 x1="[0-9a-f]"
163 x2="$x1$x1"
164 xtrunc=$(echo $OID_REGEX | sed -e "s/\[0-9a-f\]\[0-9a-f\]//")
166 test_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] "
176 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
177 "$ROOT_PATH"/test_repo_clone main
179 test_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
189 test_expect_failure 'user was prompted only once for password' '
190 expect_askpass pass user@host
193 test_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
204 test_done