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 server' '
106 test_when_finished "rm -rf test_http_clone" &&
107 test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
109 git -C upstream config receive.advertisePushOptions false &&
110 git -C upstream config http.receivepack true &&
111 cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
112 git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
113 test_commit -C test_http_clone one &&
114 test_must_fail git -C test_http_clone push --push-option=asdf origin master 2>actual &&
115 test_i18ngrep "the receiving end does not support push options" actual &&
116 git -C test_http_clone push origin master
119 test_expect_success 'push options work properly across http' '
120 test_when_finished "rm -rf test_http_clone" &&
121 test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
123 git -C upstream config receive.advertisePushOptions true &&
124 git -C upstream config http.receivepack true &&
125 cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
126 git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
128 test_commit -C test_http_clone one &&
129 git -C test_http_clone push origin master &&
130 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
131 git -C test_http_clone rev-parse --verify master >actual &&
132 test_cmp expect actual &&
134 test_commit -C test_http_clone two &&
135 git -C test_http_clone push --push-option=asdf --push-option="more structured text" origin master &&
136 printf "asdf\nmore structured text\n" >expect &&
137 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options &&
138 test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/post-receive.push_options &&
140 git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
141 git -C test_http_clone rev-parse --verify master >actual &&
142 test_cmp expect actual