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
145 test_expect_success
'push options and submodules' '
146 test_when_finished "rm -rf parent" &&
147 test_when_finished "rm -rf parent_upstream" &&
149 git -C upstream config receive.advertisePushOptions true &&
150 cp -r upstream parent_upstream &&
151 test_commit -C upstream one &&
153 test_create_repo parent &&
154 git -C parent remote add up ../parent_upstream &&
155 test_commit -C parent one &&
156 git -C parent push --mirror up &&
158 git -C parent submodule add ../upstream workbench &&
159 git -C parent/workbench remote add up ../../upstream &&
160 git -C parent commit -m "add submoule" &&
162 test_commit -C parent/workbench two &&
163 git -C parent add workbench &&
164 git -C parent commit -m "update workbench" &&
167 --push-option=asdf --push-option="more structured text" \
168 --recurse-submodules=on-demand up master &&
170 git -C upstream rev-parse --verify master >expect &&
171 git -C parent/workbench rev-parse --verify master >actual &&
172 test_cmp expect actual &&
174 git -C parent_upstream rev-parse --verify master >expect &&
175 git -C parent rev-parse --verify master >actual &&
176 test_cmp expect actual &&
178 printf "asdf\nmore structured text\n" >expect &&
179 test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
180 test_cmp expect upstream/.git/hooks/post-receive.push_options &&
181 test_cmp expect parent_upstream/.git/hooks/pre-receive.push_options &&
182 test_cmp expect parent_upstream/.git/hooks/post-receive.push_options