Skip to content

Commit 9877775

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 186167a commit 9877775

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
@@ -338,10 +338,159 @@ run_git_push_porcelain_output_test() {
338338
'
339339
}
340340

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

343488
run_git_push_porcelain_output_test file
344489

490+
setup_upstream_and_workbench upstream.git
491+
492+
run_git_push_dry_run_porcelain_output_test file
493+
345494
ROOT_PATH="$PWD"
346495
. "$TEST_DIRECTORY"/lib-gpg.sh
347496
. "$TEST_DIRECTORY"/lib-httpd.sh
@@ -353,4 +502,8 @@ setup_upstream_and_workbench "$HTTPD_DOCUMENT_ROOT_PATH/upstream.git"
353502

354503
run_git_push_porcelain_output_test http
355504

505+
setup_upstream_and_workbench "$HTTPD_DOCUMENT_ROOT_PATH/upstream.git"
506+
507+
run_git_push_dry_run_porcelain_output_test http
508+
356509
test_done

0 commit comments

Comments
 (0)