]>
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 | ||
10 | . ./test-lib.sh | |
11 | ||
96086262 MH |
12 | if git http-push > /dev/null 2>&1 || [ $? -eq 128 ] |
13 | then | |
fadb5156 | 14 | skip_all="skipping test, USE_CURL_MULTI is not defined" |
96086262 | 15 | test_done |
96086262 MH |
16 | fi |
17 | ||
859d1fb4 | 18 | LIB_HTTPD_DAV=t |
bfdbee98 | 19 | . "$TEST_DIRECTORY"/lib-httpd.sh |
859d1fb4 | 20 | ROOT_PATH="$PWD" |
75318a3b | 21 | start_httpd |
faa4bc35 CB |
22 | |
23 | test_expect_success 'setup remote repository' ' | |
24 | cd "$ROOT_PATH" && | |
25 | mkdir test_repo && | |
26 | cd test_repo && | |
27 | git init && | |
28 | : >path1 && | |
29 | git add path1 && | |
30 | test_tick && | |
31 | git commit -m initial && | |
32 | cd - && | |
33 | git clone --bare test_repo test_repo.git && | |
34 | cd test_repo.git && | |
35 | git --bare update-server-info && | |
7dce9918 | 36 | mv hooks/post-update.sample hooks/post-update && |
ae4efe19 | 37 | ORIG_HEAD=$(git rev-parse --verify HEAD) && |
faa4bc35 | 38 | cd - && |
13b5481e | 39 | mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH" |
faa4bc35 | 40 | ' |
3b2eb186 | 41 | |
0521710a JK |
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" | |
46 | ' | |
47 | ||
e837936c | 48 | setup_askpass_helper |
0521710a | 49 | |
faa4bc35 CB |
50 | test_expect_success 'clone remote repository' ' |
51 | cd "$ROOT_PATH" && | |
024bb125 | 52 | git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone |
faa4bc35 CB |
53 | ' |
54 | ||
ae4efe19 | 55 | test_expect_success 'push to remote repository with packed refs' ' |
faa4bc35 CB |
56 | cd "$ROOT_PATH"/test_repo_clone && |
57 | : >path2 && | |
58 | git add path2 && | |
59 | test_tick && | |
60 | git commit -m path2 && | |
8ee09acd | 61 | HEAD=$(git rev-parse --verify HEAD) && |
b5cd2d1e | 62 | git push && |
8ee09acd JS |
63 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && |
64 | test $HEAD = $(git rev-parse --verify HEAD)) | |
faa4bc35 CB |
65 | ' |
66 | ||
d8f67d20 | 67 | test_expect_success 'push already up-to-date' ' |
ae4efe19 SP |
68 | git push |
69 | ' | |
70 | ||
71 | test_expect_success 'push to remote repository with unpacked refs' ' | |
8ee09acd JS |
72 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && |
73 | rm packed-refs && | |
ae4efe19 SP |
74 | git update-ref refs/heads/master $ORIG_HEAD && |
75 | git --bare update-server-info) && | |
8ee09acd JS |
76 | git push && |
77 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && | |
78 | test $HEAD = $(git rev-parse --verify HEAD)) | |
79 | ' | |
80 | ||
4f66250d | 81 | test_expect_success 'http-push fetches unpacked objects' ' |
242a9077 TRC |
82 | cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ |
83 | "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git && | |
84 | ||
024bb125 | 85 | git clone $HTTPD_URL/dumb/test_repo_unpacked.git \ |
242a9077 TRC |
86 | "$ROOT_PATH"/fetch_unpacked && |
87 | ||
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 && | |
93 | git prune && | |
024bb125 | 94 | git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master) |
242a9077 TRC |
95 | ' |
96 | ||
4f66250d | 97 | test_expect_success 'http-push fetches packed objects' ' |
86d99f6d TRC |
98 | cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ |
99 | "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && | |
100 | ||
024bb125 | 101 | git clone $HTTPD_URL/dumb/test_repo_packed.git \ |
86d99f6d TRC |
102 | "$ROOT_PATH"/test_repo_clone_packed && |
103 | ||
104 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && | |
105 | git --bare repack && | |
106 | git --bare prune-packed) && | |
107 | ||
108 | # By reset, we force git to retrieve the packed object | |
109 | (cd "$ROOT_PATH"/test_repo_clone_packed && | |
110 | git reset --hard HEAD^ && | |
e17dba8f | 111 | git remote remove origin && |
86d99f6d TRC |
112 | git reflog expire --expire=0 --all && |
113 | git prune && | |
024bb125 | 114 | git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master) |
86d99f6d TRC |
115 | ' |
116 | ||
8ee09acd | 117 | test_expect_success 'create and delete remote branch' ' |
faa4bc35 CB |
118 | cd "$ROOT_PATH"/test_repo_clone && |
119 | git checkout -b dev && | |
120 | : >path3 && | |
121 | git add path3 && | |
122 | test_tick && | |
123 | git commit -m dev && | |
124 | git push origin dev && | |
faa4bc35 | 125 | git push origin :dev && |
d492b31c | 126 | test_must_fail git show-ref --verify refs/remotes/origin/dev |
faa4bc35 CB |
127 | ' |
128 | ||
64472d15 | 129 | test_expect_success 'non-force push fails if not up to date' ' |
130 | git init --bare "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_conflict.git && | |
131 | git -C "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_conflict.git update-server-info && | |
132 | git clone $HTTPD_URL/dumb/test_repo_conflict.git "$ROOT_PATH"/c1 && | |
133 | git clone $HTTPD_URL/dumb/test_repo_conflict.git "$ROOT_PATH"/c2 && | |
134 | test_commit -C "$ROOT_PATH/c1" path1 && | |
135 | git -C "$ROOT_PATH/c1" push origin HEAD && | |
136 | git -C "$ROOT_PATH/c2" pull && | |
137 | test_commit -C "$ROOT_PATH/c1" path2 && | |
138 | git -C "$ROOT_PATH/c1" push origin HEAD && | |
139 | test_commit -C "$ROOT_PATH/c2" path3 && | |
140 | git -C "$ROOT_PATH/c1" log --graph --all && | |
141 | git -C "$ROOT_PATH/c2" log --graph --all && | |
142 | test_must_fail git -C "$ROOT_PATH/c2" push origin HEAD | |
143 | ' | |
144 | ||
466ddf90 JS |
145 | test_expect_success 'MKCOL sends directory names with trailing slashes' ' |
146 | ||
147 | ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log | |
148 | ||
149 | ' | |
150 | ||
2591838b JS |
151 | x1="[0-9a-f]" |
152 | x2="$x1$x1" | |
1b8f39fb | 153 | xtrunc=$(echo $OID_REGEX | sed -e "s/\[0-9a-f\]\[0-9a-f\]//") |
dfab7c14 | 154 | |
2591838b | 155 | test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' ' |
f6918da7 BG |
156 | sed \ |
157 | -e "s/PUT /OP /" \ | |
158 | -e "s/MOVE /OP /" \ | |
1b8f39fb | 159 | -e "s|/objects/$x2/${xtrunc}_$OID_REGEX|WANTED_PATH_REQUEST|" \ |
f6918da7 BG |
160 | "$HTTPD_ROOT_PATH"/access.log | |
161 | grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] " | |
dfab7c14 TRC |
162 | |
163 | ' | |
164 | ||
6cbd6e92 TRC |
165 | test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ |
166 | "$ROOT_PATH"/test_repo_clone master | |
167 | ||
a4ddbc33 | 168 | test_expect_success 'push to password-protected repository (user in URL)' ' |
0521710a | 169 | test_commit pw-user && |
afbf5ca5 | 170 | set_askpass user@host pass@host && |
0521710a JK |
171 | git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD && |
172 | git rev-parse --verify HEAD >expect && | |
173 | git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \ | |
174 | rev-parse --verify HEAD >actual && | |
175 | test_cmp expect actual | |
176 | ' | |
177 | ||
e837936c JK |
178 | test_expect_failure 'user was prompted only once for password' ' |
179 | expect_askpass pass user@host | |
180 | ' | |
181 | ||
0521710a JK |
182 | test_expect_failure 'push to password-protected repository (no user in URL)' ' |
183 | test_commit pw-nouser && | |
afbf5ca5 | 184 | set_askpass user@host pass@host && |
0521710a | 185 | git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD && |
8fb26872 | 186 | expect_askpass both user@host && |
0521710a JK |
187 | git rev-parse --verify HEAD >expect && |
188 | git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \ | |
189 | rev-parse --verify HEAD >actual && | |
190 | test_cmp expect actual | |
191 | ' | |
192 | ||
faa4bc35 | 193 | test_done |