Skip to content

Commit dd69a12

Browse files
jiangxingitster
authored andcommitted
t5548: add porcelain push test cases for dry-run mode
New dry-run test cases: - git push --porcelain --dry-run - git push --porcelain --dry-run --force - git push --porcelain --dry-run --atomic - git push --porcelain --dry-run --atomic --force Signed-off-by: Jiang Xin <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2329b6b commit dd69a12

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

t/t5548-push-porcelain.sh

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,159 @@ run_git_push_porcelain_output_test() {
336336
'
337337
}
338338

339+
run_git_push_dry_run_porcelain_output_test() {
340+
case $1 in
341+
http)
342+
PROTOCOL="HTTP protocol"
343+
URL_PREFIX="http://.*"
344+
;;
345+
file)
346+
PROTOCOL="builtin protocol"
347+
URL_PREFIX=".*"
348+
;;
349+
esac
350+
351+
# Refs of upstream : main(B) foo(A) bar(A) baz(A)
352+
# Refs of workbench: main(A) baz(A) next(A)
353+
# git-push : main(A) NULL (B) baz(A) next(A)
354+
test_expect_success ".. git-push --porcelain --dry-run ($PROTOCOL)" '
355+
test_must_fail git -C workbench push --porcelain --dry-run origin \
356+
main \
357+
:refs/heads/foo \
358+
$B:bar \
359+
baz \
360+
next >out &&
361+
make_user_friendly_and_stable_output <out >actual &&
362+
format_and_save_expect <<-EOF &&
363+
> To <URL/of/upstream.git>
364+
> = refs/heads/baz:refs/heads/baz [up to date]
365+
> <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
366+
> - :refs/heads/foo [deleted]
367+
> * refs/heads/next:refs/heads/next [new branch]
368+
> ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
369+
> Done
370+
EOF
371+
test_cmp expect actual &&
372+
373+
git -C "$upstream" show-ref >out &&
374+
make_user_friendly_and_stable_output <out >actual &&
375+
cat >expect <<-EOF &&
376+
<COMMIT-A> refs/heads/bar
377+
<COMMIT-A> refs/heads/baz
378+
<COMMIT-A> refs/heads/foo
379+
<COMMIT-B> refs/heads/main
380+
EOF
381+
test_cmp expect actual
382+
'
383+
384+
# Refs of upstream : main(B) foo(A) bar(A) baz(A)
385+
# Refs of workbench: main(A) baz(A) next(A)
386+
# push : main(A) NULL (B) baz(A) next(A)
387+
test_expect_success ".. git-push --porcelain --dry-run --force ($PROTOCOL)" '
388+
git -C workbench push --porcelain --dry-run --force origin \
389+
main \
390+
:refs/heads/foo \
391+
$B:bar \
392+
baz \
393+
next >out &&
394+
make_user_friendly_and_stable_output <out >actual &&
395+
format_and_save_expect <<-EOF &&
396+
> To <URL/of/upstream.git>
397+
> = refs/heads/baz:refs/heads/baz [up to date]
398+
> <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
399+
> - :refs/heads/foo [deleted]
400+
> + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
401+
> * refs/heads/next:refs/heads/next [new branch]
402+
> Done
403+
EOF
404+
test_cmp expect actual &&
405+
406+
git -C "$upstream" show-ref >out &&
407+
make_user_friendly_and_stable_output <out >actual &&
408+
cat >expect <<-EOF &&
409+
<COMMIT-A> refs/heads/bar
410+
<COMMIT-A> refs/heads/baz
411+
<COMMIT-A> refs/heads/foo
412+
<COMMIT-B> refs/heads/main
413+
EOF
414+
test_cmp expect actual
415+
'
416+
417+
# Refs of upstream : main(B) foo(A) bar(A) baz(A)
418+
# Refs of workbench: main(A) baz(A) next(A)
419+
# git-push : main(A) NULL (B) baz(A) next(A)
420+
test_expect_success ".. git-push --porcelain --dry-run --atomic ($PROTOCOL)" '
421+
test_must_fail git -C workbench push --porcelain --dry-run --atomic origin \
422+
main \
423+
:refs/heads/foo \
424+
$B:bar \
425+
baz \
426+
next >out &&
427+
make_user_friendly_and_stable_output <out >actual &&
428+
format_and_save_expect <<-EOF &&
429+
> To <URL/of/upstream.git>
430+
> = refs/heads/baz:refs/heads/baz [up to date]
431+
> ! <COMMIT-B>:refs/heads/bar [rejected] (atomic push failed)
432+
> ! (delete):refs/heads/foo [rejected] (atomic push failed)
433+
> ! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
434+
> ! refs/heads/next:refs/heads/next [rejected] (atomic push failed)
435+
> Done
436+
EOF
437+
test_cmp expect actual &&
438+
439+
git -C "$upstream" show-ref >out &&
440+
make_user_friendly_and_stable_output <out >actual &&
441+
cat >expect <<-EOF &&
442+
<COMMIT-A> refs/heads/bar
443+
<COMMIT-A> refs/heads/baz
444+
<COMMIT-A> refs/heads/foo
445+
<COMMIT-B> refs/heads/main
446+
EOF
447+
test_cmp expect actual
448+
'
449+
450+
# Refs of upstream : main(B) foo(A) bar(A) baz(A)
451+
# Refs of workbench: main(A) baz(A) next(A)
452+
# push : main(A) NULL (B) baz(A) next(A)
453+
test_expect_success ".. git-push --porcelain --dry-run --atomic --force ($PROTOCOL)" '
454+
git -C workbench push --porcelain --dry-run --atomic --force origin \
455+
main \
456+
:refs/heads/foo \
457+
$B:bar \
458+
baz \
459+
next >out &&
460+
make_user_friendly_and_stable_output <out >actual &&
461+
format_and_save_expect <<-EOF &&
462+
> To <URL/of/upstream.git>
463+
> = refs/heads/baz:refs/heads/baz [up to date]
464+
> <COMMIT-B>:refs/heads/bar <COMMIT-A>..<COMMIT-B>
465+
> - :refs/heads/foo [deleted]
466+
> + refs/heads/main:refs/heads/main <COMMIT-B>...<COMMIT-A> (forced update)
467+
> * refs/heads/next:refs/heads/next [new branch]
468+
> Done
469+
EOF
470+
test_cmp expect actual &&
471+
472+
git -C "$upstream" show-ref >out &&
473+
make_user_friendly_and_stable_output <out >actual &&
474+
cat >expect <<-EOF &&
475+
<COMMIT-A> refs/heads/bar
476+
<COMMIT-A> refs/heads/baz
477+
<COMMIT-A> refs/heads/foo
478+
<COMMIT-B> refs/heads/main
479+
EOF
480+
test_cmp expect actual
481+
'
482+
}
483+
339484
setup_upstream_and_workbench upstream.git
340485

341486
run_git_push_porcelain_output_test file
342487

488+
setup_upstream_and_workbench upstream.git
489+
490+
run_git_push_dry_run_porcelain_output_test file
491+
343492
ROOT_PATH="$PWD"
344493
. "$TEST_DIRECTORY"/lib-gpg.sh
345494
. "$TEST_DIRECTORY"/lib-httpd.sh
@@ -351,4 +500,8 @@ setup_upstream_and_workbench "$HTTPD_DOCUMENT_ROOT_PATH/upstream.git"
351500

352501
run_git_push_porcelain_output_test http
353502

503+
setup_upstream_and_workbench "$HTTPD_DOCUMENT_ROOT_PATH/upstream.git"
504+
505+
run_git_push_dry_run_porcelain_output_test http
506+
354507
test_done

0 commit comments

Comments
 (0)