2016-07-14 23:49:48 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='pushing to a repository using push options'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
2017-02-08 23:04:00 +01:00
|
|
|
. "$TEST_DIRECTORY"/lib-httpd.sh
|
|
|
|
start_httpd
|
2016-07-14 23:49:48 +02:00
|
|
|
|
|
|
|
mk_repo_pair () {
|
|
|
|
rm -rf workbench upstream &&
|
|
|
|
test_create_repo upstream &&
|
|
|
|
test_create_repo workbench &&
|
|
|
|
(
|
|
|
|
cd upstream &&
|
|
|
|
git config receive.denyCurrentBranch warn &&
|
|
|
|
mkdir -p .git/hooks &&
|
|
|
|
cat >.git/hooks/pre-receive <<-'EOF' &&
|
|
|
|
#!/bin/sh
|
|
|
|
if test -n "$GIT_PUSH_OPTION_COUNT"; then
|
|
|
|
i=0
|
|
|
|
>hooks/pre-receive.push_options
|
|
|
|
while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
|
|
|
|
eval "value=\$GIT_PUSH_OPTION_$i"
|
|
|
|
echo $value >>hooks/pre-receive.push_options
|
|
|
|
i=$((i + 1))
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
EOF
|
|
|
|
chmod u+x .git/hooks/pre-receive
|
|
|
|
|
|
|
|
cat >.git/hooks/post-receive <<-'EOF' &&
|
|
|
|
#!/bin/sh
|
|
|
|
if test -n "$GIT_PUSH_OPTION_COUNT"; then
|
|
|
|
i=0
|
|
|
|
>hooks/post-receive.push_options
|
|
|
|
while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"; do
|
|
|
|
eval "value=\$GIT_PUSH_OPTION_$i"
|
|
|
|
echo $value >>hooks/post-receive.push_options
|
|
|
|
i=$((i + 1))
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
EOF
|
|
|
|
chmod u+x .git/hooks/post-receive
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
git remote add up ../upstream
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
# Compare the ref ($1) in upstream with a ref value from workbench ($2)
|
|
|
|
# i.e. test_refs second HEAD@{2}
|
|
|
|
test_refs () {
|
|
|
|
test $# = 2 &&
|
|
|
|
git -C upstream rev-parse --verify "$1" >expect &&
|
|
|
|
git -C workbench rev-parse --verify "$2" >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'one push option works for a single branch' '
|
|
|
|
mk_repo_pair &&
|
|
|
|
git -C upstream config receive.advertisePushOptions true &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
test_commit one &&
|
|
|
|
git push --mirror up &&
|
|
|
|
test_commit two &&
|
|
|
|
git push --push-option=asdf up master
|
|
|
|
) &&
|
|
|
|
test_refs master master &&
|
|
|
|
echo "asdf" >expect &&
|
|
|
|
test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
|
|
|
|
test_cmp expect upstream/.git/hooks/post-receive.push_options
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'push option denied by remote' '
|
|
|
|
mk_repo_pair &&
|
|
|
|
git -C upstream config receive.advertisePushOptions false &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
test_commit one &&
|
|
|
|
git push --mirror up &&
|
|
|
|
test_commit two &&
|
|
|
|
test_must_fail git push --push-option=asdf up master
|
|
|
|
) &&
|
|
|
|
test_refs master HEAD@{1}
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'two push options work' '
|
|
|
|
mk_repo_pair &&
|
|
|
|
git -C upstream config receive.advertisePushOptions true &&
|
|
|
|
(
|
|
|
|
cd workbench &&
|
|
|
|
test_commit one &&
|
|
|
|
git push --mirror up &&
|
|
|
|
test_commit two &&
|
|
|
|
git push --push-option=asdf --push-option="more structured text" up master
|
|
|
|
) &&
|
|
|
|
test_refs master master &&
|
|
|
|
printf "asdf\nmore structured text\n" >expect &&
|
|
|
|
test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
|
|
|
|
test_cmp expect upstream/.git/hooks/post-receive.push_options
|
|
|
|
'
|
|
|
|
|
2017-03-22 23:22:00 +01:00
|
|
|
test_expect_success 'push option denied properly by http server' '
|
|
|
|
test_when_finished "rm -rf test_http_clone" &&
|
|
|
|
test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
|
2017-02-08 23:04:00 +01:00
|
|
|
mk_repo_pair &&
|
|
|
|
git -C upstream config receive.advertisePushOptions false &&
|
|
|
|
git -C upstream config http.receivepack true &&
|
|
|
|
cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
|
|
|
|
git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
|
|
|
|
test_commit -C test_http_clone one &&
|
2017-03-22 23:22:00 +01:00
|
|
|
test_must_fail git -C test_http_clone push --push-option=asdf origin master 2>actual &&
|
|
|
|
test_i18ngrep "the receiving end does not support push options" actual &&
|
2017-02-08 23:04:00 +01:00
|
|
|
git -C test_http_clone push origin master
|
|
|
|
'
|
|
|
|
|
2017-03-22 23:22:00 +01:00
|
|
|
test_expect_success 'push options work properly across http' '
|
|
|
|
test_when_finished "rm -rf test_http_clone" &&
|
|
|
|
test_when_finished "rm -rf \"$HTTPD_DOCUMENT_ROOT_PATH\"/upstream.git" &&
|
|
|
|
mk_repo_pair &&
|
|
|
|
git -C upstream config receive.advertisePushOptions true &&
|
|
|
|
git -C upstream config http.receivepack true &&
|
|
|
|
cp -R upstream/.git "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git &&
|
|
|
|
git clone "$HTTPD_URL"/smart/upstream test_http_clone &&
|
|
|
|
|
|
|
|
test_commit -C test_http_clone one &&
|
|
|
|
git -C test_http_clone push origin master &&
|
|
|
|
git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
|
|
|
|
git -C test_http_clone rev-parse --verify master >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
|
|
|
|
test_commit -C test_http_clone two &&
|
|
|
|
git -C test_http_clone push --push-option=asdf --push-option="more structured text" origin master &&
|
|
|
|
printf "asdf\nmore structured text\n" >expect &&
|
|
|
|
test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/pre-receive.push_options &&
|
|
|
|
test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git/hooks/post-receive.push_options &&
|
|
|
|
|
|
|
|
git -C "$HTTPD_DOCUMENT_ROOT_PATH"/upstream.git rev-parse --verify master >expect &&
|
|
|
|
git -C test_http_clone rev-parse --verify master >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2017-02-08 23:04:00 +01:00
|
|
|
stop_httpd
|
|
|
|
|
2016-07-14 23:49:48 +02:00
|
|
|
test_done
|