blob: 37fe87541127887742530a8f8859f1dd369d3f34 [file] [log] [blame]
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +01001#!/bin/sh
2#
3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
4#
5
Shawn O. Pearce7da4e222009-10-30 17:47:47 -07006test_description='test WebDAV http-push
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +01007
8This test runs various sanity checks on http-push.'
9
10. ./test-lib.sh
11
Mike Hommey96086262008-07-07 21:02:50 +020012if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
13then
14 say "skipping test, USE_CURL_MULTI is not defined"
15 test_done
Mike Hommey96086262008-07-07 21:02:50 +020016fi
17
Clemens Buchacher859d1fb2009-10-30 17:47:45 -070018LIB_HTTPD_DAV=t
19LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'}
Junio C Hamanobfdbee92008-08-08 02:26:28 -070020. "$TEST_DIRECTORY"/lib-httpd.sh
Clemens Buchacher859d1fb2009-10-30 17:47:45 -070021ROOT_PATH="$PWD"
Jeff King75318a32009-02-25 03:32:08 -050022start_httpd
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +010023
24test_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 &&
Petr Baudis7dce9912008-08-12 00:34:46 +020037 mv hooks/post-update.sample hooks/post-update &&
Shawn O. Pearceae4efe12009-10-30 17:47:30 -070038 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +010039 cd - &&
Mike Hommey13b54812008-07-07 21:02:37 +020040 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +010041'
Jeff King3b2eb182008-06-14 03:25:56 -040042
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +010043test_expect_success 'clone remote repository' '
44 cd "$ROOT_PATH" &&
Shawn O. Pearce024bb122009-10-30 17:47:46 -070045 git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +010046'
47
Shawn O. Pearceae4efe12009-10-30 17:47:30 -070048test_expect_success 'push to remote repository with packed refs' '
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +010049 cd "$ROOT_PATH"/test_repo_clone &&
50 : >path2 &&
51 git add path2 &&
52 test_tick &&
53 git commit -m path2 &&
Johannes Schindelin8ee09ac2009-01-17 16:41:41 +010054 HEAD=$(git rev-parse --verify HEAD) &&
Mike Hommeyb5cd2d12008-07-07 23:06:46 +020055 git push &&
Johannes Schindelin8ee09ac2009-01-17 16:41:41 +010056 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
57 test $HEAD = $(git rev-parse --verify HEAD))
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +010058'
59
Clemens Buchacherd8f67d22009-10-30 17:47:31 -070060test_expect_success 'push already up-to-date' '
Shawn O. Pearceae4efe12009-10-30 17:47:30 -070061 git push
62'
63
64test_expect_success 'push to remote repository with unpacked refs' '
Johannes Schindelin8ee09ac2009-01-17 16:41:41 +010065 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
66 rm packed-refs &&
Shawn O. Pearceae4efe12009-10-30 17:47:30 -070067 git update-ref refs/heads/master $ORIG_HEAD &&
68 git --bare update-server-info) &&
Johannes Schindelin8ee09ac2009-01-17 16:41:41 +010069 git push &&
70 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
71 test $HEAD = $(git rev-parse --verify HEAD))
72'
73
Tay Ray Chuan4f662502009-06-06 16:43:27 +080074test_expect_success 'http-push fetches unpacked objects' '
Tay Ray Chuan242a9072009-06-06 16:43:23 +080075 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
76 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
77
Shawn O. Pearce024bb122009-10-30 17:47:46 -070078 git clone $HTTPD_URL/dumb/test_repo_unpacked.git \
Tay Ray Chuan242a9072009-06-06 16:43:23 +080079 "$ROOT_PATH"/fetch_unpacked &&
80
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 &&
Shawn O. Pearce024bb122009-10-30 17:47:46 -070087 git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master)
Tay Ray Chuan242a9072009-06-06 16:43:23 +080088'
89
Tay Ray Chuan4f662502009-06-06 16:43:27 +080090test_expect_success 'http-push fetches packed objects' '
Tay Ray Chuan86d99f62009-06-06 16:43:24 +080091 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
92 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
93
Shawn O. Pearce024bb122009-10-30 17:47:46 -070094 git clone $HTTPD_URL/dumb/test_repo_packed.git \
Tay Ray Chuan86d99f62009-06-06 16:43:24 +080095 "$ROOT_PATH"/test_repo_clone_packed &&
96
97 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
98 git --bare repack &&
99 git --bare prune-packed) &&
100
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 &&
Shawn O. Pearce024bb122009-10-30 17:47:46 -0700107 git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master)
Tay Ray Chuan86d99f62009-06-06 16:43:24 +0800108'
109
Johannes Schindelin8ee09ac2009-01-17 16:41:41 +0100110test_expect_success 'create and delete remote branch' '
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +0100111 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 &&
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +0100118 git push origin :dev &&
Stephan Beyerd492b312008-07-12 17:47:52 +0200119 test_must_fail git show-ref --verify refs/remotes/origin/dev
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +0100120'
121
Johannes Schindelin466ddf92009-01-17 16:11:51 +0100122test_expect_success 'MKCOL sends directory names with trailing slashes' '
123
124 ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
125
126'
127
Jay Soffian25918382009-02-26 18:44:40 -0500128x1="[0-9a-f]"
129x2="$x1$x1"
130x5="$x1$x1$x1$x1$x1"
131x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"
132x40="$x38$x2"
Tay Ray Chuandfab7c12009-02-14 17:52:14 +0800133
Jay Soffian25918382009-02-26 18:44:40 -0500134test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
135 sed -e "s/PUT /OP /" -e "s/MOVE /OP /" "$HTTPD_ROOT_PATH"/access.log |
136 grep -e "\"OP .*/objects/$x2/${x38}_$x40 HTTP/[.0-9]*\" 20[0-9] "
Tay Ray Chuandfab7c12009-02-14 17:52:14 +0800137
138'
139
Tay Ray Chuan6cbd6e92010-03-02 18:49:26 +0800140test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
141 "$ROOT_PATH"/test_repo_clone master
142
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +0100143stop_httpd
144
145test_done