Code

Merge branch 'cb/maint-t5541-make-server-port-portable' into maint-1.7.8
[git.git] / t / t5541-http-push.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
4 #
6 test_description='test smart pushing over http via http-backend'
7 . ./test-lib.sh
9 if test -n "$NO_CURL"; then
10         skip_all='skipping test, git built without http support'
11         test_done
12 fi
14 ROOT_PATH="$PWD"
15 LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5541'}
16 . "$TEST_DIRECTORY"/lib-httpd.sh
17 start_httpd
19 test_expect_success 'setup remote repository' '
20         cd "$ROOT_PATH" &&
21         mkdir test_repo &&
22         cd test_repo &&
23         git init &&
24         : >path1 &&
25         git add path1 &&
26         test_tick &&
27         git commit -m initial &&
28         cd - &&
29         git clone --bare test_repo test_repo.git &&
30         cd test_repo.git &&
31         git config http.receivepack true &&
32         ORIG_HEAD=$(git rev-parse --verify HEAD) &&
33         cd - &&
34         mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
35 '
37 cat >exp <<EOF
38 GET  /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
39 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
40 EOF
41 test_expect_success 'no empty path components' '
42         # In the URL, add a trailing slash, and see if git appends yet another
43         # slash.
44         cd "$ROOT_PATH" &&
45         git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
47         sed -e "
48                 s/^.* \"//
49                 s/\"//
50                 s/ [1-9][0-9]*\$//
51                 s/^GET /GET  /
52         " >act <"$HTTPD_ROOT_PATH"/access.log &&
54         # Clear the log, so that it does not affect the "used receive-pack
55         # service" test which reads the log too.
56         #
57         # We do this before the actual comparison to ensure the log is cleared.
58         echo > "$HTTPD_ROOT_PATH"/access.log &&
60         test_cmp exp act
61 '
63 test_expect_success 'clone remote repository' '
64         rm -rf test_repo_clone &&
65         git clone $HTTPD_URL/smart/test_repo.git test_repo_clone
66 '
68 test_expect_success 'push to remote repository (standard)' '
69         cd "$ROOT_PATH"/test_repo_clone &&
70         : >path2 &&
71         git add path2 &&
72         test_tick &&
73         git commit -m path2 &&
74         HEAD=$(git rev-parse --verify HEAD) &&
75         GIT_CURL_VERBOSE=1 git push -v -v 2>err &&
76         ! grep "Expect: 100-continue" err &&
77         grep "POST git-receive-pack ([0-9]* bytes)" err &&
78         (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
79          test $HEAD = $(git rev-parse --verify HEAD))
80 '
82 test_expect_success 'push already up-to-date' '
83         git push
84 '
86 test_expect_success 'create and delete remote branch' '
87         cd "$ROOT_PATH"/test_repo_clone &&
88         git checkout -b dev &&
89         : >path3 &&
90         git add path3 &&
91         test_tick &&
92         git commit -m dev &&
93         git push origin dev &&
94         git push origin :dev &&
95         test_must_fail git show-ref --verify refs/remotes/origin/dev
96 '
98 cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
99 #!/bin/sh
100 exit 1
101 EOF
102 chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
104 cat >exp <<EOF
105 remote: error: hook declined to update refs/heads/dev2
106 To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
107  ! [remote rejected] dev2 -> dev2 (hook declined)
108 error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
109 EOF
111 test_expect_success 'rejected update prints status' '
112         cd "$ROOT_PATH"/test_repo_clone &&
113         git checkout -b dev2 &&
114         : >path4 &&
115         git add path4 &&
116         test_tick &&
117         git commit -m dev2 &&
118         test_must_fail git push origin dev2 2>act &&
119         sed -e "/^remote: /s/ *$//" <act >cmp &&
120         test_cmp exp cmp
122 rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
124 cat >exp <<EOF
126 GET  /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
127 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
128 GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
129 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
130 GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
131 GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
132 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
133 GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
134 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
135 GET  /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
136 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
137 EOF
138 test_expect_success 'used receive-pack service' '
139         sed -e "
140                 s/^.* \"//
141                 s/\"//
142                 s/ [1-9][0-9]*\$//
143                 s/^GET /GET  /
144         " >act <"$HTTPD_ROOT_PATH"/access.log &&
145         test_cmp exp act
148 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
149         "$ROOT_PATH"/test_repo_clone master
151 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
152         # create a dissimilarly-named remote ref so that git is unable to match the
153         # two refs (viz. local, remote) unless an explicit refspec is provided.
154         git push origin master:retsam
156         echo "change changed" > path2 &&
157         git commit -a -m path2 --amend &&
159         # push master too; this ensures there is at least one '"'push'"' command to
160         # the remote helper and triggers interaction with the helper.
161         test_must_fail git push -v origin +master master:retsam >output 2>&1'
163 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: remote output' '
164         grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
165         grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
168 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
169         test_i18ngrep "To prevent you from losing history, non-fast-forward updates were rejected" \
170                 output
173 test_expect_success 'push (chunked)' '
174         git checkout master &&
175         test_commit commit path3 &&
176         HEAD=$(git rev-parse --verify HEAD) &&
177         git config http.postbuffer 4 &&
178         test_when_finished "git config --unset http.postbuffer" &&
179         git push -v -v origin $BRANCH 2>err &&
180         grep "POST git-receive-pack (chunked)" err &&
181         (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
182          test $HEAD = $(git rev-parse --verify HEAD))
185 test_expect_success 'push --all can push to empty repo' '
186         d=$HTTPD_DOCUMENT_ROOT_PATH/empty-all.git &&
187         git init --bare "$d" &&
188         git --git-dir="$d" config http.receivepack true &&
189         git push --all "$HTTPD_URL"/smart/empty-all.git
192 test_expect_success 'push --mirror can push to empty repo' '
193         d=$HTTPD_DOCUMENT_ROOT_PATH/empty-mirror.git &&
194         git init --bare "$d" &&
195         git --git-dir="$d" config http.receivepack true &&
196         git push --mirror "$HTTPD_URL"/smart/empty-mirror.git
199 test_expect_success 'push --all to repo with alternates' '
200         s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
201         d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-all.git &&
202         git clone --bare --shared "$s" "$d" &&
203         git --git-dir="$d" config http.receivepack true &&
204         git --git-dir="$d" repack -adl &&
205         git push --all "$HTTPD_URL"/smart/alternates-all.git
208 test_expect_success 'push --mirror to repo with alternates' '
209         s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
210         d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-mirror.git &&
211         git clone --bare --shared "$s" "$d" &&
212         git --git-dir="$d" config http.receivepack true &&
213         git --git-dir="$d" repack -adl &&
214         git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git
217 stop_httpd
218 test_done