1#!/bin/sh23test_description='pushing to a repository using push options'45. ./test-lib.sh6. "$TEST_DIRECTORY"/lib-httpd.sh7start_httpd89mk_repo_pair () {10rm -rf workbench upstream &&11test_create_repo upstream &&12test_create_repo workbench &&13(14cd upstream &&15git config receive.denyCurrentBranch warn &&16mkdir -p .git/hooks &&17cat >.git/hooks/pre-receive <<-'EOF' &&18#!/bin/sh19if test -n "$GIT_PUSH_OPTION_COUNT"; then20i=021>hooks/pre-receive.push_options22while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do23eval "value=\$GIT_PUSH_OPTION_$i"24echo $value >>hooks/pre-receive.push_options25i=$((i + 1))26done27fi28EOF29chmod u+x .git/hooks/pre-receive3031cat >.git/hooks/post-receive <<-'EOF' &&32#!/bin/sh33if test -n "$GIT_PUSH_OPTION_COUNT"; then34i=035>hooks/post-receive.push_options36while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do37eval "value=\$GIT_PUSH_OPTION_$i"38echo $value >>hooks/post-receive.push_options39i=$((i + 1))40done41fi42EOF43chmod u+x .git/hooks/post-receive44) &&45(46cd workbench &&47git remote add up ../upstream48)49}5051# Compare the ref ($1) in upstream with a ref value from workbench ($2)52# i.e. test_refs second HEAD@{2}53test_refs () {54test $# = 2 &&55git -C upstream rev-parse --verify "$1" >expect &&56git -C workbench rev-parse --verify "$2" >actual &&57test_cmp expect actual58}5960test_expect_success 'one push option works for a single branch' '61mk_repo_pair &&62git -C upstream config receive.advertisePushOptions true &&63(64cd workbench &&65test_commit one &&66git push --mirror up &&67test_commit two &&68git push --push-option=asdf up master69) &&70test_refs master master &&71echo "asdf" >expect &&72test_cmp expect upstream/.git/hooks/pre-receive.push_options &&73test_cmp expect upstream/.git/hooks/post-receive.push_options74'7576test_expect_success 'push option denied by remote' '77mk_repo_pair &&78git -C upstream config receive.advertisePushOptions false &&79(80cd workbench &&81test_commit one &&82git push --mirror up &&83test_commit two &&84test_must_fail git push --push-option=asdf up master85) &&86test_refs master HEAD@{1}87'8889test_expect_success 'two push options work' '90mk_repo_pair &&91git -C upstream config receive.advertisePushOptions true &&92(93cd workbench &&94test_commit one &&95git push --mirror up &&96test_commit two &&97git push --push-option=asdf --push-option="more structured text" up master98) &&99test_refs master master &&100printf "asdf\nmore structured text\n" >expect &&101test_cmp expect upstream/.git/hooks/pre-receive.push_options &&102test_cmp expect upstream/.git/hooks/post-receive.push_options103'104105test_expect_success 'push option denied properly by http remote helper' '\106mk_repo_pair &&107git -C upstream config receive.advertisePushOptions false &&108git -C upstream config http.receivepack true &&109cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&110git clone "$HTTPD_URL"/smart/upstream test_http_clone &&111test_commit -C test_http_clone one &&112test_must_fail git -C test_http_clone push --push-option=asdf origin master &&113git -C test_http_clone push origin master114'115116stop_httpd117118test_done