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
15 if git http-push
> /dev
/null
2>&1 ||
[ $?
-eq 128 ]
17 skip_all
="skipping test, USE_CURL_MULTI is not defined"
21 if test_have_prereq
!REFFILES
23 skip_all
='skipping test; dumb HTTP protocol not supported with reftable.'
28 .
"$TEST_DIRECTORY"/lib-httpd.sh
32 test_expect_success
'setup remote repository' '
40 git commit -m initial &&
42 git clone --bare test_repo test_repo.git &&
44 git --bare update-server-info &&
45 test_hook --setup post-update <<-\EOF &&
46 exec git update-server-info
48 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
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"
61 test_expect_success
'clone remote repository' '
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 &&
71 git commit -m path2 &&
72 HEAD=$(git rev-parse --verify HEAD) &&
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' '
82 test_expect_success
'push to remote repository with unpacked refs' '
83 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
85 git update-ref refs/heads/main $ORIG_HEAD &&
86 git --bare update-server-info) &&
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 &&
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 &&
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 &&
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 &&
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
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' '
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