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 git -C parent submodule add ../upstream workbench &&
120 git -C parent/workbench remote add up ../../upstream &&
121 git -C parent commit -m "add submodule" &&
123 test_commit -C parent/workbench two &&
124 git -C parent add workbench &&
125 git -C parent commit -m "update workbench" &&
128 --push-option=asdf --push-option="more structured text" \
129 --recurse-submodules=on-demand up main &&
131 git -C upstream rev-parse --verify main >expect &&
132 git -C parent/workbench rev-parse --verify main >actual &&
133 test_cmp expect actual &&
135 git -C parent_upstream rev-parse --verify main >expect &&
136 git -C parent rev-parse --verify main >actual &&
137 test_cmp expect actual &&
139 printf "asdf\nmore structured text\n" >expect &&
140 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
141 test_cmp expect upstream/.git/hooks/post-receive.push_options &&
142 test_cmp expect parent_upstream/.git/hooks/pre-receive.push_options &&
143 test_cmp expect parent_upstream/.git/hooks/post-receive.push_options
146 test_expect_success 'default push option' '
148 git -C upstream config receive.advertisePushOptions true &&
152 git push --mirror up &&
154 git -c push.pushOption=default push up main
156 test_refs main main &&
157 echo "default" >expect &&
158 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
159 test_cmp expect upstream/.git/hooks/post-receive.push_options
162 test_expect_success 'two default push options' '
164 git -C upstream config receive.advertisePushOptions true &&
168 git push --mirror up &&
170 git -c push.pushOption=default1 -c push.pushOption=default2 push up main
172 test_refs main main &&
173 printf "default1\ndefault2\n" >expect &&
174 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
175 test_cmp expect upstream/.git/hooks/post-receive.push_options
178 test_expect_success 'push option from command line overrides from-config push option' '
180 git -C upstream config receive.advertisePushOptions true &&
184 git push --mirror up &&
186 git -c push.pushOption=default push --push-option=manual up main
188 test_refs main main &&
189 echo "manual" >expect &&
190 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
191 test_cmp expect upstream/.git/hooks/post-receive.push_options
194 test_expect_success 'empty value of push.pushOption in config clears the list' '
196 git -C upstream config receive.advertisePushOptions true &&
200 git push --mirror up &&
202 git -c push.pushOption=default1 -c push.pushOption= -c push.pushOption=default2 push up main
204 test_refs main main &&
205 echo "default2" >expect &&
206 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
207 test_cmp expect upstream/.git/hooks/post-receive.push_options
210 test_expect_success 'invalid push option in config' '
212 git -C upstream config receive.advertisePushOptions true &&
216 git push --mirror up &&
218 test_must_fail git -c push.pushOption push up main
220 test_refs main HEAD@{1}
223 test_expect_success 'push options keep quoted characters intact (direct)' '
225 git -C upstream config receive.advertisePushOptions true &&
226 test_commit -C workbench one &&
227 git -C workbench push --push-option="\"embedded quotes\"" up main &&
228 echo "\"embedded quotes\"" >expect &&
229 test_cmp expect upstream/.git/hooks/pre-receive.push_options
232 . "$TEST_DIRECTORY"/lib-httpd.sh
235 # set up http repository for fetching/pushing, with push options config
238 test_when_finished "rm -rf test_http_clone" &&
239 test_when_finished 'rm -rf "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git' &&
241 git -C upstream config receive.advertisePushOptions "$1" &&
242 git -C upstream config http.receivepack true &&
243 cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
244 git clone "$HTTPD_URL"/smart/upstream test_http_clone
247 test_expect_success 'push option denied properly by http server' '
248 mk_http_pair false &&
249 test_commit -C test_http_clone one &&
250 test_must_fail git -C test_http_clone push --push-option=asdf origin main 2>actual &&
251 test_i18ngrep "the receiving end does not support push options" actual &&
252 git -C test_http_clone push origin main
255 test_expect_success 'push options work properly across http' '
258 test_commit -C test_http_clone one &&
259 git -C test_http_clone push origin main &&
260 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify main >expect &&
261 git -C test_http_clone rev-parse --verify main >actual &&
262 test_cmp expect actual &&
264 test_commit -C test_http_clone two &&
265 git -C test_http_clone push --push-option=asdf --push-option="more structured text" origin main &&
266 printf "asdf\nmore structured text\n" >expect &&
267 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options &&
268 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/post-receive.push_options &&
270 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify main >expect &&
271 git -C test_http_clone rev-parse --verify main >actual &&
272 test_cmp expect actual
275 test_expect_success 'push options keep quoted characters intact (http)' '
278 test_commit -C test_http_clone one &&
279 git -C test_http_clone push --push-option="\"embedded quotes\"" origin main &&
280 echo "\"embedded quotes\"" >expect &&
281 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options
284 # DO NOT add non-httpd-specific tests here, because the last part of this
285 # test script is only executed when httpd is available and enabled.