Skip to content

Commit bc0f593

Browse files
jiangxingitster
authored andcommitted
t5548: refactor test cases by resetting upstream
Refactor the test cases with the following changes: - Calling setup_upstream() to reset upstream after running each test case. - Change the initial branch tips of the workspace to reduce the branch setup operations in the workspace. - Reduced the two steps of setting up and cleaning up the pre-receive hook by moving the operations into the corresponding test case, Signed-off-by: Jiang Xin <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 12ad6b8 commit bc0f593

File tree

1 file changed

+67
-82
lines changed

1 file changed

+67
-82
lines changed

t/t5548-push-porcelain.sh

Lines changed: 67 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,17 @@ setup_upstream_and_workbench () {
9494
fi
9595
upstream="$1"
9696

97-
# Upstream after setup : main(B) foo(A) bar(A) baz(A)
98-
# Workbench after setup : main(A)
97+
# Upstream after setup: main(B) foo(A) bar(A) baz(A)
98+
# Workbench after setup: main(A) baz(A) next(A)
9999
test_expect_success "setup upstream repository and workbench" '
100100
setup_upstream "$upstream" &&
101101
rm -rf workbench &&
102102
git clone "$upstream" workbench &&
103103
(
104104
cd workbench &&
105105
git update-ref refs/heads/main $A &&
106+
git update-ref refs/heads/baz $A &&
107+
git update-ref refs/heads/next $A &&
106108
# Try to make a stable fixed width for abbreviated commit ID,
107109
# this fixed-width oid will be replaced with "<OID>".
108110
git config core.abbrev 7 &&
@@ -131,19 +133,14 @@ run_git_push_porcelain_output_test() {
131133
# Refs of upstream : main(B) foo(A) bar(A) baz(A)
132134
# Refs of workbench: main(A) baz(A) next(A)
133135
# git-push : main(A) NULL (B) baz(A) next(A)
134-
test_expect_success "porcelain output of successful git-push ($PROTOCOL)" '
135-
(
136-
cd workbench &&
137-
git update-ref refs/heads/main $A &&
138-
git update-ref refs/heads/baz $A &&
139-
git update-ref refs/heads/next $A &&
140-
git push --porcelain --force origin \
141-
main \
142-
:refs/heads/foo \
143-
$B:bar \
144-
baz \
145-
next
146-
) >out &&
136+
test_expect_success ".. git-push --porcelain --force ($PROTOCOL)" '
137+
test_when_finished "setup_upstream \"$upstream\"" &&
138+
git -C workbench push --porcelain --force origin \
139+
main \
140+
:refs/heads/foo \
141+
$B:bar \
142+
baz \
143+
next >out &&
147144
make_user_friendly_and_stable_output <out >actual &&
148145
format_and_save_expect <<-EOF &&
149146
> To <URL/of/upstream.git>
@@ -167,115 +164,103 @@ run_git_push_porcelain_output_test() {
167164
test_cmp expect actual
168165
'
169166

170-
# Refs of upstream : main(A) bar(B) baz(A) next(A)
171-
# Refs of workbench: main(B) bar(A) baz(A) next(A)
172-
# git-push : main(B) bar(A) NULL next(A)
173-
test_expect_success "atomic push failed ($PROTOCOL)" '
174-
(
175-
cd workbench &&
176-
git update-ref refs/heads/main $B &&
177-
git update-ref refs/heads/bar $A &&
178-
test_must_fail git push --atomic --porcelain origin \
179-
main \
180-
bar \
181-
:baz \
182-
next
183-
) >out &&
167+
# Refs of upstream : main(B) foo(A) bar(A) baz(A)
168+
# Refs of workbench: main(A) baz(A) next(A)
169+
# git-push : main(A) NULL (B) baz(A) next(A)
170+
test_expect_success ".. git push --porcelain --atomic ($PROTOCOL)" '
171+
test_when_finished "setup_upstream \"$upstream\"" &&
172+
test_must_fail git -C workbench push --porcelain --atomic origin \
173+
main \
174+
:refs/heads/foo \
175+
$B:bar \
176+
baz \
177+
next >out &&
184178
make_user_friendly_and_stable_output <out >actual &&
185179
format_and_save_expect <<-EOF &&
186-
To <URL/of/upstream.git>
187-
> = refs/heads/next:refs/heads/next [up to date]
188-
> ! refs/heads/bar:refs/heads/bar [rejected] (non-fast-forward)
189-
> ! (delete):refs/heads/baz [rejected] (atomic push failed)
190-
> ! refs/heads/main:refs/heads/main [rejected] (atomic push failed)
191-
Done
180+
> To <URL/of/upstream.git>
181+
> = refs/heads/baz:refs/heads/baz [up to date]
182+
> ! <COMMIT-B>:refs/heads/bar [rejected] (atomic push failed)
183+
> ! (delete):refs/heads/foo [rejected] (atomic push failed)
184+
> ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
185+
> ! refs/heads/next:refs/heads/next [rejected] (atomic push failed)
186+
> Done
192187
EOF
193188
test_cmp expect actual &&
194189
195190
git -C "$upstream" show-ref >out &&
196191
make_user_friendly_and_stable_output <out >actual &&
197192
cat >expect <<-EOF &&
198-
<COMMIT-B> refs/heads/bar
193+
<COMMIT-A> refs/heads/bar
199194
<COMMIT-A> refs/heads/baz
200-
<COMMIT-A> refs/heads/main
201-
<COMMIT-A> refs/heads/next
195+
<COMMIT-A> refs/heads/foo
196+
<COMMIT-B> refs/heads/main
202197
EOF
203198
test_cmp expect actual
204199
'
205200

206-
test_expect_success "prepare pre-receive hook ($PROTOCOL)" '
207-
test_hook --setup -C "$upstream" pre-receive <<-EOF
208-
exit 1
201+
# Refs of upstream : main(B) foo(A) bar(A) baz(A)
202+
# Refs of workbench: main(A) baz(A) next(A)
203+
# git-push : main(A) NULL (B) baz(A) next(A)
204+
test_expect_success ".. pre-receive hook declined ($PROTOCOL)" '
205+
test_when_finished "rm -f \"$upstream/hooks/pre-receive\" &&
206+
setup_upstream \"$upstream\"" &&
207+
test_hook --setup -C "$upstream" pre-receive <<-EOF &&
208+
exit 1
209209
EOF
210-
'
211-
212-
# Refs of upstream : main(A) bar(B) baz(A) next(A)
213-
# Refs of workbench: main(B) bar(A) baz(A) next(A)
214-
# git-push : main(B) bar(A) NULL next(A)
215-
test_expect_success "pre-receive hook declined ($PROTOCOL)" '
216-
(
217-
cd workbench &&
218-
git update-ref refs/heads/main $B &&
219-
git update-ref refs/heads/bar $A &&
220-
test_must_fail git push --porcelain --force origin \
221-
main \
222-
bar \
223-
:baz \
224-
next
225-
) >out &&
210+
test_must_fail git -C workbench push --porcelain --force origin \
211+
main \
212+
:refs/heads/foo \
213+
$B:bar \
214+
baz \
215+
next >out &&
226216
make_user_friendly_and_stable_output <out >actual &&
227217
format_and_save_expect <<-EOF &&
228-
To <URL/of/upstream.git>
229-
> = refs/heads/next:refs/heads/next [up to date]
230-
> ! refs/heads/bar:refs/heads/bar [remote rejected] (pre-receive hook declined)
231-
> ! :refs/heads/baz [remote rejected] (pre-receive hook declined)
218+
> To <URL/of/upstream.git>
219+
> = refs/heads/baz:refs/heads/baz [up to date]
220+
> ! <COMMIT-B>:refs/heads/bar [remote rejected] (pre-receive hook declined)
221+
> ! :refs/heads/foo [remote rejected] (pre-receive hook declined)
232222
> ! refs/heads/main:refs/heads/main [remote rejected] (pre-receive hook declined)
233-
Done
223+
> ! refs/heads/next:refs/heads/next [remote rejected] (pre-receive hook declined)
224+
> Done
234225
EOF
235226
test_cmp expect actual &&
236227
237228
git -C "$upstream" show-ref >out &&
238229
make_user_friendly_and_stable_output <out >actual &&
239230
cat >expect <<-EOF &&
240-
<COMMIT-B> refs/heads/bar
231+
<COMMIT-A> refs/heads/bar
241232
<COMMIT-A> refs/heads/baz
242-
<COMMIT-A> refs/heads/main
243-
<COMMIT-A> refs/heads/next
233+
<COMMIT-A> refs/heads/foo
234+
<COMMIT-B> refs/heads/main
244235
EOF
245236
test_cmp expect actual
246237
'
247238

248-
test_expect_success "remove pre-receive hook ($PROTOCOL)" '
249-
rm "$upstream/hooks/pre-receive"
250-
'
251-
252-
# Refs of upstream : main(A) bar(B) baz(A) next(A)
253-
# Refs of workbench: main(B) bar(A) baz(A) next(A)
254-
# git-push : main(B) bar(A) NULL next(A)
255-
test_expect_success "non-fastforward push ($PROTOCOL)" '
239+
# Refs of upstream : main(B) foo(A) bar(A) baz(A)
240+
# Refs of workbench: main(A) baz(A) next(A)
241+
# git-push : main(A) next(A)
242+
test_expect_success ".. non-fastforward push ($PROTOCOL)" '
256243
(
257244
cd workbench &&
258245
test_must_fail git push --porcelain origin \
259246
main \
260-
bar \
261-
:baz \
262247
next
263248
) >out &&
264249
make_user_friendly_and_stable_output <out >actual &&
265250
format_and_save_expect <<-EOF &&
266-
To <URL/of/upstream.git>
267-
> = refs/heads/next:refs/heads/next [up to date]
268-
> - :refs/heads/baz [deleted]
269-
> refs/heads/main:refs/heads/main <COMMIT-A>..<COMMIT-B>
270-
> ! refs/heads/bar:refs/heads/bar [rejected] (non-fast-forward)
271-
Done
251+
> To <URL/of/upstream.git>
252+
> * refs/heads/next:refs/heads/next [new branch]
253+
> ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
254+
> Done
272255
EOF
273256
test_cmp expect actual &&
274257
275258
git -C "$upstream" show-ref >out &&
276259
make_user_friendly_and_stable_output <out >actual &&
277260
cat >expect <<-EOF &&
278-
<COMMIT-B> refs/heads/bar
261+
<COMMIT-A> refs/heads/bar
262+
<COMMIT-A> refs/heads/baz
263+
<COMMIT-A> refs/heads/foo
279264
<COMMIT-B> refs/heads/main
280265
<COMMIT-A> refs/heads/next
281266
EOF

0 commit comments

Comments
 (0)