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"
22 .
"$TEST_DIRECTORY"/lib-httpd.sh
26 test_expect_success
'setup remote repository' '
34 git commit -m initial &&
36 git clone --bare test_repo test_repo.git &&
38 git --bare update-server-info &&
39 mv hooks/post-update.sample hooks/post-update &&
40 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
42 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
45 test_expect_success
'create password-protected repository' '
46 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb" &&
47 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
48 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git"
53 test_expect_success
'clone remote repository' '
55 git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone
58 test_expect_success
'push to remote repository with packed refs' '
59 cd "$ROOT_PATH"/test_repo_clone &&
63 git commit -m path2 &&
64 HEAD=$(git rev-parse --verify HEAD) &&
66 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
67 test $HEAD = $(git rev-parse --verify HEAD))
70 test_expect_success
'push already up-to-date' '
74 test_expect_success
'push to remote repository with unpacked refs' '
75 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
77 git update-ref refs/heads/main $ORIG_HEAD &&
78 git --bare update-server-info) &&
80 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
81 test $HEAD = $(git rev-parse --verify HEAD))
84 test_expect_success
'http-push fetches unpacked objects' '
85 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
86 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
88 git clone $HTTPD_URL/dumb/test_repo_unpacked.git \
89 "$ROOT_PATH"/fetch_unpacked &&
91 # By reset, we force git to retrieve the object
92 (cd "$ROOT_PATH"/fetch_unpacked &&
93 git reset --hard HEAD^ &&
94 git remote rm origin &&
95 git reflog expire --expire=0 --all &&
97 git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git main)
100 test_expect_success
'http-push fetches packed objects' '
101 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
102 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
104 git clone $HTTPD_URL/dumb/test_repo_packed.git \
105 "$ROOT_PATH"/test_repo_clone_packed &&
107 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
109 git --bare prune-packed) &&
111 # By reset, we force git to retrieve the packed object
112 (cd "$ROOT_PATH"/test_repo_clone_packed &&
113 git reset --hard HEAD^ &&
114 git remote remove origin &&
115 git reflog expire --expire=0 --all &&
117 git push -f -v $HTTPD_URL/dumb/test_repo_packed.git main)
120 test_expect_success
'create and delete remote branch' '
121 cd "$ROOT_PATH"/test_repo_clone &&
122 git checkout -b dev &&
127 git push origin dev &&
128 git push origin :dev &&
129 test_must_fail git show-ref --verify refs/remotes/origin/dev
132 test_expect_success
'non-force push fails if not up to date' '
133 git init --bare "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_conflict.git &&
134 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_conflict.git update-server-info &&
135 git clone $HTTPD_URL/dumb/test_repo_conflict.git "$ROOT_PATH"/c1 &&
136 git clone $HTTPD_URL/dumb/test_repo_conflict.git "$ROOT_PATH"/c2 &&
137 test_commit -C "$ROOT_PATH/c1" path1 &&
138 git -C "$ROOT_PATH/c1" push origin HEAD &&
139 git -C "$ROOT_PATH/c2" pull &&
140 test_commit -C "$ROOT_PATH/c1" path2 &&
141 git -C "$ROOT_PATH/c1" push origin HEAD &&
142 test_commit -C "$ROOT_PATH/c2" path3 &&
143 git -C "$ROOT_PATH/c1" log --graph --all &&
144 git -C "$ROOT_PATH/c2" log --graph --all &&
145 test_must_fail git -C "$ROOT_PATH/c2" push origin HEAD
148 test_expect_success
'MKCOL sends directory names with trailing slashes' '
150 ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
156 xtrunc
=$
(echo $OID_REGEX |
sed -e "s/\[0-9a-f\]\[0-9a-f\]//")
158 test_expect_success
'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
162 -e "s|/objects/$x2/${xtrunc}_$OID_REGEX|WANTED_PATH_REQUEST|" \
163 "$HTTPD_ROOT_PATH"/access.log |
164 grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] "
168 test_http_push_nonff
"$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
169 "$ROOT_PATH"/test_repo_clone main
171 test_expect_success
'push to password-protected repository (user in URL)' '
172 test_commit pw-user &&
173 set_askpass user@host pass@host &&
174 git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
175 git rev-parse --verify HEAD >expect &&
176 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
177 rev-parse --verify HEAD >actual &&
178 test_cmp expect actual
181 test_expect_failure
'user was prompted only once for password' '
182 expect_askpass pass user@host
185 test_expect_failure
'push to password-protected repository (no user in URL)' '
186 test_commit pw-nouser &&
187 set_askpass user@host pass@host &&
188 git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
189 expect_askpass both user@host &&
190 git rev-parse --verify HEAD >expect &&
191 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
192 rev-parse --verify HEAD >actual &&
193 test_cmp expect actual