Skip to content

Commit 12ad6b8

Browse files
jiangxingitster
authored andcommitted
t5548: refactor to reuse setup_upstream() function
Refactor the function setup_upstream_and_workbench(), extracting create_upstream_template() and setup_upstream() from it. The former is used to create the upstream repository template, while the latter is used to rebuild the upstream repository and will be reused in subsequent commits. To ensure that setup_upstream() works properly in both local and HTTP protocols, the HTTP settings have been moved to the setup_upstream() and setup_upstream_and_workbench() functions. Signed-off-by: Jiang Xin <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b1be395 commit 12ad6b8

File tree

1 file changed

+53
-30
lines changed

1 file changed

+53
-30
lines changed

t/t5548-push-porcelain.sh

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,65 @@ format_and_save_expect () {
5454
sed -e 's/^> //' -e 's/Z$//' >expect
5555
}
5656

57+
create_upstream_template () {
58+
git init --bare upstream-template.git &&
59+
git clone upstream-template.git tmp_work_dir &&
60+
create_commits_in tmp_work_dir A B &&
61+
(
62+
cd tmp_work_dir &&
63+
git push origin \
64+
$B:refs/heads/main \
65+
$A:refs/heads/foo \
66+
$A:refs/heads/bar \
67+
$A:refs/heads/baz
68+
) &&
69+
rm -rf tmp_work_dir
70+
}
71+
72+
setup_upstream () {
73+
if test $# -ne 1
74+
then
75+
BUG "location of upstream repository is not provided"
76+
fi &&
77+
rm -rf "$1" &&
78+
if ! test -d upstream-template.git
79+
then
80+
create_upstream_template
81+
fi &&
82+
git clone --mirror upstream-template.git "$1" &&
83+
# The upstream repository provides services using the HTTP protocol.
84+
if ! test "$1" = "upstream.git"
85+
then
86+
git -C "$1" config http.receivepack true
87+
fi
88+
}
89+
5790
setup_upstream_and_workbench () {
91+
if test $# -ne 1
92+
then
93+
BUG "location of upstream repository is not provided"
94+
fi
95+
upstream="$1"
96+
5897
# Upstream after setup : main(B) foo(A) bar(A) baz(A)
5998
# Workbench after setup : main(A)
6099
test_expect_success "setup upstream repository and workbench" '
61-
rm -rf upstream.git workbench &&
62-
git init --bare upstream.git &&
63-
git init workbench &&
64-
create_commits_in workbench A B &&
100+
setup_upstream "$upstream" &&
101+
rm -rf workbench &&
102+
git clone "$upstream" workbench &&
65103
(
66104
cd workbench &&
105+
git update-ref refs/heads/main $A &&
67106
# Try to make a stable fixed width for abbreviated commit ID,
68107
# this fixed-width oid will be replaced with "<OID>".
69108
git config core.abbrev 7 &&
70-
git remote add origin ../upstream.git &&
71-
git update-ref refs/heads/main $A &&
72-
git push origin \
73-
$B:refs/heads/main \
74-
$A:refs/heads/foo \
75-
$A:refs/heads/bar \
76-
$A:refs/heads/baz
109+
git config advice.pushUpdateRejected false
77110
) &&
78-
git -C "workbench" config advice.pushUpdateRejected false &&
79-
upstream=upstream.git
111+
# The upstream repository provides services using the HTTP protocol.
112+
if ! test "$upstream" = "upstream.git"
113+
then
114+
git -C workbench remote set-url origin "$HTTPD_URL/smart/upstream.git"
115+
fi
80116
'
81117
}
82118

@@ -88,7 +124,7 @@ run_git_push_porcelain_output_test() {
88124
;;
89125
file)
90126
PROTOCOL="builtin protocol"
91-
URL_PREFIX="\.\."
127+
URL_PREFIX=".*"
92128
;;
93129
esac
94130

@@ -247,32 +283,19 @@ run_git_push_porcelain_output_test() {
247283
'
248284
}
249285

250-
# Initialize the upstream repository and local workbench.
251-
setup_upstream_and_workbench
286+
setup_upstream_and_workbench upstream.git
252287

253-
# Run git-push porcelain test on builtin protocol
254288
run_git_push_porcelain_output_test file
255289

256290
ROOT_PATH="$PWD"
257291
. "$TEST_DIRECTORY"/lib-gpg.sh
258292
. "$TEST_DIRECTORY"/lib-httpd.sh
259293
. "$TEST_DIRECTORY"/lib-terminal.sh
260294
start_httpd
261-
262-
# Re-initialize the upstream repository and local workbench.
263-
setup_upstream_and_workbench
264-
265-
test_expect_success "setup for http" '
266-
git -C upstream.git config http.receivepack true &&
267-
upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" &&
268-
mv upstream.git "$upstream" &&
269-
270-
git -C workbench remote set-url origin $HTTPD_URL/smart/upstream.git
271-
'
272-
273295
setup_askpass_helper
274296

275-
# Run git-push porcelain test on HTTP protocol
297+
setup_upstream_and_workbench "$HTTPD_DOCUMENT_ROOT_PATH/upstream.git"
298+
276299
run_git_push_porcelain_output_test http
277300

278301
test_done

0 commit comments

Comments
 (0)