Skip to content

Commit 679beaa

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 60ce244 commit 679beaa

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
@@ -96,15 +96,17 @@ setup_upstream_and_workbench () {
9696
# we will use it in the subsequent test cases.
9797
upstream="$1"
9898

99-
# Upstream after setup : main(B) foo(A) bar(A) baz(A)
100-
# Workbench after setup : main(A)
99+
# Upstream after setup: main(B) foo(A) bar(A) baz(A)
100+
# Workbench after setup: main(A) baz(A) next(A)
101101
test_expect_success "setup upstream repository and workbench" '
102102
setup_upstream "$upstream" &&
103103
rm -rf workbench &&
104104
git clone "$upstream" workbench &&
105105
(
106106
cd workbench &&
107107
git update-ref refs/heads/main $A &&
108+
git update-ref refs/heads/baz $A &&
109+
git update-ref refs/heads/next $A &&
108110
# Try to make a stable fixed width for abbreviated commit ID,
109111
# this fixed-width oid will be replaced with "<OID>".
110112
git config core.abbrev 7 &&
@@ -133,19 +135,14 @@ run_git_push_porcelain_output_test() {
133135
# Refs of upstream : main(B) foo(A) bar(A) baz(A)
134136
# Refs of workbench: main(A) baz(A) next(A)
135137
# git-push : main(A) NULL (B) baz(A) next(A)
136-
test_expect_success "porcelain output of successful git-push ($PROTOCOL)" '
137-
(
138-
cd workbench &&
139-
git update-ref refs/heads/main $A &&
140-
git update-ref refs/heads/baz $A &&
141-
git update-ref refs/heads/next $A &&
142-
git push --porcelain --force origin \
143-
main \
144-
:refs/heads/foo \
145-
$B:bar \
146-
baz \
147-
next
148-
) >out &&
138+
test_expect_success ".. git-push --porcelain --force ($PROTOCOL)" '
139+
test_when_finished "setup_upstream \"$upstream\"" &&
140+
git -C workbench push --porcelain --force origin \
141+
main \
142+
:refs/heads/foo \
143+
$B:bar \
144+
baz \
145+
next >out &&
149146
make_user_friendly_and_stable_output <out >actual &&
150147
format_and_save_expect <<-EOF &&
151148
> To <URL/of/upstream.git>
@@ -169,115 +166,103 @@ run_git_push_porcelain_output_test() {
169166
test_cmp expect actual
170167
'
171168

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

208-
test_expect_success "prepare pre-receive hook ($PROTOCOL)" '
209-
test_hook --setup -C "$upstream" pre-receive <<-EOF
210-
exit 1
203+
# Refs of upstream : main(B) foo(A) bar(A) baz(A)
204+
# Refs of workbench: main(A) baz(A) next(A)
205+
# git-push : main(A) NULL (B) baz(A) next(A)
206+
test_expect_success ".. pre-receive hook declined ($PROTOCOL)" '
207+
test_when_finished "rm -f \"$upstream/hooks/pre-receive\" &&
208+
setup_upstream \"$upstream\"" &&
209+
test_hook --setup -C "$upstream" pre-receive <<-EOF &&
210+
exit 1
211211
EOF
212-
'
213-
214-
# Refs of upstream : main(A) bar(B) baz(A) next(A)
215-
# Refs of workbench: main(B) bar(A) baz(A) next(A)
216-
# git-push : main(B) bar(A) NULL next(A)
217-
test_expect_success "pre-receive hook declined ($PROTOCOL)" '
218-
(
219-
cd workbench &&
220-
git update-ref refs/heads/main $B &&
221-
git update-ref refs/heads/bar $A &&
222-
test_must_fail git push --porcelain --force origin \
223-
main \
224-
bar \
225-
:baz \
226-
next
227-
) >out &&
212+
test_must_fail git -C workbench push --porcelain --force origin \
213+
main \
214+
:refs/heads/foo \
215+
$B:bar \
216+
baz \
217+
next >out &&
228218
make_user_friendly_and_stable_output <out >actual &&
229219
format_and_save_expect <<-EOF &&
230-
To <URL/of/upstream.git>
231-
> = refs/heads/next:refs/heads/next [up to date]
232-
> ! refs/heads/bar:refs/heads/bar [remote rejected] (pre-receive hook declined)
233-
> ! :refs/heads/baz [remote rejected] (pre-receive hook declined)
220+
> To <URL/of/upstream.git>
221+
> = refs/heads/baz:refs/heads/baz [up to date]
222+
> ! <COMMIT-B>:refs/heads/bar [remote rejected] (pre-receive hook declined)
223+
> ! :refs/heads/foo [remote rejected] (pre-receive hook declined)
234224
> ! refs/heads/main:refs/heads/main [remote rejected] (pre-receive hook declined)
235-
Done
225+
> ! refs/heads/next:refs/heads/next [remote rejected] (pre-receive hook declined)
226+
> Done
236227
EOF
237228
test_cmp expect actual &&
238229
239230
git -C "$upstream" show-ref >out &&
240231
make_user_friendly_and_stable_output <out >actual &&
241232
cat >expect <<-EOF &&
242-
<COMMIT-B> refs/heads/bar
233+
<COMMIT-A> refs/heads/bar
243234
<COMMIT-A> refs/heads/baz
244-
<COMMIT-A> refs/heads/main
245-
<COMMIT-A> refs/heads/next
235+
<COMMIT-A> refs/heads/foo
236+
<COMMIT-B> refs/heads/main
246237
EOF
247238
test_cmp expect actual
248239
'
249240

250-
test_expect_success "remove pre-receive hook ($PROTOCOL)" '
251-
rm "$upstream/hooks/pre-receive"
252-
'
253-
254-
# Refs of upstream : main(A) bar(B) baz(A) next(A)
255-
# Refs of workbench: main(B) bar(A) baz(A) next(A)
256-
# git-push : main(B) bar(A) NULL next(A)
257-
test_expect_success "non-fastforward push ($PROTOCOL)" '
241+
# Refs of upstream : main(B) foo(A) bar(A) baz(A)
242+
# Refs of workbench: main(A) baz(A) next(A)
243+
# git-push : main(A) next(A)
244+
test_expect_success ".. non-fastforward push ($PROTOCOL)" '
258245
(
259246
cd workbench &&
260247
test_must_fail git push --porcelain origin \
261248
main \
262-
bar \
263-
:baz \
264249
next
265250
) >out &&
266251
make_user_friendly_and_stable_output <out >actual &&
267252
format_and_save_expect <<-EOF &&
268-
To <URL/of/upstream.git>
269-
> = refs/heads/next:refs/heads/next [up to date]
270-
> - :refs/heads/baz [deleted]
271-
> refs/heads/main:refs/heads/main <COMMIT-A>..<COMMIT-B>
272-
> ! refs/heads/bar:refs/heads/bar [rejected] (non-fast-forward)
273-
Done
253+
> To <URL/of/upstream.git>
254+
> * refs/heads/next:refs/heads/next [new branch]
255+
> ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
256+
> Done
274257
EOF
275258
test_cmp expect actual &&
276259
277260
git -C "$upstream" show-ref >out &&
278261
make_user_friendly_and_stable_output <out >actual &&
279262
cat >expect <<-EOF &&
280-
<COMMIT-B> refs/heads/bar
263+
<COMMIT-A> refs/heads/bar
264+
<COMMIT-A> refs/heads/baz
265+
<COMMIT-A> refs/heads/foo
281266
<COMMIT-B> refs/heads/main
282267
<COMMIT-A> refs/heads/next
283268
EOF

0 commit comments

Comments
 (0)