Code

09edd2387bd4fb603f8eb2d2611be950ced322d2
[git.git] / t / t5540-http-push.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
4 #
6 test_description='test http-push
8 This test runs various sanity checks on http-push.'
10 . ./test-lib.sh
12 ROOT_PATH="$PWD"
13 LIB_HTTPD_DAV=t
14 LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'}
16 if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
17 then
18         say "skipping test, USE_CURL_MULTI is not defined"
19         test_done
20 fi
22 . "$TEST_DIRECTORY"/lib-httpd.sh
23 start_httpd
25 test_expect_success 'setup remote repository' '
26         cd "$ROOT_PATH" &&
27         mkdir test_repo &&
28         cd test_repo &&
29         git init &&
30         : >path1 &&
31         git add path1 &&
32         test_tick &&
33         git commit -m initial &&
34         cd - &&
35         git clone --bare test_repo test_repo.git &&
36         cd test_repo.git &&
37         git --bare update-server-info &&
38         mv hooks/post-update.sample hooks/post-update &&
39         ORIG_HEAD=$(git rev-parse --verify HEAD) &&
40         cd - &&
41         mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
42 '
44 test_expect_success 'clone remote repository' '
45         cd "$ROOT_PATH" &&
46         git clone $HTTPD_URL/test_repo.git test_repo_clone
47 '
49 test_expect_success 'push to remote repository with packed refs' '
50         cd "$ROOT_PATH"/test_repo_clone &&
51         : >path2 &&
52         git add path2 &&
53         test_tick &&
54         git commit -m path2 &&
55         HEAD=$(git rev-parse --verify HEAD) &&
56         git push &&
57         (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
58          test $HEAD = $(git rev-parse --verify HEAD))
59 '
61 test_expect_failure 'push already up-to-date' '
62         git push
63 '
65 test_expect_success 'push to remote repository with unpacked refs' '
66         (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
67          rm packed-refs &&
68          git update-ref refs/heads/master $ORIG_HEAD &&
69          git --bare update-server-info) &&
70         git push &&
71         (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
72          test $HEAD = $(git rev-parse --verify HEAD))
73 '
75 test_expect_success 'http-push fetches unpacked objects' '
76         cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
77                 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
79         git clone $HTTPD_URL/test_repo_unpacked.git \
80                 "$ROOT_PATH"/fetch_unpacked &&
82         # By reset, we force git to retrieve the object
83         (cd "$ROOT_PATH"/fetch_unpacked &&
84          git reset --hard HEAD^ &&
85          git remote rm origin &&
86          git reflog expire --expire=0 --all &&
87          git prune &&
88          git push -f -v $HTTPD_URL/test_repo_unpacked.git master)
89 '
91 test_expect_success 'http-push fetches packed objects' '
92         cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
93                 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
95         git clone $HTTPD_URL/test_repo_packed.git \
96                 "$ROOT_PATH"/test_repo_clone_packed &&
98         (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
99          git --bare repack &&
100          git --bare prune-packed) &&
102         # By reset, we force git to retrieve the packed object
103         (cd "$ROOT_PATH"/test_repo_clone_packed &&
104          git reset --hard HEAD^ &&
105          git remote rm origin &&
106          git reflog expire --expire=0 --all &&
107          git prune &&
108          git push -f -v $HTTPD_URL/test_repo_packed.git master)
111 test_expect_success 'create and delete remote branch' '
112         cd "$ROOT_PATH"/test_repo_clone &&
113         git checkout -b dev &&
114         : >path3 &&
115         git add path3 &&
116         test_tick &&
117         git commit -m dev &&
118         git push origin dev &&
119         git fetch &&
120         git push origin :dev &&
121         git fetch &&
122         test_must_fail git show-ref --verify refs/remotes/origin/dev
125 test_expect_success 'MKCOL sends directory names with trailing slashes' '
127         ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
131 x1="[0-9a-f]"
132 x2="$x1$x1"
133 x5="$x1$x1$x1$x1$x1"
134 x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"
135 x40="$x38$x2"
137 test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
138         sed -e "s/PUT /OP /" -e "s/MOVE /OP /" "$HTTPD_ROOT_PATH"/access.log |
139         grep -e "\"OP .*/objects/$x2/${x38}_$x40 HTTP/[.0-9]*\" 20[0-9] "
143 stop_httpd
145 test_done