t5545: factor out http repository setup

We repeat many lines of setup code in the two http tests, and further tests would need to repeat it again. Let's factor this out into a function. Incidentally, this also fixes an unlikely bug: if the httpd root path contains a double-quote, our test_when_finished would barf due to improper quoting (we escape the embedded quotes, but not the $, meaning we expand the variable before the eval). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 19, 2018 at 14:48 UTC 6cdffd06d6ce1e997963790f9206fc981715fbbb
1 file changed +11 -11
t/t5545-push-options.sh
+11 -11
@@ -220,14 +220,20 @@ test_expect_success 'invalid push option in config' '
220 . "$TEST_DIRECTORY"/lib-httpd.sh
221 start_httpd
222
223 -test_expect_success 'push option denied properly by http server' '
223 +# set up http repository for fetching/pushing, with push options config
224 +# bool set to $1
225 +mk_http_pair () {
226 test_when_finished "rm -rf test_http_clone" &&
225 - test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
227 + test_when_finished 'rm -rf "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git' &&
228 mk_repo_pair &&
227 - git -C upstream config receive.advertisePushOptions false &&
229 + git -C upstream config receive.advertisePushOptions "$1" &&
230 git -C upstream config http.receivepack true &&
231 cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
230 - git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
232 + git clone "$HTTPD_URL"/smart/upstream test_http_clone
233 +}
234 +
235 +test_expect_success 'push option denied properly by http server' '
236 + mk_http_pair false &&
237 test_commit -C test_http_clone one &&
238 test_must_fail git -C test_http_clone push --push-option=asdf origin master 2>actual &&
239 test_i18ngrep "the receiving end does not support push options" actual &&
@@ -235,13 +241,7 @@ test_expect_success 'push option denied properly by http server' '
241 '
242
243 test_expect_success 'push options work properly across http' '
238 - test_when_finished "rm -rf test_http_clone" &&
239 - test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
240 - mk_repo_pair &&
241 - git -C upstream config receive.advertisePushOptions true &&
242 - git -C upstream config http.receivepack true &&
243 - cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
244 - git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
244 + mk_http_pair true &&
245
246 test_commit -C test_http_clone one &&
247 git -C test_http_clone push origin master &&