config: introduce git_parse_maybe_bool_text
[git.git] / t / t5545-push-options.sh
blob9a57a7d8f2319e48a267e4f2a605e420f779fd96
1 #!/bin/sh
3 test_description='pushing to a repository using push options'
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-httpd.sh
7 start_httpd
9 mk_repo_pair () {
10 rm -rf workbench upstream &&
11 test_create_repo upstream &&
12 test_create_repo workbench &&
14 cd upstream &&
15 git config receive.denyCurrentBranch warn &&
16 mkdir -p .git/hooks &&
17 cat >.git/hooks/pre-receive <<-'EOF' &&
18 #!/bin/sh
19 if test -n "$GIT_PUSH_OPTION_COUNT"; then
20 i=0
21 >hooks/pre-receive.push_options
22 while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
23 eval "value=\$GIT_PUSH_OPTION_$i"
24 echo $value >>hooks/pre-receive.push_options
25 i=$((i + 1))
26 done
28 EOF
29 chmod u+x .git/hooks/pre-receive
31 cat >.git/hooks/post-receive <<-'EOF' &&
32 #!/bin/sh
33 if test -n "$GIT_PUSH_OPTION_COUNT"; then
34 i=0
35 >hooks/post-receive.push_options
36 while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
37 eval "value=\$GIT_PUSH_OPTION_$i"
38 echo $value >>hooks/post-receive.push_options
39 i=$((i + 1))
40 done
42 EOF
43 chmod u+x .git/hooks/post-receive
44 ) &&
46 cd workbench &&
47 git remote add up ../upstream
51 # Compare the ref ($1) in upstream with a ref value from workbench ($2)
52 # i.e. test_refs second HEAD@{2}
53 test_refs () {
54 test $# = 2 &&
55 git -C upstream rev-parse --verify "$1" >expect &&
56 git -C workbench rev-parse --verify "$2" >actual &&
57 test_cmp expect actual
60 test_expect_success 'one push option works for a single branch' '
61 mk_repo_pair &&
62 git -C upstream config receive.advertisePushOptions true &&
64 cd workbench &&
65 test_commit one &&
66 git push --mirror up &&
67 test_commit two &&
68 git push --push-option=asdf up master
69 ) &&
70 test_refs master master &&
71 echo "asdf" >expect &&
72 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
73 test_cmp expect upstream/.git/hooks/post-receive.push_options
76 test_expect_success 'push option denied by remote' '
77 mk_repo_pair &&
78 git -C upstream config receive.advertisePushOptions false &&
80 cd workbench &&
81 test_commit one &&
82 git push --mirror up &&
83 test_commit two &&
84 test_must_fail git push --push-option=asdf up master
85 ) &&
86 test_refs master HEAD@{1}
89 test_expect_success 'two push options work' '
90 mk_repo_pair &&
91 git -C upstream config receive.advertisePushOptions true &&
93 cd workbench &&
94 test_commit one &&
95 git push --mirror up &&
96 test_commit two &&
97 git push --push-option=asdf --push-option="more structured text" up master
98 ) &&
99 test_refs master master &&
100 printf "asdf\nmore structured text\n" >expect &&
101 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
102 test_cmp expect upstream/.git/hooks/post-receive.push_options
105 test_expect_success 'push option denied properly by http remote helper' '\
106 mk_repo_pair &&
107 git -C upstream config receive.advertisePushOptions false &&
108 git -C upstream config http.receivepack true &&
109 cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
110 git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
111 test_commit -C test_http_clone one &&
112 test_must_fail git -C test_http_clone push --push-option=asdf origin master &&
113 git -C test_http_clone push origin master
116 stop_httpd
118 test_done