3 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
6 test_description='test smart pushing over http via http-backend'
9 if test -n "$NO_CURL"; then
10 skip_all='skipping test, git built without http support'
15 LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5541'}
16 . "$TEST_DIRECTORY"/lib-httpd.sh
17 . "$TEST_DIRECTORY"/lib-terminal.sh
20 test_expect_success 'setup remote repository' '
28 git commit -m initial &&
30 git clone --bare test_repo test_repo.git &&
32 git config http.receivepack true &&
33 git config core.logallrefupdates true &&
34 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
36 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
40 GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
41 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
43 test_expect_success 'no empty path components' '
44 # In the URL, add a trailing slash, and see if git appends yet another
47 git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
54 " >act <"$HTTPD_ROOT_PATH"/access.log &&
56 # Clear the log, so that it does not affect the "used receive-pack
57 # service" test which reads the log too.
59 # We do this before the actual comparison to ensure the log is cleared.
60 echo > "$HTTPD_ROOT_PATH"/access.log &&
65 test_expect_success 'clone remote repository' '
66 rm -rf test_repo_clone &&
67 git clone $HTTPD_URL/smart/test_repo.git test_repo_clone
70 test_expect_success 'push to remote repository (standard)' '
71 cd "$ROOT_PATH"/test_repo_clone &&
75 git commit -m path2 &&
76 HEAD=$(git rev-parse --verify HEAD) &&
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 &&
80 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
81 test $HEAD = $(git rev-parse --verify HEAD))
84 test_expect_success 'push already up-to-date' '
88 test_expect_success 'create and delete remote branch' '
89 cd "$ROOT_PATH"/test_repo_clone &&
90 git checkout -b dev &&
95 git push origin dev &&
96 git push origin :dev &&
97 test_must_fail git show-ref --verify refs/remotes/origin/dev
100 cat >"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update" <<EOF
104 chmod a+x "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
107 remote: error: hook declined to update refs/heads/dev2
108 To http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git
109 ! [remote rejected] dev2 -> dev2 (hook declined)
110 error: failed to push some refs to 'http://127.0.0.1:$LIB_HTTPD_PORT/smart/test_repo.git'
113 test_expect_success 'rejected update prints status' '
114 cd "$ROOT_PATH"/test_repo_clone &&
115 git checkout -b dev2 &&
119 git commit -m dev2 &&
120 test_must_fail git push origin dev2 2>act &&
121 sed -e "/^remote: /s/ *$//" <act >cmp &&
124 rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
128 GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
129 POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
130 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
131 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
132 GET /smart/test_repo.git/info/refs?service=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 GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
138 POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
140 test_expect_success 'used receive-pack service' '
146 " >act <"$HTTPD_ROOT_PATH"/access.log &&
150 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
151 "$ROOT_PATH"/test_repo_clone master
153 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
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
158 echo "change changed" > path2 &&
159 git commit -a -m path2 --amend &&
161 # push master too; this ensures there is at least one '"'push'"' command to
162 # the remote helper and triggers interaction with the helper.
163 test_must_fail git push -v origin +master master:retsam >output 2>&1'
165 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: remote output' '
166 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
167 grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
170 test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
171 test_i18ngrep "Updates were rejected because" \
175 test_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))
187 test_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
194 test_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
201 test_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
210 test_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
219 test_expect_success TTY 'push shows progress when stderr is a tty' '
220 cd "$ROOT_PATH"/test_repo_clone &&
222 test_terminal git push >output 2>&1 &&
223 grep "^Writing objects" output
226 test_expect_success TTY 'push --quiet silences status and progress' '
227 cd "$ROOT_PATH"/test_repo_clone &&
229 test_terminal git push --quiet >output 2>&1 &&
230 test_cmp /dev/null output
233 test_expect_success TTY 'push --no-progress silences progress but not status' '
234 cd "$ROOT_PATH"/test_repo_clone &&
235 test_commit no-progress &&
236 test_terminal git push --no-progress >output 2>&1 &&
237 grep "^To http" output &&
238 ! grep "^Writing objects"
241 test_expect_success 'push --progress shows progress to non-tty' '
242 cd "$ROOT_PATH"/test_repo_clone &&
243 test_commit progress &&
244 git push --progress >output 2>&1 &&
245 grep "^To http" output &&
246 grep "^Writing objects" output
249 test_expect_success 'http push gives sane defaults to reflog' '
250 cd "$ROOT_PATH"/test_repo_clone &&
251 test_commit reflog-test &&
252 git push "$HTTPD_URL"/smart/test_repo.git &&
253 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
254 log -g -1 --format="%gn <%ge>" >actual &&
255 echo "anonymous <anonymous@http.127.0.0.1>" >expect &&
256 test_cmp expect actual
259 test_expect_success 'http push respects GIT_COMMITTER_* in reflog' '
260 cd "$ROOT_PATH"/test_repo_clone &&
261 test_commit custom-reflog-test &&
262 git push "$HTTPD_URL"/smart_custom_env/test_repo.git &&
263 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
264 log -g -1 --format="%gn <%ge>" >actual &&
265 echo "Custom User <custom@example.com>" >expect &&
266 test_cmp expect actual