3 test_description='pushing to a repository using push options'
8 rm -rf workbench upstream &&
9 test_create_repo upstream &&
10 test_create_repo workbench &&
13 git config receive.denyCurrentBranch warn &&
14 mkdir -p .git/hooks &&
15 cat >.git/hooks/pre-receive <<-'EOF' &&
17 if test -n "$GIT_PUSH_OPTION_COUNT"; then
19 >hooks/pre-receive.push_options
20 while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
21 eval "value=\$GIT_PUSH_OPTION_$i"
22 echo $value >>hooks/pre-receive.push_options
27 chmod u+x .git/hooks/pre-receive
29 cat >.git/hooks/post-receive <<-'EOF' &&
31 if test -n "$GIT_PUSH_OPTION_COUNT"; then
33 >hooks/post-receive.push_options
34 while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
35 eval "value=\$GIT_PUSH_OPTION_$i"
36 echo $value >>hooks/post-receive.push_options
41 chmod u+x .git/hooks/post-receive
45 git remote add up ../upstream
49 # Compare the ref ($1) in upstream with a ref value from workbench ($2)
50 # i.e. test_refs second HEAD@{2}
53 git -C upstream rev-parse --verify "$1" >expect &&
54 git -C workbench rev-parse --verify "$2" >actual &&
55 test_cmp expect actual
58 test_expect_success 'one push option works for a single branch' '
60 git -C upstream config receive.advertisePushOptions true &&
64 git push --mirror up &&
66 git push --push-option=asdf up master
68 test_refs master master &&
69 echo "asdf" >expect &&
70 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
71 test_cmp expect upstream/.git/hooks/post-receive.push_options
74 test_expect_success 'push option denied by remote' '
76 git -C upstream config receive.advertisePushOptions false &&
80 git push --mirror up &&
82 test_must_fail git push --push-option=asdf up master
84 test_refs master HEAD@{1}
87 test_expect_success 'two push options work' '
89 git -C upstream config receive.advertisePushOptions true &&
93 git push --mirror up &&
95 git push --push-option=asdf --push-option="more structured text" up master
97 test_refs master master &&
98 printf "asdf\nmore structured text\n" >expect &&
99 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
100 test_cmp expect upstream/.git/hooks/post-receive.push_options
103 test_expect_success 'push options and submodules' '
104 test_when_finished "rm -rf parent" &&
105 test_when_finished "rm -rf parent_upstream" &&
107 git -C upstream config receive.advertisePushOptions true &&
108 cp -r upstream parent_upstream &&
109 test_commit -C upstream one &&
111 test_create_repo parent &&
112 git -C parent remote add up ../parent_upstream &&
113 test_commit -C parent one &&
114 git -C parent push --mirror up &&
116 git -C parent submodule add ../upstream workbench &&
117 git -C parent/workbench remote add up ../../upstream &&
118 git -C parent commit -m "add submodule" &&
120 test_commit -C parent/workbench two &&
121 git -C parent add workbench &&
122 git -C parent commit -m "update workbench" &&
125 --push-option=asdf --push-option="more structured text" \
126 --recurse-submodules=on-demand up master &&
128 git -C upstream rev-parse --verify master >expect &&
129 git -C parent/workbench rev-parse --verify master >actual &&
130 test_cmp expect actual &&
132 git -C parent_upstream rev-parse --verify master >expect &&
133 git -C parent rev-parse --verify master >actual &&
134 test_cmp expect actual &&
136 printf "asdf\nmore structured text\n" >expect &&
137 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
138 test_cmp expect upstream/.git/hooks/post-receive.push_options &&
139 test_cmp expect parent_upstream/.git/hooks/pre-receive.push_options &&
140 test_cmp expect parent_upstream/.git/hooks/post-receive.push_options
143 test_expect_success 'default push option' '
145 git -C upstream config receive.advertisePushOptions true &&
149 git push --mirror up &&
151 git -c push.pushOption=default push up master
153 test_refs master master &&
154 echo "default" >expect &&
155 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
156 test_cmp expect upstream/.git/hooks/post-receive.push_options
159 test_expect_success 'two default push options' '
161 git -C upstream config receive.advertisePushOptions true &&
165 git push --mirror up &&
167 git -c push.pushOption=default1 -c push.pushOption=default2 push up master
169 test_refs master master &&
170 printf "default1\ndefault2\n" >expect &&
171 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
172 test_cmp expect upstream/.git/hooks/post-receive.push_options
175 test_expect_success 'push option from command line overrides from-config push option' '
177 git -C upstream config receive.advertisePushOptions true &&
181 git push --mirror up &&
183 git -c push.pushOption=default push --push-option=manual up master
185 test_refs master master &&
186 echo "manual" >expect &&
187 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
188 test_cmp expect upstream/.git/hooks/post-receive.push_options
191 test_expect_success 'empty value of push.pushOption in config clears the list' '
193 git -C upstream config receive.advertisePushOptions true &&
197 git push --mirror up &&
199 git -c push.pushOption=default1 -c push.pushOption= -c push.pushOption=default2 push up master
201 test_refs master master &&
202 echo "default2" >expect &&
203 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
204 test_cmp expect upstream/.git/hooks/post-receive.push_options
207 test_expect_success 'invalid push option in config' '
209 git -C upstream config receive.advertisePushOptions true &&
213 git push --mirror up &&
215 test_must_fail git -c push.pushOption push up master
217 test_refs master HEAD@{1}
220 test_expect_success 'push options keep quoted characters intact (direct)' '
222 git -C upstream config receive.advertisePushOptions true &&
223 test_commit -C workbench one &&
224 git -C workbench push --push-option="\"embedded quotes\"" up master &&
225 echo "\"embedded quotes\"" >expect &&
226 test_cmp expect upstream/.git/hooks/pre-receive.push_options
229 . "$TEST_DIRECTORY"/lib-httpd.sh
232 # set up http repository for fetching/pushing, with push options config
235 test_when_finished "rm -rf test_http_clone" &&
236 test_when_finished 'rm -rf "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git' &&
238 git -C upstream config receive.advertisePushOptions "$1" &&
239 git -C upstream config http.receivepack true &&
240 cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
241 git clone "$HTTPD_URL"/smart/upstream test_http_clone
244 test_expect_success 'push option denied properly by http server' '
245 mk_http_pair false &&
246 test_commit -C test_http_clone one &&
247 test_must_fail git -C test_http_clone push --push-option=asdf origin master 2>actual &&
248 test_i18ngrep "the receiving end does not support push options" actual &&
249 git -C test_http_clone push origin master
252 test_expect_success 'push options work properly across http' '
255 test_commit -C test_http_clone one &&
256 git -C test_http_clone push origin master &&
257 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
258 git -C test_http_clone rev-parse --verify master >actual &&
259 test_cmp expect actual &&
261 test_commit -C test_http_clone two &&
262 git -C test_http_clone push --push-option=asdf --push-option="more structured text" origin master &&
263 printf "asdf\nmore structured text\n" >expect &&
264 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options &&
265 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/post-receive.push_options &&
267 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
268 git -C test_http_clone rev-parse --verify master >actual &&
269 test_cmp expect actual
272 test_expect_success 'push options keep quoted characters intact (http)' '
275 test_commit -C test_http_clone one &&
276 git -C test_http_clone push --push-option="\"embedded quotes\"" origin master &&
277 echo "\"embedded quotes\"" >expect &&
278 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options
281 # DO NOT add non-httpd-specific tests here, because the last part of this
282 # test script is only executed when httpd is available and enabled.