Stefan Beller | 3ac8703 | 2016-07-14 14:49:48 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='pushing to a repository using push options' |
| 4 | |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Jonathan Tan | 13a2f62 | 2021-10-08 14:08:19 -0700 | [diff] [blame] | 8 | GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 |
| 9 | export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB |
| 10 | |
Stefan Beller | 3ac8703 | 2016-07-14 14:49:48 -0700 | [diff] [blame] | 11 | . ./test-lib.sh |
| 12 | |
| 13 | mk_repo_pair () { |
| 14 | rm -rf workbench upstream && |
| 15 | test_create_repo upstream && |
| 16 | test_create_repo workbench && |
| 17 | ( |
| 18 | cd upstream && |
| 19 | git config receive.denyCurrentBranch warn && |
| 20 | mkdir -p .git/hooks && |
| 21 | cat >.git/hooks/pre-receive <<-'EOF' && |
| 22 | #!/bin/sh |
| 23 | if test -n "$GIT_PUSH_OPTION_COUNT"; then |
| 24 | i=0 |
| 25 | >hooks/pre-receive.push_options |
| 26 | while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do |
| 27 | eval "value=\$GIT_PUSH_OPTION_$i" |
| 28 | echo $value >>hooks/pre-receive.push_options |
| 29 | i=$((i + 1)) |
| 30 | done |
| 31 | fi |
| 32 | EOF |
| 33 | chmod u+x .git/hooks/pre-receive |
| 34 | |
| 35 | cat >.git/hooks/post-receive <<-'EOF' && |
| 36 | #!/bin/sh |
| 37 | if test -n "$GIT_PUSH_OPTION_COUNT"; then |
| 38 | i=0 |
| 39 | >hooks/post-receive.push_options |
| 40 | while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do |
| 41 | eval "value=\$GIT_PUSH_OPTION_$i" |
| 42 | echo $value >>hooks/post-receive.push_options |
| 43 | i=$((i + 1)) |
| 44 | done |
| 45 | fi |
| 46 | EOF |
| 47 | chmod u+x .git/hooks/post-receive |
| 48 | ) && |
| 49 | ( |
| 50 | cd workbench && |
| 51 | git remote add up ../upstream |
| 52 | ) |
| 53 | } |
| 54 | |
| 55 | # Compare the ref ($1) in upstream with a ref value from workbench ($2) |
| 56 | # i.e. test_refs second HEAD@{2} |
| 57 | test_refs () { |
| 58 | test $# = 2 && |
| 59 | git -C upstream rev-parse --verify "$1" >expect && |
| 60 | git -C workbench rev-parse --verify "$2" >actual && |
| 61 | test_cmp expect actual |
| 62 | } |
| 63 | |
| 64 | test_expect_success 'one push option works for a single branch' ' |
| 65 | mk_repo_pair && |
| 66 | git -C upstream config receive.advertisePushOptions true && |
| 67 | ( |
| 68 | cd workbench && |
| 69 | test_commit one && |
| 70 | git push --mirror up && |
| 71 | test_commit two && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 72 | git push --push-option=asdf up main |
Stefan Beller | 3ac8703 | 2016-07-14 14:49:48 -0700 | [diff] [blame] | 73 | ) && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 74 | test_refs main main && |
Stefan Beller | 3ac8703 | 2016-07-14 14:49:48 -0700 | [diff] [blame] | 75 | echo "asdf" >expect && |
| 76 | test_cmp expect upstream/.git/hooks/pre-receive.push_options && |
| 77 | test_cmp expect upstream/.git/hooks/post-receive.push_options |
| 78 | ' |
| 79 | |
| 80 | test_expect_success 'push option denied by remote' ' |
| 81 | mk_repo_pair && |
| 82 | git -C upstream config receive.advertisePushOptions false && |
| 83 | ( |
| 84 | cd workbench && |
| 85 | test_commit one && |
| 86 | git push --mirror up && |
| 87 | test_commit two && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 88 | test_must_fail git push --push-option=asdf up main |
Stefan Beller | 3ac8703 | 2016-07-14 14:49:48 -0700 | [diff] [blame] | 89 | ) && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 90 | test_refs main HEAD@{1} |
Stefan Beller | 3ac8703 | 2016-07-14 14:49:48 -0700 | [diff] [blame] | 91 | ' |
| 92 | |
| 93 | test_expect_success 'two push options work' ' |
| 94 | mk_repo_pair && |
| 95 | git -C upstream config receive.advertisePushOptions true && |
| 96 | ( |
| 97 | cd workbench && |
| 98 | test_commit one && |
| 99 | git push --mirror up && |
| 100 | test_commit two && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 101 | git push --push-option=asdf --push-option="more structured text" up main |
Stefan Beller | 3ac8703 | 2016-07-14 14:49:48 -0700 | [diff] [blame] | 102 | ) && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 103 | test_refs main main && |
Stefan Beller | 3ac8703 | 2016-07-14 14:49:48 -0700 | [diff] [blame] | 104 | printf "asdf\nmore structured text\n" >expect && |
| 105 | test_cmp expect upstream/.git/hooks/pre-receive.push_options && |
| 106 | test_cmp expect upstream/.git/hooks/post-receive.push_options |
| 107 | ' |
| 108 | |
Brandon Williams | 2a90556 | 2017-04-05 10:47:16 -0700 | [diff] [blame] | 109 | test_expect_success 'push options and submodules' ' |
| 110 | test_when_finished "rm -rf parent" && |
| 111 | test_when_finished "rm -rf parent_upstream" && |
| 112 | mk_repo_pair && |
| 113 | git -C upstream config receive.advertisePushOptions true && |
| 114 | cp -r upstream parent_upstream && |
| 115 | test_commit -C upstream one && |
| 116 | |
| 117 | test_create_repo parent && |
| 118 | git -C parent remote add up ../parent_upstream && |
| 119 | test_commit -C parent one && |
| 120 | git -C parent push --mirror up && |
| 121 | |
Taylor Blau | 225d2d5 | 2022-07-29 15:21:06 -0400 | [diff] [blame] | 122 | test_config_global protocol.file.allow always && |
Brandon Williams | 2a90556 | 2017-04-05 10:47:16 -0700 | [diff] [blame] | 123 | git -C parent submodule add ../upstream workbench && |
| 124 | git -C parent/workbench remote add up ../../upstream && |
Elijah Newren | aa74be3 | 2019-11-05 17:07:27 +0000 | [diff] [blame] | 125 | git -C parent commit -m "add submodule" && |
Brandon Williams | 2a90556 | 2017-04-05 10:47:16 -0700 | [diff] [blame] | 126 | |
| 127 | test_commit -C parent/workbench two && |
| 128 | git -C parent add workbench && |
| 129 | git -C parent commit -m "update workbench" && |
| 130 | |
| 131 | git -C parent push \ |
| 132 | --push-option=asdf --push-option="more structured text" \ |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 133 | --recurse-submodules=on-demand up main && |
Brandon Williams | 2a90556 | 2017-04-05 10:47:16 -0700 | [diff] [blame] | 134 | |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 135 | git -C upstream rev-parse --verify main >expect && |
| 136 | git -C parent/workbench rev-parse --verify main >actual && |
Brandon Williams | 2a90556 | 2017-04-05 10:47:16 -0700 | [diff] [blame] | 137 | test_cmp expect actual && |
| 138 | |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 139 | git -C parent_upstream rev-parse --verify main >expect && |
| 140 | git -C parent rev-parse --verify main >actual && |
Brandon Williams | 2a90556 | 2017-04-05 10:47:16 -0700 | [diff] [blame] | 141 | test_cmp expect actual && |
| 142 | |
| 143 | printf "asdf\nmore structured text\n" >expect && |
| 144 | test_cmp expect upstream/.git/hooks/pre-receive.push_options && |
| 145 | test_cmp expect upstream/.git/hooks/post-receive.push_options && |
| 146 | test_cmp expect parent_upstream/.git/hooks/pre-receive.push_options && |
| 147 | test_cmp expect parent_upstream/.git/hooks/post-receive.push_options |
| 148 | ' |
| 149 | |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 150 | test_expect_success 'default push option' ' |
| 151 | mk_repo_pair && |
| 152 | git -C upstream config receive.advertisePushOptions true && |
| 153 | ( |
| 154 | cd workbench && |
| 155 | test_commit one && |
| 156 | git push --mirror up && |
| 157 | test_commit two && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 158 | git -c push.pushOption=default push up main |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 159 | ) && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 160 | test_refs main main && |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 161 | echo "default" >expect && |
| 162 | test_cmp expect upstream/.git/hooks/pre-receive.push_options && |
| 163 | test_cmp expect upstream/.git/hooks/post-receive.push_options |
| 164 | ' |
| 165 | |
| 166 | test_expect_success 'two default push options' ' |
| 167 | mk_repo_pair && |
| 168 | git -C upstream config receive.advertisePushOptions true && |
| 169 | ( |
| 170 | cd workbench && |
| 171 | test_commit one && |
| 172 | git push --mirror up && |
| 173 | test_commit two && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 174 | git -c push.pushOption=default1 -c push.pushOption=default2 push up main |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 175 | ) && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 176 | test_refs main main && |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 177 | printf "default1\ndefault2\n" >expect && |
| 178 | test_cmp expect upstream/.git/hooks/pre-receive.push_options && |
| 179 | test_cmp expect upstream/.git/hooks/post-receive.push_options |
| 180 | ' |
| 181 | |
| 182 | test_expect_success 'push option from command line overrides from-config push option' ' |
| 183 | mk_repo_pair && |
| 184 | git -C upstream config receive.advertisePushOptions true && |
| 185 | ( |
| 186 | cd workbench && |
| 187 | test_commit one && |
| 188 | git push --mirror up && |
| 189 | test_commit two && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 190 | git -c push.pushOption=default push --push-option=manual up main |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 191 | ) && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 192 | test_refs main main && |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 193 | echo "manual" >expect && |
| 194 | test_cmp expect upstream/.git/hooks/pre-receive.push_options && |
| 195 | test_cmp expect upstream/.git/hooks/post-receive.push_options |
| 196 | ' |
| 197 | |
| 198 | test_expect_success 'empty value of push.pushOption in config clears the list' ' |
| 199 | mk_repo_pair && |
| 200 | git -C upstream config receive.advertisePushOptions true && |
| 201 | ( |
| 202 | cd workbench && |
| 203 | test_commit one && |
| 204 | git push --mirror up && |
| 205 | test_commit two && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 206 | git -c push.pushOption=default1 -c push.pushOption= -c push.pushOption=default2 push up main |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 207 | ) && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 208 | test_refs main main && |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 209 | echo "default2" >expect && |
| 210 | test_cmp expect upstream/.git/hooks/pre-receive.push_options && |
| 211 | test_cmp expect upstream/.git/hooks/post-receive.push_options |
| 212 | ' |
| 213 | |
| 214 | test_expect_success 'invalid push option in config' ' |
| 215 | mk_repo_pair && |
| 216 | git -C upstream config receive.advertisePushOptions true && |
| 217 | ( |
| 218 | cd workbench && |
| 219 | test_commit one && |
| 220 | git push --mirror up && |
| 221 | test_commit two && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 222 | test_must_fail git -c push.pushOption push up main |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 223 | ) && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 224 | test_refs main HEAD@{1} |
Marius Paliga | d805275 | 2017-10-23 13:44:49 +0200 | [diff] [blame] | 225 | ' |
| 226 | |
Jeff King | 90dce21 | 2018-02-19 14:50:14 -0500 | [diff] [blame] | 227 | test_expect_success 'push options keep quoted characters intact (direct)' ' |
| 228 | mk_repo_pair && |
| 229 | git -C upstream config receive.advertisePushOptions true && |
| 230 | test_commit -C workbench one && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 231 | git -C workbench push --push-option="\"embedded quotes\"" up main && |
Jeff King | 90dce21 | 2018-02-19 14:50:14 -0500 | [diff] [blame] | 232 | echo "\"embedded quotes\"" >expect && |
| 233 | test_cmp expect upstream/.git/hooks/pre-receive.push_options |
| 234 | ' |
| 235 | |
Stefan Beller | 2e397e4 | 2017-05-16 20:11:03 -0700 | [diff] [blame] | 236 | . "$TEST_DIRECTORY"/lib-httpd.sh |
| 237 | start_httpd |
| 238 | |
Jeff King | 6cdffd0 | 2018-02-19 14:48:44 -0500 | [diff] [blame] | 239 | # set up http repository for fetching/pushing, with push options config |
| 240 | # bool set to $1 |
| 241 | mk_http_pair () { |
Stefan Beller | 2e397e4 | 2017-05-16 20:11:03 -0700 | [diff] [blame] | 242 | test_when_finished "rm -rf test_http_clone" && |
Jeff King | 6cdffd0 | 2018-02-19 14:48:44 -0500 | [diff] [blame] | 243 | test_when_finished 'rm -rf "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git' && |
Stefan Beller | 2e397e4 | 2017-05-16 20:11:03 -0700 | [diff] [blame] | 244 | mk_repo_pair && |
Jeff King | 6cdffd0 | 2018-02-19 14:48:44 -0500 | [diff] [blame] | 245 | git -C upstream config receive.advertisePushOptions "$1" && |
Stefan Beller | 2e397e4 | 2017-05-16 20:11:03 -0700 | [diff] [blame] | 246 | git -C upstream config http.receivepack true && |
| 247 | cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git && |
Jeff King | 6cdffd0 | 2018-02-19 14:48:44 -0500 | [diff] [blame] | 248 | git clone "$HTTPD_URL"/smart/upstream test_http_clone |
| 249 | } |
| 250 | |
| 251 | test_expect_success 'push option denied properly by http server' ' |
| 252 | mk_http_pair false && |
Stefan Beller | 2e397e4 | 2017-05-16 20:11:03 -0700 | [diff] [blame] | 253 | test_commit -C test_http_clone one && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 254 | test_must_fail git -C test_http_clone push --push-option=asdf origin main 2>actual && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 255 | test_grep "the receiving end does not support push options" actual && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 256 | git -C test_http_clone push origin main |
Stefan Beller | 2e397e4 | 2017-05-16 20:11:03 -0700 | [diff] [blame] | 257 | ' |
| 258 | |
| 259 | test_expect_success 'push options work properly across http' ' |
Jeff King | 6cdffd0 | 2018-02-19 14:48:44 -0500 | [diff] [blame] | 260 | mk_http_pair true && |
Stefan Beller | 2e397e4 | 2017-05-16 20:11:03 -0700 | [diff] [blame] | 261 | |
| 262 | test_commit -C test_http_clone one && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 263 | git -C test_http_clone push origin main && |
| 264 | git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify main >expect && |
| 265 | git -C test_http_clone rev-parse --verify main >actual && |
Stefan Beller | 2e397e4 | 2017-05-16 20:11:03 -0700 | [diff] [blame] | 266 | test_cmp expect actual && |
| 267 | |
| 268 | test_commit -C test_http_clone two && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 269 | git -C test_http_clone push --push-option=asdf --push-option="more structured text" origin main && |
Stefan Beller | 2e397e4 | 2017-05-16 20:11:03 -0700 | [diff] [blame] | 270 | printf "asdf\nmore structured text\n" >expect && |
| 271 | test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options && |
| 272 | test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/post-receive.push_options && |
| 273 | |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 274 | git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify main >expect && |
| 275 | git -C test_http_clone rev-parse --verify main >actual && |
Stefan Beller | 2e397e4 | 2017-05-16 20:11:03 -0700 | [diff] [blame] | 276 | test_cmp expect actual |
| 277 | ' |
| 278 | |
Jeff King | 90dce21 | 2018-02-19 14:50:14 -0500 | [diff] [blame] | 279 | test_expect_success 'push options keep quoted characters intact (http)' ' |
| 280 | mk_http_pair true && |
| 281 | |
| 282 | test_commit -C test_http_clone one && |
Johannes Schindelin | 028cb64 | 2020-11-18 23:44:34 +0000 | [diff] [blame] | 283 | git -C test_http_clone push --push-option="\"embedded quotes\"" origin main && |
Jeff King | 90dce21 | 2018-02-19 14:50:14 -0500 | [diff] [blame] | 284 | echo "\"embedded quotes\"" >expect && |
| 285 | test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options |
| 286 | ' |
| 287 | |
SZEDER Gábor | decfe05 | 2019-08-01 17:53:09 +0200 | [diff] [blame] | 288 | # DO NOT add non-httpd-specific tests here, because the last part of this |
| 289 | # test script is only executed when httpd is available and enabled. |
| 290 | |
Stefan Beller | 3ac8703 | 2016-07-14 14:49:48 -0700 | [diff] [blame] | 291 | test_done |