3 test_description
='pushing to a repository using push options'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 rm -rf workbench upstream
&&
12 test_create_repo upstream
&&
13 test_create_repo workbench
&&
16 git config receive.denyCurrentBranch warn
&&
17 mkdir
-p .git
/hooks
&&
18 cat >.git
/hooks
/pre-receive
<<-'EOF' &&
20 if test -n "$GIT_PUSH_OPTION_COUNT"; then
22 >hooks/pre-receive.push_options
23 while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
24 eval "value=\$GIT_PUSH_OPTION_$i"
25 echo $value >>hooks/pre-receive.push_options
30 chmod u
+x .git
/hooks
/pre-receive
32 cat >.git
/hooks
/post-receive
<<-'EOF' &&
34 if test -n "$GIT_PUSH_OPTION_COUNT"; then
36 >hooks/post-receive.push_options
37 while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
38 eval "value=\$GIT_PUSH_OPTION_$i"
39 echo $value >>hooks/post-receive.push_options
44 chmod u
+x .git
/hooks
/post-receive
48 git remote add up ..
/upstream
52 # Compare the ref ($1) in upstream with a ref value from workbench ($2)
53 # i.e. test_refs second HEAD@{2}
56 git
-C upstream rev-parse
--verify "$1" >expect
&&
57 git
-C workbench rev-parse
--verify "$2" >actual
&&
58 test_cmp expect actual
61 test_expect_success
'one push option works for a single branch' '
63 git -C upstream config receive.advertisePushOptions true &&
67 git push --mirror up &&
69 git push --push-option=asdf up main
71 test_refs main main &&
72 echo "asdf" >expect &&
73 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
74 test_cmp expect upstream/.git/hooks/post-receive.push_options
77 test_expect_success
'push option denied by remote' '
79 git -C upstream config receive.advertisePushOptions false &&
83 git push --mirror up &&
85 test_must_fail git push --push-option=asdf up main
87 test_refs main HEAD@{1}
90 test_expect_success
'two push options work' '
92 git -C upstream config receive.advertisePushOptions true &&
96 git push --mirror up &&
98 git push --push-option=asdf --push-option="more structured text" up main
100 test_refs main main &&
101 printf "asdf\nmore structured text\n" >expect &&
102 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
103 test_cmp expect upstream/.git/hooks/post-receive.push_options
106 test_expect_success
'push options and submodules' '
107 test_when_finished "rm -rf parent" &&
108 test_when_finished "rm -rf parent_upstream" &&
110 git -C upstream config receive.advertisePushOptions true &&
111 cp -r upstream parent_upstream &&
112 test_commit -C upstream one &&
114 test_create_repo parent &&
115 git -C parent remote add up ../parent_upstream &&
116 test_commit -C parent one &&
117 git -C parent push --mirror up &&
119 test_config_global protocol.file.allow always &&
120 git -C parent submodule add ../upstream workbench &&
121 git -C parent/workbench remote add up ../../upstream &&
122 git -C parent commit -m "add submodule" &&
124 test_commit -C parent/workbench two &&
125 git -C parent add workbench &&
126 git -C parent commit -m "update workbench" &&
129 --push-option=asdf --push-option="more structured text" \
130 --recurse-submodules=on-demand up main &&
132 git -C upstream rev-parse --verify main >expect &&
133 git -C parent/workbench rev-parse --verify main >actual &&
134 test_cmp expect actual &&
136 git -C parent_upstream rev-parse --verify main >expect &&
137 git -C parent rev-parse --verify main >actual &&
138 test_cmp expect actual &&
140 printf "asdf\nmore structured text\n" >expect &&
141 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
142 test_cmp expect upstream/.git/hooks/post-receive.push_options &&
143 test_cmp expect parent_upstream/.git/hooks/pre-receive.push_options &&
144 test_cmp expect parent_upstream/.git/hooks/post-receive.push_options
147 test_expect_success
'default push option' '
149 git -C upstream config receive.advertisePushOptions true &&
153 git push --mirror up &&
155 git -c push.pushOption=default push up main
157 test_refs main main &&
158 echo "default" >expect &&
159 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
160 test_cmp expect upstream/.git/hooks/post-receive.push_options
163 test_expect_success
'two default push options' '
165 git -C upstream config receive.advertisePushOptions true &&
169 git push --mirror up &&
171 git -c push.pushOption=default1 -c push.pushOption=default2 push up main
173 test_refs main main &&
174 printf "default1\ndefault2\n" >expect &&
175 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
176 test_cmp expect upstream/.git/hooks/post-receive.push_options
179 test_expect_success
'push option from command line overrides from-config push option' '
181 git -C upstream config receive.advertisePushOptions true &&
185 git push --mirror up &&
187 git -c push.pushOption=default push --push-option=manual up main
189 test_refs main main &&
190 echo "manual" >expect &&
191 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
192 test_cmp expect upstream/.git/hooks/post-receive.push_options
195 test_expect_success
'empty value of push.pushOption in config clears the list' '
197 git -C upstream config receive.advertisePushOptions true &&
201 git push --mirror up &&
203 git -c push.pushOption=default1 -c push.pushOption= -c push.pushOption=default2 push up main
205 test_refs main main &&
206 echo "default2" >expect &&
207 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
208 test_cmp expect upstream/.git/hooks/post-receive.push_options
211 test_expect_success
'invalid push option in config' '
213 git -C upstream config receive.advertisePushOptions true &&
217 git push --mirror up &&
219 test_must_fail git -c push.pushOption push up main
221 test_refs main HEAD@{1}
224 test_expect_success
'push options keep quoted characters intact (direct)' '
226 git -C upstream config receive.advertisePushOptions true &&
227 test_commit -C workbench one &&
228 git -C workbench push --push-option="\"embedded quotes\"" up main &&
229 echo "\"embedded quotes\"" >expect &&
230 test_cmp expect upstream/.git/hooks/pre-receive.push_options
233 .
"$TEST_DIRECTORY"/lib-httpd.sh
236 # set up http repository for fetching/pushing, with push options config
239 test_when_finished
"rm -rf test_http_clone" &&
240 test_when_finished
'rm -rf "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git' &&
242 git
-C upstream config receive.advertisePushOptions
"$1" &&
243 git
-C upstream config http.receivepack true
&&
244 cp -R upstream
/.git
"$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git
&&
245 git clone
"$HTTPD_URL"/smart
/upstream test_http_clone
248 test_expect_success
'push option denied properly by http server' '
249 mk_http_pair false &&
250 test_commit -C test_http_clone one &&
251 test_must_fail git -C test_http_clone push --push-option=asdf origin main 2>actual &&
252 test_i18ngrep "the receiving end does not support push options" actual &&
253 git -C test_http_clone push origin main
256 test_expect_success
'push options work properly across http' '
259 test_commit -C test_http_clone one &&
260 git -C test_http_clone push origin main &&
261 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify main >expect &&
262 git -C test_http_clone rev-parse --verify main >actual &&
263 test_cmp expect actual &&
265 test_commit -C test_http_clone two &&
266 git -C test_http_clone push --push-option=asdf --push-option="more structured text" origin main &&
267 printf "asdf\nmore structured text\n" >expect &&
268 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options &&
269 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/post-receive.push_options &&
271 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify main >expect &&
272 git -C test_http_clone rev-parse --verify main >actual &&
273 test_cmp expect actual
276 test_expect_success
'push options keep quoted characters intact (http)' '
279 test_commit -C test_http_clone one &&
280 git -C test_http_clone push --push-option="\"embedded quotes\"" origin main &&
281 echo "\"embedded quotes\"" >expect &&
282 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options
285 # DO NOT add non-httpd-specific tests here, because the last part of this
286 # test script is only executed when httpd is available and enabled.