git-p4 tests: refactor and cleanup
[git/jrn.git] / t / t5540-http-push.sh
blob64767d87055c9ad65a225432b5193497c9fad405
1 #!/bin/sh
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.'
10 . ./test-lib.sh
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
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
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"
43 test_expect_success 'clone remote repository' '
44 cd "$ROOT_PATH" &&
45 git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone
48 test_expect_success 'push to remote repository with packed refs' '
49 cd "$ROOT_PATH"/test_repo_clone &&
50 : >path2 &&
51 git add path2 &&
52 test_tick &&
53 git commit -m path2 &&
54 HEAD=$(git rev-parse --verify HEAD) &&
55 git push &&
56 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
57 test $HEAD = $(git rev-parse --verify HEAD))
60 test_expect_success 'push already up-to-date' '
61 git push
64 test_expect_success 'push to remote repository with unpacked refs' '
65 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
66 rm packed-refs &&
67 git update-ref refs/heads/master $ORIG_HEAD &&
68 git --bare update-server-info) &&
69 git push &&
70 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
71 test $HEAD = $(git rev-parse --verify HEAD))
74 test_expect_success 'http-push fetches unpacked objects' '
75 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
76 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
78 git clone $HTTPD_URL/dumb/test_repo_unpacked.git \
79 "$ROOT_PATH"/fetch_unpacked &&
81 # By reset, we force git to retrieve the object
82 (cd "$ROOT_PATH"/fetch_unpacked &&
83 git reset --hard HEAD^ &&
84 git remote rm origin &&
85 git reflog expire --expire=0 --all &&
86 git prune &&
87 git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master)
90 test_expect_success 'http-push fetches packed objects' '
91 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
92 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
94 git clone $HTTPD_URL/dumb/test_repo_packed.git \
95 "$ROOT_PATH"/test_repo_clone_packed &&
97 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
98 git --bare repack &&
99 git --bare prune-packed) &&
101 # By reset, we force git to retrieve the packed object
102 (cd "$ROOT_PATH"/test_repo_clone_packed &&
103 git reset --hard HEAD^ &&
104 git remote rm origin &&
105 git reflog expire --expire=0 --all &&
106 git prune &&
107 git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master)
110 test_expect_success 'create and delete remote branch' '
111 cd "$ROOT_PATH"/test_repo_clone &&
112 git checkout -b dev &&
113 : >path3 &&
114 git add path3 &&
115 test_tick &&
116 git commit -m dev &&
117 git push origin dev &&
118 git push origin :dev &&
119 test_must_fail git show-ref --verify refs/remotes/origin/dev
122 test_expect_success 'MKCOL sends directory names with trailing slashes' '
124 ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
128 x1="[0-9a-f]"
129 x2="$x1$x1"
130 x5="$x1$x1$x1$x1$x1"
131 x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"
132 x40="$x38$x2"
134 test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
135 sed \
136 -e "s/PUT /OP /" \
137 -e "s/MOVE /OP /" \
138 -e "s|/objects/$x2/${x38}_$x40|WANTED_PATH_REQUEST|" \
139 "$HTTPD_ROOT_PATH"/access.log |
140 grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] "
144 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
145 "$ROOT_PATH"/test_repo_clone master
147 stop_httpd
149 test_done