1#!/bin/sh
23
test_description='pushing to a repository using push options'
45
. ./test-lib.sh
6. "$TEST_DIRECTORY"/lib-httpd.sh
7start_httpd
89
mk_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/sh
19if test -n "$GIT_PUSH_OPTION_COUNT"; then
20i=0
21>hooks/pre-receive.push_options
22while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
23eval "value=\$GIT_PUSH_OPTION_$i"
24echo $value >>hooks/pre-receive.push_options
25i=$((i + 1))
26done
27fi
28EOF
29chmod u+x .git/hooks/pre-receive
3031
cat >.git/hooks/post-receive <<-'EOF' &&
32#!/bin/sh
33if test -n "$GIT_PUSH_OPTION_COUNT"; then
34i=0
35>hooks/post-receive.push_options
36while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
37eval "value=\$GIT_PUSH_OPTION_$i"
38echo $value >>hooks/post-receive.push_options
39i=$((i + 1))
40done
41fi
42EOF
43chmod u+x .git/hooks/post-receive
44) &&
45(
46cd workbench &&
47git remote add up ../upstream
48)
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 actual
58}
5960
test_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 master
69) &&
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_options
74'
7576
test_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 master
85) &&
86test_refs master HEAD@{1}
87'
8889
test_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 master
98) &&
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_options
103'
104105
test_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 master
114'
115116
stop_httpd
117118
test_done