Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t5545-push-options.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t5545-push-options.sh` 288 lines ยท 9055 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='pushing to a repository using push options' 4 5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8 . ./test-lib.sh 9 10 mk_repo_pair () { 11 rm -rf workbench upstream && 12 test_create_repo upstream && 13 test_create_repo workbench && 14 ( 15 cd upstream && 16 git config receive.denyCurrentBranch warn && 17 mkdir -p .git/hooks && 18 cat >.git/hooks/pre-receive <<-'EOF' && 19 #!/bin/sh 20 if test -n "$GIT_PUSH_OPTION_COUNT"; then 21 i=0 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 26 i=$((i + 1)) 27 done 28 fi 29 EOF 30 chmod u+x .git/hooks/pre-receive 31 32 cat >.git/hooks/post-receive <<-'EOF' && 33 #!/bin/sh 34 if test -n "$GIT_PUSH_OPTION_COUNT"; then 35 i=0 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 40 i=$((i + 1)) 41 done 42 fi 43 EOF 44 chmod u+x .git/hooks/post-receive 45 ) && 46 ( 47 cd workbench && 48 git remote add up ../upstream 49 ) 50 } 51 52 # Compare the ref ($1) in upstream with a ref value from workbench ($2) 53 # i.e. test_refs second HEAD@{2} 54 test_refs () { 55 test $# = 2 && 56 git -C upstream rev-parse --verify "$1" >expect && 57 git -C workbench rev-parse --verify "$2" >actual && 58 test_cmp expect actual 59 } 60 61 test_expect_success 'one push option works for a single branch' ' 62 mk_repo_pair && 63 git -C upstream config receive.advertisePushOptions true && 64 ( 65 cd workbench && 66 test_commit one && 67 git push --mirror up && 68 test_commit two && 69 git push --push-option=asdf up main 70 ) && 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 75 ' 76 77 test_expect_success 'push option denied by remote' ' 78 mk_repo_pair && 79 git -C upstream config receive.advertisePushOptions false && 80 ( 81 cd workbench && 82 test_commit one && 83 git push --mirror up && 84 test_commit two && 85 test_must_fail git push --push-option=asdf up main 86 ) && 87 test_refs main HEAD@{1} 88 ' 89 90 test_expect_success 'two push options work' ' 91 mk_repo_pair && 92 git -C upstream config receive.advertisePushOptions true && 93 ( 94 cd workbench && 95 test_commit one && 96 git push --mirror up && 97 test_commit two && 98 git push --push-option=asdf --push-option="more structured text" up main 99 ) && 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 104 ' 105 106 test_expect_success 'push options and submodules' ' 107 test_when_finished "rm -rf parent" && 108 test_when_finished "rm -rf parent_upstream" && 109 mk_repo_pair && 110 git -C upstream config receive.advertisePushOptions true && 111 cp -r upstream parent_upstream && 112 test_commit -C upstream one && 113 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 && 118 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" && 123 124 test_commit -C parent/workbench two && 125 git -C parent add workbench && 126 git -C parent commit -m "update workbench" && 127 128 git -C parent push \ 129 --push-option=asdf --push-option="more structured text" \ 130 --recurse-submodules=on-demand up main && 131 132 git -C upstream rev-parse --verify main >expect && 133 git -C parent/workbench rev-parse --verify main >actual && 134 test_cmp expect actual && 135 136 git -C parent_upstream rev-parse --verify main >expect && 137 git -C parent rev-parse --verify main >actual && 138 test_cmp expect actual && 139 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 145 ' 146 147 test_expect_success 'default push option' ' 148 mk_repo_pair && 149 git -C upstream config receive.advertisePushOptions true && 150 ( 151 cd workbench && 152 test_commit one && 153 git push --mirror up && 154 test_commit two && 155 git -c push.pushOption=default push up main 156 ) && 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 161 ' 162 163 test_expect_success 'two default push options' ' 164 mk_repo_pair && 165 git -C upstream config receive.advertisePushOptions true && 166 ( 167 cd workbench && 168 test_commit one && 169 git push --mirror up && 170 test_commit two && 171 git -c push.pushOption=default1 -c push.pushOption=default2 push up main 172 ) && 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 177 ' 178 179 test_expect_success 'push option from command line overrides from-config push option' ' 180 mk_repo_pair && 181 git -C upstream config receive.advertisePushOptions true && 182 ( 183 cd workbench && 184 test_commit one && 185 git push --mirror up && 186 test_commit two && 187 git -c push.pushOption=default push --push-option=manual up main 188 ) && 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 193 ' 194 195 test_expect_success 'empty value of push.pushOption in config clears the list' ' 196 mk_repo_pair && 197 git -C upstream config receive.advertisePushOptions true && 198 ( 199 cd workbench && 200 test_commit one && 201 git push --mirror up && 202 test_commit two && 203 git -c push.pushOption=default1 -c push.pushOption= -c push.pushOption=default2 push up main 204 ) && 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 209 ' 210 211 test_expect_success 'invalid push option in config' ' 212 mk_repo_pair && 213 git -C upstream config receive.advertisePushOptions true && 214 ( 215 cd workbench && 216 test_commit one && 217 git push --mirror up && 218 test_commit two && 219 test_must_fail git -c push.pushOption push up main 220 ) && 221 test_refs main HEAD@{1} 222 ' 223 224 test_expect_success 'push options keep quoted characters intact (direct)' ' 225 mk_repo_pair && 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 231 ' 232 233 . "$TEST_DIRECTORY"/lib-httpd.sh 234 start_httpd 235 236 # set up http repository for fetching/pushing, with push options config 237 # bool set to $1 238 mk_http_pair () { 239 test_when_finished "rm -rf test_http_clone" && 240 test_when_finished 'rm -rf "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git' && 241 mk_repo_pair && 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 246 } 247 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_grep "the receiving end does not support push options" actual && 253 git -C test_http_clone push origin main 254 ' 255 256 test_expect_success 'push options work properly across http' ' 257 mk_http_pair true && 258 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 && 264 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 && 270 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 274 ' 275 276 test_expect_success 'push options keep quoted characters intact (http)' ' 277 mk_http_pair true && 278 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 283 ' 284 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. 287 288 test_done