]>
Commit | Line | Data |
---|---|---|
faa4bc35 CB |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at> | |
4 | # | |
5 | ||
7da4e228 | 6 | test_description='test WebDAV http-push |
faa4bc35 CB |
7 | |
8 | This test runs various sanity checks on http-push.' | |
9 | ||
028cb644 | 10 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
11 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
12 | ||
faa4bc35 CB |
13 | . ./test-lib.sh |
14 | ||
96086262 MH |
15 | if git http-push > /dev/null 2>&1 || [ $? -eq 128 ] |
16 | then | |
fadb5156 | 17 | skip_all="skipping test, USE_CURL_MULTI is not defined" |
96086262 | 18 | test_done |
96086262 MH |
19 | fi |
20 | ||
8c21d820 HWN |
21 | if test_have_prereq !REFFILES |
22 | then | |
23 | skip_all='skipping test; dumb HTTP protocol not supported with reftable.' | |
24 | test_done | |
25 | fi | |
26 | ||
859d1fb4 | 27 | LIB_HTTPD_DAV=t |
bfdbee98 | 28 | . "$TEST_DIRECTORY"/lib-httpd.sh |
859d1fb4 | 29 | ROOT_PATH="$PWD" |
75318a3b | 30 | start_httpd |
faa4bc35 CB |
31 | |
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 && | |
94945322 ÆAB |
45 | test_hook --setup post-update <<-\EOF && |
46 | exec git update-server-info | |
47 | EOF | |
ae4efe19 | 48 | ORIG_HEAD=$(git rev-parse --verify HEAD) && |
faa4bc35 | 49 | cd - && |
13b5481e | 50 | mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH" |
faa4bc35 | 51 | ' |
3b2eb186 | 52 | |
0521710a JK |
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" | |
57 | ' | |
58 | ||
e837936c | 59 | setup_askpass_helper |
0521710a | 60 | |
faa4bc35 CB |
61 | test_expect_success 'clone remote repository' ' |
62 | cd "$ROOT_PATH" && | |
024bb125 | 63 | git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone |
faa4bc35 CB |
64 | ' |
65 | ||
ae4efe19 | 66 | test_expect_success 'push to remote repository with packed refs' ' |
faa4bc35 CB |
67 | cd "$ROOT_PATH"/test_repo_clone && |
68 | : >path2 && | |
69 | git add path2 && | |
70 | test_tick && | |
71 | git commit -m path2 && | |
8ee09acd | 72 | HEAD=$(git rev-parse --verify HEAD) && |
b5cd2d1e | 73 | git push && |
8ee09acd JS |
74 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && |
75 | test $HEAD = $(git rev-parse --verify HEAD)) | |
faa4bc35 CB |
76 | ' |
77 | ||
d8f67d20 | 78 | test_expect_success 'push already up-to-date' ' |
ae4efe19 SP |
79 | git push |
80 | ' | |
81 | ||
82 | test_expect_success 'push to remote repository with unpacked refs' ' | |
8ee09acd JS |
83 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && |
84 | rm packed-refs && | |
028cb644 | 85 | git update-ref refs/heads/main $ORIG_HEAD && |
ae4efe19 | 86 | git --bare update-server-info) && |
8ee09acd JS |
87 | git push && |
88 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && | |
89 | test $HEAD = $(git rev-parse --verify HEAD)) | |
90 | ' | |
91 | ||
4f66250d | 92 | test_expect_success 'http-push fetches unpacked objects' ' |
242a9077 TRC |
93 | cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ |
94 | "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git && | |
95 | ||
024bb125 | 96 | git clone $HTTPD_URL/dumb/test_repo_unpacked.git \ |
242a9077 TRC |
97 | "$ROOT_PATH"/fetch_unpacked && |
98 | ||
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 && | |
028cb644 | 105 | git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git main) |
242a9077 TRC |
106 | ' |
107 | ||
4f66250d | 108 | test_expect_success 'http-push fetches packed objects' ' |
86d99f6d TRC |
109 | cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ |
110 | "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && | |
111 | ||
024bb125 | 112 | git clone $HTTPD_URL/dumb/test_repo_packed.git \ |
86d99f6d TRC |
113 | "$ROOT_PATH"/test_repo_clone_packed && |
114 | ||
115 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && | |
116 | git --bare repack && | |
117 | git --bare prune-packed) && | |
118 | ||
119 | # By reset, we force git to retrieve the packed object | |
120 | (cd "$ROOT_PATH"/test_repo_clone_packed && | |
121 | git reset --hard HEAD^ && | |
e17dba8f | 122 | git remote remove origin && |
86d99f6d TRC |
123 | git reflog expire --expire=0 --all && |
124 | git prune && | |
028cb644 | 125 | git push -f -v $HTTPD_URL/dumb/test_repo_packed.git main) |
86d99f6d TRC |
126 | ' |
127 | ||
8ee09acd | 128 | test_expect_success 'create and delete remote branch' ' |
faa4bc35 CB |
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 && | |
faa4bc35 | 136 | git push origin :dev && |
d492b31c | 137 | test_must_fail git show-ref --verify refs/remotes/origin/dev |
faa4bc35 CB |
138 | ' |
139 | ||
64472d15 | 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 | |
154 | ' | |
155 | ||
466ddf90 JS |
156 | test_expect_success 'MKCOL sends directory names with trailing slashes' ' |
157 | ||
158 | ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log | |
159 | ||
160 | ' | |
161 | ||
2591838b JS |
162 | x1="[0-9a-f]" |
163 | x2="$x1$x1" | |
1b8f39fb | 164 | xtrunc=$(echo $OID_REGEX | sed -e "s/\[0-9a-f\]\[0-9a-f\]//") |
dfab7c14 | 165 | |
2591838b | 166 | test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' ' |
f6918da7 BG |
167 | sed \ |
168 | -e "s/PUT /OP /" \ | |
169 | -e "s/MOVE /OP /" \ | |
1b8f39fb | 170 | -e "s|/objects/$x2/${xtrunc}_$OID_REGEX|WANTED_PATH_REQUEST|" \ |
f6918da7 BG |
171 | "$HTTPD_ROOT_PATH"/access.log | |
172 | grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] " | |
dfab7c14 TRC |
173 | |
174 | ' | |
175 | ||
6cbd6e92 | 176 | test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ |
028cb644 | 177 | "$ROOT_PATH"/test_repo_clone main |
6cbd6e92 | 178 | |
a4ddbc33 | 179 | test_expect_success 'push to password-protected repository (user in URL)' ' |
0521710a | 180 | test_commit pw-user && |
afbf5ca5 | 181 | set_askpass user@host pass@host && |
0521710a JK |
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 | |
187 | ' | |
188 | ||
e837936c JK |
189 | test_expect_failure 'user was prompted only once for password' ' |
190 | expect_askpass pass user@host | |
191 | ' | |
192 | ||
0521710a JK |
193 | test_expect_failure 'push to password-protected repository (no user in URL)' ' |
194 | test_commit pw-nouser && | |
afbf5ca5 | 195 | set_askpass user@host pass@host && |
0521710a | 196 | git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD && |
8fb26872 | 197 | expect_askpass both user@host && |
0521710a JK |
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 | |
202 | ' | |
203 | ||
faa4bc35 | 204 | test_done |