3 test_description='pushing to a repository using push options'
6 . "$TEST_DIRECTORY"/lib-httpd.sh
10 rm -rf workbench upstream &&
11 test_create_repo upstream &&
12 test_create_repo workbench &&
15 git config receive.denyCurrentBranch warn &&
16 mkdir -p .git/hooks &&
17 cat >.git/hooks/pre-receive <<-'EOF' &&
19 if test -n "$GIT_PUSH_OPTION_COUNT"; then
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
29 chmod u+x .git/hooks/pre-receive
31 cat >.git/hooks/post-receive <<-'EOF' &&
33 if test -n "$GIT_PUSH_OPTION_COUNT"; then
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
43 chmod u+x .git/hooks/post-receive
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}
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' '
62 git -C upstream config receive.advertisePushOptions true &&
66 git push --mirror up &&
68 git push --push-option=asdf up master
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' '
78 git -C upstream config receive.advertisePushOptions false &&
82 git push --mirror up &&
84 test_must_fail git push --push-option=asdf up master
86 test_refs master HEAD@{1}
89 test_expect_success 'two push options work' '
91 git -C upstream config receive.advertisePushOptions true &&
95 git push --mirror up &&
97 git push --push-option=asdf --push-option="more structured text" up master
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' '\
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