Imported Upstream version 1.8.0
[platform/upstream/git.git] / t / t5540-http-push.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
4 #
5
6 test_description='test WebDAV http-push
7
8 This test runs various sanity checks on http-push.'
9
10 . ./test-lib.sh
11
12 if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
13 then
14         skip_all="skipping test, USE_CURL_MULTI is not defined"
15         test_done
16 fi
17
18 LIB_HTTPD_DAV=t
19 LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'}
20 . "$TEST_DIRECTORY"/lib-httpd.sh
21 ROOT_PATH="$PWD"
22 start_httpd
23
24 test_expect_success 'setup remote repository' '
25         cd "$ROOT_PATH" &&
26         mkdir test_repo &&
27         cd test_repo &&
28         git init &&
29         : >path1 &&
30         git add path1 &&
31         test_tick &&
32         git commit -m initial &&
33         cd - &&
34         git clone --bare test_repo test_repo.git &&
35         cd test_repo.git &&
36         git --bare update-server-info &&
37         mv hooks/post-update.sample hooks/post-update &&
38         ORIG_HEAD=$(git rev-parse --verify HEAD) &&
39         cd - &&
40         mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
41 '
42
43 test_expect_success 'create password-protected repository' '
44         mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb" &&
45         cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
46                "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git"
47 '
48
49 setup_askpass_helper
50
51 test_expect_success 'clone remote repository' '
52         cd "$ROOT_PATH" &&
53         git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone
54 '
55
56 test_expect_success 'push to remote repository with packed refs' '
57         cd "$ROOT_PATH"/test_repo_clone &&
58         : >path2 &&
59         git add path2 &&
60         test_tick &&
61         git commit -m path2 &&
62         HEAD=$(git rev-parse --verify HEAD) &&
63         git push &&
64         (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
65          test $HEAD = $(git rev-parse --verify HEAD))
66 '
67
68 test_expect_success 'push already up-to-date' '
69         git push
70 '
71
72 test_expect_success 'push to remote repository with unpacked refs' '
73         (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
74          rm packed-refs &&
75          git update-ref refs/heads/master $ORIG_HEAD &&
76          git --bare update-server-info) &&
77         git push &&
78         (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
79          test $HEAD = $(git rev-parse --verify HEAD))
80 '
81
82 test_expect_success 'http-push fetches unpacked objects' '
83         cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
84                 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
85
86         git clone $HTTPD_URL/dumb/test_repo_unpacked.git \
87                 "$ROOT_PATH"/fetch_unpacked &&
88
89         # By reset, we force git to retrieve the object
90         (cd "$ROOT_PATH"/fetch_unpacked &&
91          git reset --hard HEAD^ &&
92          git remote rm origin &&
93          git reflog expire --expire=0 --all &&
94          git prune &&
95          git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master)
96 '
97
98 test_expect_success 'http-push fetches packed objects' '
99         cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
100                 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
101
102         git clone $HTTPD_URL/dumb/test_repo_packed.git \
103                 "$ROOT_PATH"/test_repo_clone_packed &&
104
105         (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
106          git --bare repack &&
107          git --bare prune-packed) &&
108
109         # By reset, we force git to retrieve the packed object
110         (cd "$ROOT_PATH"/test_repo_clone_packed &&
111          git reset --hard HEAD^ &&
112          git remote remove origin &&
113          git reflog expire --expire=0 --all &&
114          git prune &&
115          git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master)
116 '
117
118 test_expect_success 'create and delete remote branch' '
119         cd "$ROOT_PATH"/test_repo_clone &&
120         git checkout -b dev &&
121         : >path3 &&
122         git add path3 &&
123         test_tick &&
124         git commit -m dev &&
125         git push origin dev &&
126         git push origin :dev &&
127         test_must_fail git show-ref --verify refs/remotes/origin/dev
128 '
129
130 test_expect_success 'MKCOL sends directory names with trailing slashes' '
131
132         ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
133
134 '
135
136 x1="[0-9a-f]"
137 x2="$x1$x1"
138 x5="$x1$x1$x1$x1$x1"
139 x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"
140 x40="$x38$x2"
141
142 test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
143         sed \
144                 -e "s/PUT /OP /" \
145                 -e "s/MOVE /OP /" \
146             -e "s|/objects/$x2/${x38}_$x40|WANTED_PATH_REQUEST|" \
147                 "$HTTPD_ROOT_PATH"/access.log |
148         grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] "
149
150 '
151
152 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
153         "$ROOT_PATH"/test_repo_clone master
154
155 test_expect_success 'push to password-protected repository (user in URL)' '
156         test_commit pw-user &&
157         set_askpass user@host &&
158         git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
159         git rev-parse --verify HEAD >expect &&
160         git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
161                 rev-parse --verify HEAD >actual &&
162         test_cmp expect actual
163 '
164
165 test_expect_failure 'user was prompted only once for password' '
166         expect_askpass pass user@host
167 '
168
169 test_expect_failure 'push to password-protected repository (no user in URL)' '
170         test_commit pw-nouser &&
171         set_askpass user@host &&
172         git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
173         expect_askpass both user@host
174         git rev-parse --verify HEAD >expect &&
175         git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
176                 rev-parse --verify HEAD >actual &&
177         test_cmp expect actual
178 '
179
180 stop_httpd
181
182 test_done