push.default doc: explain simple after upstream
[git/git.git] / t / t5541-http-push.sh
CommitLineData
7da4e228
SP
1#!/bin/sh
2#
3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
4#
5
6test_description='test smart pushing over http via http-backend'
7. ./test-lib.sh
8
9if test -n "$NO_CURL"; then
fadb5156 10 skip_all='skipping test, git built without http support'
7da4e228
SP
11 test_done
12fi
13
14ROOT_PATH="$PWD"
15LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5541'}
16. "$TEST_DIRECTORY"/lib-httpd.sh
d336572f 17. "$TEST_DIRECTORY"/lib-terminal.sh
7da4e228
SP
18start_httpd
19
20test_expect_success 'setup remote repository' '
21 cd "$ROOT_PATH" &&
22 mkdir test_repo &&
23 cd test_repo &&
24 git init &&
25 : >path1 &&
26 git add path1 &&
27 test_tick &&
28 git commit -m initial &&
29 cd - &&
30 git clone --bare test_repo test_repo.git &&
31 cd test_repo.git &&
32 git config http.receivepack true &&
e32a4581 33 git config core.logallrefupdates true &&
7da4e228
SP
34 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
35 cd - &&
36 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
37'
38
9ee6bcd3
TRC
39cat >exp <<EOF
40GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
41POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
42EOF
d8fab072 43test_expect_success 'no empty path components' '
9ee6bcd3
TRC
44 # In the URL, add a trailing slash, and see if git appends yet another
45 # slash.
7da4e228 46 cd "$ROOT_PATH" &&
9ee6bcd3
TRC
47 git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
48
49 sed -e "
50 s/^.* \"//
51 s/\"//
52 s/ [1-9][0-9]*\$//
53 s/^GET /GET /
54 " >act <"$HTTPD_ROOT_PATH"/access.log &&
55
56 # Clear the log, so that it does not affect the "used receive-pack
57 # service" test which reads the log too.
58 #
59 # We do this before the actual comparison to ensure the log is cleared.
60 echo > "$HTTPD_ROOT_PATH"/access.log &&
61
62 test_cmp exp act
63'
64
65test_expect_success 'clone remote repository' '
66 rm -rf test_repo_clone &&
7da4e228
SP
67 git clone $HTTPD_URL/smart/test_repo.git test_repo_clone
68'
69
0cc6330d 70test_expect_success 'push to remote repository (standard)' '
7da4e228
SP
71 cd "$ROOT_PATH"/test_repo_clone &&
72 : >path2 &&
73 git add path2 &&
74 test_tick &&
75 git commit -m path2 &&
76 HEAD=$(git rev-parse --verify HEAD) &&
0cc6330d
TRC
77 GIT_CURL_VERBOSE=1 git push -v -v 2>err &&
78 ! grep "Expect: 100-continue" err &&
79 grep "POST git-receive-pack ([0-9]* bytes)" err &&
7da4e228
SP
80 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
81 test $HEAD = $(git rev-parse --verify HEAD))
82'
83
84test_expect_success 'push already up-to-date' '
85 git push
86'
87
88test_expect_success 'create and delete remote branch' '
89 cd "$ROOT_PATH"/test_repo_clone &&
90 git checkout -b dev &&
91 : >path3 &&
92 git add path3 &&
93 test_tick &&
94 git commit -m dev &&
95 git push origin dev &&
96 git push origin :dev &&
97 test_must_fail git show-ref --verify refs/remotes/origin/dev
98'
99
5238cbf6
SP
100cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
101#!/bin/sh
102exit 1
103EOF
104chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
105
106cat >exp <<EOF
107remote: error: hook declined to update refs/heads/dev2
108To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
109 ! [remote rejected] dev2 -> dev2 (hook declined)
d202a513 110error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
5238cbf6
SP
111EOF
112
113test_expect_success 'rejected update prints status' '
114 cd "$ROOT_PATH"/test_repo_clone &&
115 git checkout -b dev2 &&
116 : >path4 &&
117 git add path4 &&
118 test_tick &&
119 git commit -m dev2 &&
120 test_must_fail git push origin dev2 2>act &&
121 sed -e "/^remote: /s/ *$//" <act >cmp &&
122 test_cmp exp cmp
123'
124rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
125
7da4e228 126cat >exp <<EOF
9ee6bcd3 127
7da4e228
SP
128GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
129POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
130GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
131POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
132GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
133GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
134POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
135GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
136POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
5238cbf6
SP
137GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
138POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
7da4e228
SP
139EOF
140test_expect_success 'used receive-pack service' '
141 sed -e "
142 s/^.* \"//
143 s/\"//
144 s/ [1-9][0-9]*\$//
145 s/^GET /GET /
146 " >act <"$HTTPD_ROOT_PATH"/access.log &&
147 test_cmp exp act
148'
149
6cbd6e92
TRC
150test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
151 "$ROOT_PATH"/test_repo_clone master
19452374 152
08d63a42 153test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
7b69079b
TRC
154 # create a dissimilarly-named remote ref so that git is unable to match the
155 # two refs (viz. local, remote) unless an explicit refspec is provided.
156 git push origin master:retsam
157
158 echo "change changed" > path2 &&
159 git commit -a -m path2 --amend &&
160
161 # push master too; this ensures there is at least one '"'push'"' command to
162 # the remote helper and triggers interaction with the helper.
b32227e7 163 test_must_fail git push -v origin +master master:retsam >output 2>&1'
7b69079b 164
b32227e7 165test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: remote output' '
7b69079b 166 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
b32227e7
ÆAB
167 grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
168'
7b69079b 169
b3e1900a 170test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
0aff719f 171 test_i18ngrep "Updates were rejected because" \
9567f082 172 output
7b69079b
TRC
173'
174
0cc6330d
TRC
175test_expect_success 'push (chunked)' '
176 git checkout master &&
177 test_commit commit path3 &&
178 HEAD=$(git rev-parse --verify HEAD) &&
179 git config http.postbuffer 4 &&
180 test_when_finished "git config --unset http.postbuffer" &&
181 git push -v -v origin $BRANCH 2>err &&
182 grep "POST git-receive-pack (chunked)" err &&
183 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
184 test $HEAD = $(git rev-parse --verify HEAD))
185'
186
02f79147
JK
187test_expect_success 'push --all can push to empty repo' '
188 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-all.git &&
189 git init --bare "$d" &&
190 git --git-dir="$d" config http.receivepack true &&
191 git push --all "$HTTPD_URL"/smart/empty-all.git
192'
193
194test_expect_success 'push --mirror can push to empty repo' '
195 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-mirror.git &&
196 git init --bare "$d" &&
197 git --git-dir="$d" config http.receivepack true &&
198 git push --mirror "$HTTPD_URL"/smart/empty-mirror.git
199'
200
201test_expect_success 'push --all to repo with alternates' '
202 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
203 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-all.git &&
204 git clone --bare --shared "$s" "$d" &&
205 git --git-dir="$d" config http.receivepack true &&
206 git --git-dir="$d" repack -adl &&
207 git push --all "$HTTPD_URL"/smart/alternates-all.git
208'
209
210test_expect_success 'push --mirror to repo with alternates' '
211 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
212 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-mirror.git &&
213 git clone --bare --shared "$s" "$d" &&
214 git --git-dir="$d" config http.receivepack true &&
215 git --git-dir="$d" repack -adl &&
216 git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git
217'
218
c207e34f
CB
219test_expect_success TTY 'quiet push' '
220 cd "$ROOT_PATH"/test_repo_clone &&
221 test_commit quiet &&
222 test_terminal git push --quiet --no-progress 2>&1 | tee output &&
223 test_cmp /dev/null output
224'
225
e32a4581
JK
226test_expect_success 'http push gives sane defaults to reflog' '
227 cd "$ROOT_PATH"/test_repo_clone &&
228 test_commit reflog-test &&
229 git push "$HTTPD_URL"/smart/test_repo.git &&
230 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
231 log -g -1 --format="%gn <%ge>" >actual &&
232 echo "anonymous <anonymous@http.127.0.0.1>" >expect &&
233 test_cmp expect actual
234'
235
236test_expect_success 'http push respects GIT_COMMITTER_* in reflog' '
237 cd "$ROOT_PATH"/test_repo_clone &&
238 test_commit custom-reflog-test &&
239 git push "$HTTPD_URL"/smart_custom_env/test_repo.git &&
240 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
241 log -g -1 --format="%gn <%ge>" >actual &&
242 echo "Custom User <custom@example.com>" >expect &&
243 test_cmp expect actual
244'
245
7da4e228
SP
246stop_httpd
247test_done