]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5541-http-push.sh
configure: don't use -lintl when there is no gettext support
[thirdparty/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
17start_httpd
18
19test_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'
36
9ee6bcd3
TRC
37cat >exp <<EOF
38GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
39POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
40EOF
d8fab072 41test_expect_success 'no empty path components' '
9ee6bcd3
TRC
42 # In the URL, add a trailing slash, and see if git appends yet another
43 # slash.
7da4e228 44 cd "$ROOT_PATH" &&
9ee6bcd3
TRC
45 git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
46
47 sed -e "
48 s/^.* \"//
49 s/\"//
50 s/ [1-9][0-9]*\$//
51 s/^GET /GET /
52 " >act <"$HTTPD_ROOT_PATH"/access.log &&
53
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 &&
59
60 test_cmp exp act
61'
62
63test_expect_success 'clone remote repository' '
64 rm -rf test_repo_clone &&
7da4e228
SP
65 git clone $HTTPD_URL/smart/test_repo.git test_repo_clone
66'
67
0cc6330d 68test_expect_success 'push to remote repository (standard)' '
7da4e228
SP
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) &&
0cc6330d
TRC
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 &&
7da4e228
SP
78 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
79 test $HEAD = $(git rev-parse --verify HEAD))
80'
81
82test_expect_success 'push already up-to-date' '
83 git push
84'
85
86test_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'
97
98cat >exp <<EOF
9ee6bcd3 99
7da4e228
SP
100GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
101POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
102GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
103POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
104GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
105GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
106POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
107GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
108POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
109EOF
110test_expect_success 'used receive-pack service' '
111 sed -e "
112 s/^.* \"//
113 s/\"//
114 s/ [1-9][0-9]*\$//
115 s/^GET /GET /
116 " >act <"$HTTPD_ROOT_PATH"/access.log &&
117 test_cmp exp act
118'
119
6cbd6e92
TRC
120test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
121 "$ROOT_PATH"/test_repo_clone master
19452374 122
08d63a42 123test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' '
7b69079b
TRC
124 # create a dissimilarly-named remote ref so that git is unable to match the
125 # two refs (viz. local, remote) unless an explicit refspec is provided.
126 git push origin master:retsam
127
128 echo "change changed" > path2 &&
129 git commit -a -m path2 --amend &&
130
131 # push master too; this ensures there is at least one '"'push'"' command to
132 # the remote helper and triggers interaction with the helper.
b32227e7 133 test_must_fail git push -v origin +master master:retsam >output 2>&1'
7b69079b 134
b32227e7 135test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: remote output' '
7b69079b 136 grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output &&
b32227e7
ÆAB
137 grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output
138'
7b69079b 139
b3e1900a
JH
140test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: our output' '
141 test_i18ngrep "To prevent you from losing history, non-fast-forward updates were rejected" \
9567f082 142 output
7b69079b
TRC
143'
144
0cc6330d
TRC
145test_expect_success 'push (chunked)' '
146 git checkout master &&
147 test_commit commit path3 &&
148 HEAD=$(git rev-parse --verify HEAD) &&
149 git config http.postbuffer 4 &&
150 test_when_finished "git config --unset http.postbuffer" &&
151 git push -v -v origin $BRANCH 2>err &&
152 grep "POST git-receive-pack (chunked)" err &&
153 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
154 test $HEAD = $(git rev-parse --verify HEAD))
155'
156
02f79147
JK
157test_expect_success 'push --all can push to empty repo' '
158 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-all.git &&
159 git init --bare "$d" &&
160 git --git-dir="$d" config http.receivepack true &&
161 git push --all "$HTTPD_URL"/smart/empty-all.git
162'
163
164test_expect_success 'push --mirror can push to empty repo' '
165 d=$HTTPD_DOCUMENT_ROOT_PATH/empty-mirror.git &&
166 git init --bare "$d" &&
167 git --git-dir="$d" config http.receivepack true &&
168 git push --mirror "$HTTPD_URL"/smart/empty-mirror.git
169'
170
171test_expect_success 'push --all to repo with alternates' '
172 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
173 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-all.git &&
174 git clone --bare --shared "$s" "$d" &&
175 git --git-dir="$d" config http.receivepack true &&
176 git --git-dir="$d" repack -adl &&
177 git push --all "$HTTPD_URL"/smart/alternates-all.git
178'
179
180test_expect_success 'push --mirror to repo with alternates' '
181 s=$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git &&
182 d=$HTTPD_DOCUMENT_ROOT_PATH/alternates-mirror.git &&
183 git clone --bare --shared "$s" "$d" &&
184 git --git-dir="$d" config http.receivepack true &&
185 git --git-dir="$d" repack -adl &&
186 git push --mirror "$HTTPD_URL"/smart/alternates-mirror.git
187'
188
7da4e228
SP
189stop_httpd
190test_done