fix push --quiet: add 'quiet' capability to receive-pack
[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
c207e34f 8. "$TEST_DIRECTORY"/lib-terminal.sh
7da4e228
SP
9
10if test -n "$NO_CURL"; then
fadb5156 11 skip_all='skipping test, git built without http support'
7da4e228
SP
12 test_done
13fi
14
15ROOT_PATH="$PWD"
16LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5541'}
17. "$TEST_DIRECTORY"/lib-httpd.sh
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 &&
33 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
34 cd - &&
35 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
36'
37
9ee6bcd3
TRC
38cat >exp <<EOF
39GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
40POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
41EOF
d8fab072 42test_expect_success 'no empty path components' '
9ee6bcd3
TRC
43 # In the URL, add a trailing slash, and see if git appends yet another
44 # slash.
7da4e228 45 cd "$ROOT_PATH" &&
9ee6bcd3
TRC
46 git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
47
48 sed -e "
49 s/^.* \"//
50 s/\"//
51 s/ [1-9][0-9]*\$//
52 s/^GET /GET /
53 " >act <"$HTTPD_ROOT_PATH"/access.log &&
54
55 # Clear the log, so that it does not affect the "used receive-pack
56 # service" test which reads the log too.
57 #
58 # We do this before the actual comparison to ensure the log is cleared.
59 echo > "$HTTPD_ROOT_PATH"/access.log &&
60
61 test_cmp exp act
62'
63
64test_expect_success 'clone remote repository' '
65 rm -rf test_repo_clone &&
7da4e228
SP
66 git clone $HTTPD_URL/smart/test_repo.git test_repo_clone
67'
68
0cc6330d 69test_expect_success 'push to remote repository (standard)' '
7da4e228
SP
70 cd "$ROOT_PATH"/test_repo_clone &&
71 : >path2 &&
72 git add path2 &&
73 test_tick &&
74 git commit -m path2 &&
75 HEAD=$(git rev-parse --verify HEAD) &&
0cc6330d
TRC
76 GIT_CURL_VERBOSE=1 git push -v -v 2>err &&
77 ! grep "Expect: 100-continue" err &&
78 grep "POST git-receive-pack ([0-9]* bytes)" err &&
7da4e228
SP
79 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
80 test $HEAD = $(git rev-parse --verify HEAD))
81'
82
83test_expect_success 'push already up-to-date' '
84 git push
85'
86
87test_expect_success 'create and delete remote branch' '
88 cd "$ROOT_PATH"/test_repo_clone &&
89 git checkout -b dev &&
90 : >path3 &&
91 git add path3 &&
92 test_tick &&
93 git commit -m dev &&
94 git push origin dev &&
95 git push origin :dev &&
96 test_must_fail git show-ref --verify refs/remotes/origin/dev
97'
98
99cat >exp <<EOF
9ee6bcd3 100
7da4e228
SP
101GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
102POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
103GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
104POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
105GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
106GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
107POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
108GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
109POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
110EOF
111test_expect_success 'used receive-pack service' '
112 sed -e "
113 s/^.* \"//
114 s/\"//
115 s/ [1-9][0-9]*\$//
116 s/^GET /GET /
117 " >act <"$HTTPD_ROOT_PATH"/access.log &&
118 test_cmp exp act
119'
120
6cbd6e92
TRC
121test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
122 "$ROOT_PATH"/test_repo_clone master
19452374 123
08d63a42 124test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
7b69079b
TRC
125 # create a dissimilarly-named remote ref so that git is unable to match the
126 # two refs (viz. local, remote) unless an explicit refspec is provided.
127 git push origin master:retsam
128
129 echo "change changed" > path2 &&
130 git commit -a -m path2 --amend &&
131
132 # push master too; this ensures there is at least one '"'push'"' command to
133 # the remote helper and triggers interaction with the helper.
b32227e7 134 test_must_fail git push -v origin +master master:retsam >output 2>&1'
7b69079b 135
b32227e7 136test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: remote output' '
7b69079b 137 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
b32227e7
ÆAB
138 grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
139'
7b69079b 140
b3e1900a
JH
141test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
142 test_i18ngrep "To prevent you from losing history, non-fast-forward updates were rejected" \
9567f082 143 output
7b69079b
TRC
144'
145
0cc6330d
TRC
146test_expect_success 'push (chunked)' '
147 git checkout master &&
148 test_commit commit path3 &&
149 HEAD=$(git rev-parse --verify HEAD) &&
150 git config http.postbuffer 4 &&
151 test_when_finished "git config --unset http.postbuffer" &&
152 git push -v -v origin $BRANCH 2>err &&
153 grep "POST git-receive-pack (chunked)" err &&
154 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
155 test $HEAD = $(git rev-parse --verify HEAD))
156'
157
02f79147
JK
158test_expect_success 'push --all can push to empty repo' '
159 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-all.git &&
160 git init --bare "$d" &&
161 git --git-dir="$d" config http.receivepack true &&
162 git push --all "$HTTPD_URL"/smart/empty-all.git
163'
164
165test_expect_success 'push --mirror can push to empty repo' '
166 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-mirror.git &&
167 git init --bare "$d" &&
168 git --git-dir="$d" config http.receivepack true &&
169 git push --mirror "$HTTPD_URL"/smart/empty-mirror.git
170'
171
172test_expect_success 'push --all to repo with alternates' '
173 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
174 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-all.git &&
175 git clone --bare --shared "$s" "$d" &&
176 git --git-dir="$d" config http.receivepack true &&
177 git --git-dir="$d" repack -adl &&
178 git push --all "$HTTPD_URL"/smart/alternates-all.git
179'
180
181test_expect_success 'push --mirror to repo with alternates' '
182 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
183 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-mirror.git &&
184 git clone --bare --shared "$s" "$d" &&
185 git --git-dir="$d" config http.receivepack true &&
186 git --git-dir="$d" repack -adl &&
187 git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git
188'
189
c207e34f
CB
190test_expect_success TTY 'quiet push' '
191 cd "$ROOT_PATH"/test_repo_clone &&
192 test_commit quiet &&
193 test_terminal git push --quiet --no-progress 2>&1 | tee output &&
194 test_cmp /dev/null output
195'
196
7da4e228
SP
197stop_httpd
198test_done