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.'
12 if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
14 skip_all="skipping test, USE_CURL_MULTI is not defined"
19 . "$TEST_DIRECTORY"/lib-httpd.sh
23 test_expect_success 'setup remote repository' '
31 git commit -m initial &&
33 git clone --bare test_repo test_repo.git &&
35 git --bare update-server-info &&
36 mv hooks/post-update.sample hooks/post-update &&
37 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
39 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
42 test_expect_success 'create password-protected repository' '
43 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb" &&
44 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
45 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git"
50 test_expect_success 'clone remote repository' '
52 git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone
55 test_expect_success 'push to remote repository with packed refs' '
56 cd "$ROOT_PATH"/test_repo_clone &&
60 git commit -m path2 &&
61 HEAD=$(git rev-parse --verify HEAD) &&
63 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
64 test $HEAD = $(git rev-parse --verify HEAD))
67 test_expect_success 'push already up-to-date' '
71 test_expect_success 'push to remote repository with unpacked refs' '
72 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
74 git update-ref refs/heads/master $ORIG_HEAD &&
75 git --bare update-server-info) &&
77 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
78 test $HEAD = $(git rev-parse --verify HEAD))
81 test_expect_success 'http-push fetches unpacked objects' '
82 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
83 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
85 git clone $HTTPD_URL/dumb/test_repo_unpacked.git \
86 "$ROOT_PATH"/fetch_unpacked &&
88 # By reset, we force git to retrieve the object
89 (cd "$ROOT_PATH"/fetch_unpacked &&
90 git reset --hard HEAD^ &&
91 git remote rm origin &&
92 git reflog expire --expire=0 --all &&
94 git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master)
97 test_expect_success 'http-push fetches packed objects' '
98 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
99 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
101 git clone $HTTPD_URL/dumb/test_repo_packed.git \
102 "$ROOT_PATH"/test_repo_clone_packed &&
104 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
106 git --bare prune-packed) &&
108 # By reset, we force git to retrieve the packed object
109 (cd "$ROOT_PATH"/test_repo_clone_packed &&
110 git reset --hard HEAD^ &&
111 git remote remove origin &&
112 git reflog expire --expire=0 --all &&
114 git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master)
117 test_expect_success 'create and delete remote branch' '
118 cd "$ROOT_PATH"/test_repo_clone &&
119 git checkout -b dev &&
124 git push origin dev &&
125 git push origin :dev &&
126 test_must_fail git show-ref --verify refs/remotes/origin/dev
129 test_expect_success 'MKCOL sends directory names with trailing slashes' '
131 ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
138 x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"
141 test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
145 -e "s|/objects/$x2/${x38}_$x40|WANTED_PATH_REQUEST|" \
146 "$HTTPD_ROOT_PATH"/access.log |
147 grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] "
151 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
152 "$ROOT_PATH"/test_repo_clone master
154 test_expect_success 'push to password-protected repository (user in URL)' '
155 test_commit pw-user &&
156 set_askpass user@host pass@host &&
157 git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
158 git rev-parse --verify HEAD >expect &&
159 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
160 rev-parse --verify HEAD >actual &&
161 test_cmp expect actual
164 test_expect_failure 'user was prompted only once for password' '
165 expect_askpass pass user@host
168 test_expect_failure 'push to password-protected repository (no user in URL)' '
169 test_commit pw-nouser &&
170 set_askpass user@host pass@host &&
171 git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
172 expect_askpass both user@host &&
173 git rev-parse --verify HEAD >expect &&
174 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
175 rev-parse --verify HEAD >actual &&
176 test_cmp expect actual