update-ref: add test cases covering --stdin signature

Extend t/t1400-update-ref.sh to cover cases using the --stdin option. Signed-off-by: Brad King <brad.king@kitware.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brad King committed Sep 11, 2013 at 08:46 UTC c6268bc0082e340633b7a785e6c7761cd54063cc
1 file changed +632
t/t1400-update-ref.sh
+632
@@ -302,4 +302,636 @@ test_expect_success \
302 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
303 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'
304
305 +a=refs/heads/a
306 +b=refs/heads/b
307 +c=refs/heads/c
308 +E='""'
309 +F='%s\0'
310 +pws='path with space'
311 +
312 +test_expect_success 'stdin test setup' '
313 + echo "$pws" >"$pws" &&
314 + git add -- "$pws" &&
315 + git commit -m "$pws"
316 +'
317 +
318 +test_expect_success '-z fails without --stdin' '
319 + test_must_fail git update-ref -z $m $m $m 2>err &&
320 + grep "usage: git update-ref" err
321 +'
322 +
323 +test_expect_success 'stdin works with no input' '
324 + >stdin &&
325 + git update-ref --stdin <stdin &&
326 + git rev-parse --verify -q $m
327 +'
328 +
329 +test_expect_success 'stdin fails on empty line' '
330 + echo "" >stdin &&
331 + test_must_fail git update-ref --stdin <stdin 2>err &&
332 + grep "fatal: empty command in input" err
333 +'
334 +
335 +test_expect_success 'stdin fails on only whitespace' '
336 + echo " " >stdin &&
337 + test_must_fail git update-ref --stdin <stdin 2>err &&
338 + grep "fatal: whitespace before command: " err
339 +'
340 +
341 +test_expect_success 'stdin fails on leading whitespace' '
342 + echo " create $a $m" >stdin &&
343 + test_must_fail git update-ref --stdin <stdin 2>err &&
344 + grep "fatal: whitespace before command: create $a $m" err
345 +'
346 +
347 +test_expect_success 'stdin fails on unknown command' '
348 + echo "unknown $a" >stdin &&
349 + test_must_fail git update-ref --stdin <stdin 2>err &&
350 + grep "fatal: unknown command: unknown $a" err
351 +'
352 +
353 +test_expect_success 'stdin fails on badly quoted input' '
354 + echo "create $a \"master" >stdin &&
355 + test_must_fail git update-ref --stdin <stdin 2>err &&
356 + grep "fatal: badly quoted argument: \\\"master" err
357 +'
358 +
359 +test_expect_success 'stdin fails on arguments not separated by space' '
360 + echo "create \"$a\"master" >stdin &&
361 + test_must_fail git update-ref --stdin <stdin 2>err &&
362 + grep "fatal: expected SP but got: master" err
363 +'
364 +
365 +test_expect_success 'stdin fails create with no ref' '
366 + echo "create " >stdin &&
367 + test_must_fail git update-ref --stdin <stdin 2>err &&
368 + grep "fatal: create line missing <ref>" err
369 +'
370 +
371 +test_expect_success 'stdin fails create with bad ref name' '
372 + echo "create ~a $m" >stdin &&
373 + test_must_fail git update-ref --stdin <stdin 2>err &&
374 + grep "fatal: invalid ref format: ~a" err
375 +'
376 +
377 +test_expect_success 'stdin fails create with no new value' '
378 + echo "create $a" >stdin &&
379 + test_must_fail git update-ref --stdin <stdin 2>err &&
380 + grep "fatal: create $a missing <newvalue>" err
381 +'
382 +
383 +test_expect_success 'stdin fails create with too many arguments' '
384 + echo "create $a $m $m" >stdin &&
385 + test_must_fail git update-ref --stdin <stdin 2>err &&
386 + grep "fatal: create $a has extra input: $m" err
387 +'
388 +
389 +test_expect_success 'stdin fails update with no ref' '
390 + echo "update " >stdin &&
391 + test_must_fail git update-ref --stdin <stdin 2>err &&
392 + grep "fatal: update line missing <ref>" err
393 +'
394 +
395 +test_expect_success 'stdin fails update with bad ref name' '
396 + echo "update ~a $m" >stdin &&
397 + test_must_fail git update-ref --stdin <stdin 2>err &&
398 + grep "fatal: invalid ref format: ~a" err
399 +'
400 +
401 +test_expect_success 'stdin fails update with no new value' '
402 + echo "update $a" >stdin &&
403 + test_must_fail git update-ref --stdin <stdin 2>err &&
404 + grep "fatal: update $a missing <newvalue>" err
405 +'
406 +
407 +test_expect_success 'stdin fails update with too many arguments' '
408 + echo "update $a $m $m $m" >stdin &&
409 + test_must_fail git update-ref --stdin <stdin 2>err &&
410 + grep "fatal: update $a has extra input: $m" err
411 +'
412 +
413 +test_expect_success 'stdin fails delete with no ref' '
414 + echo "delete " >stdin &&
415 + test_must_fail git update-ref --stdin <stdin 2>err &&
416 + grep "fatal: delete line missing <ref>" err
417 +'
418 +
419 +test_expect_success 'stdin fails delete with bad ref name' '
420 + echo "delete ~a $m" >stdin &&
421 + test_must_fail git update-ref --stdin <stdin 2>err &&
422 + grep "fatal: invalid ref format: ~a" err
423 +'
424 +
425 +test_expect_success 'stdin fails delete with too many arguments' '
426 + echo "delete $a $m $m" >stdin &&
427 + test_must_fail git update-ref --stdin <stdin 2>err &&
428 + grep "fatal: delete $a has extra input: $m" err
429 +'
430 +
431 +test_expect_success 'stdin fails verify with too many arguments' '
432 + echo "verify $a $m $m" >stdin &&
433 + test_must_fail git update-ref --stdin <stdin 2>err &&
434 + grep "fatal: verify $a has extra input: $m" err
435 +'
436 +
437 +test_expect_success 'stdin fails option with unknown name' '
438 + echo "option unknown" >stdin &&
439 + test_must_fail git update-ref --stdin <stdin 2>err &&
440 + grep "fatal: option unknown: unknown" err
441 +'
442 +
443 +test_expect_success 'stdin fails with duplicate refs' '
444 + cat >stdin <<-EOF &&
445 + create $a $m
446 + create $b $m
447 + create $a $m
448 + EOF
449 + test_must_fail git update-ref --stdin <stdin 2>err &&
450 + grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
451 +'
452 +
453 +test_expect_success 'stdin create ref works' '
454 + echo "create $a $m" >stdin &&
455 + git update-ref --stdin <stdin &&
456 + git rev-parse $m >expect &&
457 + git rev-parse $a >actual &&
458 + test_cmp expect actual
459 +'
460 +
461 +test_expect_success 'stdin update ref creates with zero old value' '
462 + echo "update $b $m $Z" >stdin &&
463 + git update-ref --stdin <stdin &&
464 + git rev-parse $m >expect &&
465 + git rev-parse $b >actual &&
466 + test_cmp expect actual &&
467 + git update-ref -d $b
468 +'
469 +
470 +test_expect_success 'stdin update ref creates with empty old value' '
471 + echo "update $b $m $E" >stdin &&
472 + git update-ref --stdin <stdin &&
473 + git rev-parse $m >expect &&
474 + git rev-parse $b >actual &&
475 + test_cmp expect actual
476 +'
477 +
478 +test_expect_success 'stdin create ref works with path with space to blob' '
479 + echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
480 + git update-ref --stdin <stdin &&
481 + git rev-parse "$m:$pws" >expect &&
482 + git rev-parse refs/blobs/pws >actual &&
483 + test_cmp expect actual &&
484 + git update-ref -d refs/blobs/pws
485 +'
486 +
487 +test_expect_success 'stdin update ref fails with wrong old value' '
488 + echo "update $c $m $m~1" >stdin &&
489 + test_must_fail git update-ref --stdin <stdin 2>err &&
490 + grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
491 + test_must_fail git rev-parse --verify -q $c
492 +'
493 +
494 +test_expect_success 'stdin update ref fails with bad old value' '
495 + echo "update $c $m does-not-exist" >stdin &&
496 + test_must_fail git update-ref --stdin <stdin 2>err &&
497 + grep "fatal: invalid old value for ref $c: does-not-exist" err &&
498 + test_must_fail git rev-parse --verify -q $c
499 +'
500 +
501 +test_expect_success 'stdin create ref fails with bad new value' '
502 + echo "create $c does-not-exist" >stdin &&
503 + test_must_fail git update-ref --stdin <stdin 2>err &&
504 + grep "fatal: invalid new value for ref $c: does-not-exist" err &&
505 + test_must_fail git rev-parse --verify -q $c
506 +'
507 +
508 +test_expect_success 'stdin create ref fails with zero new value' '
509 + echo "create $c " >stdin &&
510 + test_must_fail git update-ref --stdin <stdin 2>err &&
511 + grep "fatal: create $c given zero new value" err &&
512 + test_must_fail git rev-parse --verify -q $c
513 +'
514 +
515 +test_expect_success 'stdin update ref works with right old value' '
516 + echo "update $b $m~1 $m" >stdin &&
517 + git update-ref --stdin <stdin &&
518 + git rev-parse $m~1 >expect &&
519 + git rev-parse $b >actual &&
520 + test_cmp expect actual
521 +'
522 +
523 +test_expect_success 'stdin delete ref fails with wrong old value' '
524 + echo "delete $a $m~1" >stdin &&
525 + test_must_fail git update-ref --stdin <stdin 2>err &&
526 + grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
527 + git rev-parse $m >expect &&
528 + git rev-parse $a >actual &&
529 + test_cmp expect actual
530 +'
531 +
532 +test_expect_success 'stdin delete ref fails with zero old value' '
533 + echo "delete $a " >stdin &&
534 + test_must_fail git update-ref --stdin <stdin 2>err &&
535 + grep "fatal: delete $a given zero old value" err &&
536 + git rev-parse $m >expect &&
537 + git rev-parse $a >actual &&
538 + test_cmp expect actual
539 +'
540 +
541 +test_expect_success 'stdin update symref works option no-deref' '
542 + git symbolic-ref TESTSYMREF $b &&
543 + cat >stdin <<-EOF &&
544 + option no-deref
545 + update TESTSYMREF $a $b
546 + EOF
547 + git update-ref --stdin <stdin &&
548 + git rev-parse TESTSYMREF >expect &&
549 + git rev-parse $a >actual &&
550 + test_cmp expect actual &&
551 + git rev-parse $m~1 >expect &&
552 + git rev-parse $b >actual &&
553 + test_cmp expect actual
554 +'
555 +
556 +test_expect_success 'stdin delete symref works option no-deref' '
557 + git symbolic-ref TESTSYMREF $b &&
558 + cat >stdin <<-EOF &&
559 + option no-deref
560 + delete TESTSYMREF $b
561 + EOF
562 + git update-ref --stdin <stdin &&
563 + test_must_fail git rev-parse --verify -q TESTSYMREF &&
564 + git rev-parse $m~1 >expect &&
565 + git rev-parse $b >actual &&
566 + test_cmp expect actual
567 +'
568 +
569 +test_expect_success 'stdin delete ref works with right old value' '
570 + echo "delete $b $m~1" >stdin &&
571 + git update-ref --stdin <stdin &&
572 + test_must_fail git rev-parse --verify -q $b
573 +'
574 +
575 +test_expect_success 'stdin update/create/verify combination works' '
576 + cat >stdin <<-EOF &&
577 + update $a $m
578 + create $b $m
579 + verify $c
580 + EOF
581 + git update-ref --stdin <stdin &&
582 + git rev-parse $m >expect &&
583 + git rev-parse $a >actual &&
584 + test_cmp expect actual &&
585 + git rev-parse $b >actual &&
586 + test_cmp expect actual &&
587 + test_must_fail git rev-parse --verify -q $c
588 +'
589 +
590 +test_expect_success 'stdin update refs works with identity updates' '
591 + cat >stdin <<-EOF &&
592 + update $a $m $m
593 + update $b $m $m
594 + update $c $Z $E
595 + EOF
596 + git update-ref --stdin <stdin &&
597 + git rev-parse $m >expect &&
598 + git rev-parse $a >actual &&
599 + test_cmp expect actual &&
600 + git rev-parse $b >actual &&
601 + test_cmp expect actual &&
602 + test_must_fail git rev-parse --verify -q $c
603 +'
604 +
605 +test_expect_success 'stdin update refs fails with wrong old value' '
606 + git update-ref $c $m &&
607 + cat >stdin <<-EOF &&
608 + update $a $m $m
609 + update $b $m $m
610 + update $c ''
611 + EOF
612 + test_must_fail git update-ref --stdin <stdin 2>err &&
613 + grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
614 + git rev-parse $m >expect &&
615 + git rev-parse $a >actual &&
616 + test_cmp expect actual &&
617 + git rev-parse $b >actual &&
618 + test_cmp expect actual &&
619 + git rev-parse $c >actual &&
620 + test_cmp expect actual
621 +'
622 +
623 +test_expect_success 'stdin delete refs works with packed and loose refs' '
624 + git pack-refs --all &&
625 + git update-ref $c $m~1 &&
626 + cat >stdin <<-EOF &&
627 + delete $a $m
628 + update $b $Z $m
629 + update $c $E $m~1
630 + EOF
631 + git update-ref --stdin <stdin &&
632 + test_must_fail git rev-parse --verify -q $a &&
633 + test_must_fail git rev-parse --verify -q $b &&
634 + test_must_fail git rev-parse --verify -q $c
635 +'
636 +
637 +test_expect_success 'stdin -z works on empty input' '
638 + >stdin &&
639 + git update-ref -z --stdin <stdin &&
640 + git rev-parse --verify -q $m
641 +'
642 +
643 +test_expect_success 'stdin -z fails on empty line' '
644 + echo "" >stdin &&
645 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
646 + grep "fatal: whitespace before command: " err
647 +'
648 +
649 +test_expect_success 'stdin -z fails on empty command' '
650 + printf $F "" >stdin &&
651 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
652 + grep "fatal: empty command in input" err
653 +'
654 +
655 +test_expect_success 'stdin -z fails on only whitespace' '
656 + printf $F " " >stdin &&
657 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
658 + grep "fatal: whitespace before command: " err
659 +'
660 +
661 +test_expect_success 'stdin -z fails on leading whitespace' '
662 + printf $F " create $a" "$m" >stdin &&
663 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
664 + grep "fatal: whitespace before command: create $a" err
665 +'
666 +
667 +test_expect_success 'stdin -z fails on unknown command' '
668 + printf $F "unknown $a" >stdin &&
669 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
670 + grep "fatal: unknown command: unknown $a" err
671 +'
672 +
673 +test_expect_success 'stdin -z fails create with no ref' '
674 + printf $F "create " >stdin &&
675 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
676 + grep "fatal: create line missing <ref>" err
677 +'
678 +
679 +test_expect_success 'stdin -z fails create with bad ref name' '
680 + printf $F "create ~a " "$m" >stdin &&
681 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
682 + grep "fatal: invalid ref format: ~a " err
683 +'
684 +
685 +test_expect_success 'stdin -z fails create with no new value' '
686 + printf $F "create $a" >stdin &&
687 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
688 + grep "fatal: create $a missing <newvalue>" err
689 +'
690 +
691 +test_expect_success 'stdin -z fails create with too many arguments' '
692 + printf $F "create $a" "$m" "$m" >stdin &&
693 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
694 + grep "fatal: unknown command: $m" err
695 +'
696 +
697 +test_expect_success 'stdin -z fails update with no ref' '
698 + printf $F "update " >stdin &&
699 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
700 + grep "fatal: update line missing <ref>" err
701 +'
702 +
703 +test_expect_success 'stdin -z fails update with bad ref name' '
704 + printf $F "update ~a" "$m" >stdin &&
705 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
706 + grep "fatal: invalid ref format: ~a" err
707 +'
708 +
709 +test_expect_success 'stdin -z fails update with no new value' '
710 + printf $F "update $a" >stdin &&
711 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
712 + grep "fatal: update $a missing <newvalue>" err
713 +'
714 +
715 +test_expect_success 'stdin -z fails update with no old value' '
716 + printf $F "update $a" "$m" >stdin &&
717 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
718 + grep "fatal: update $a missing \\[<oldvalue>\\] NUL" err
719 +'
720 +
721 +test_expect_success 'stdin -z fails update with too many arguments' '
722 + printf $F "update $a" "$m" "$m" "$m" >stdin &&
723 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
724 + grep "fatal: unknown command: $m" err
725 +'
726 +
727 +test_expect_success 'stdin -z fails delete with no ref' '
728 + printf $F "delete " >stdin &&
729 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
730 + grep "fatal: delete line missing <ref>" err
731 +'
732 +
733 +test_expect_success 'stdin -z fails delete with bad ref name' '
734 + printf $F "delete ~a" "$m" >stdin &&
735 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
736 + grep "fatal: invalid ref format: ~a" err
737 +'
738 +
739 +test_expect_success 'stdin -z fails delete with no old value' '
740 + printf $F "delete $a" >stdin &&
741 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
742 + grep "fatal: delete $a missing \\[<oldvalue>\\] NUL" err
743 +'
744 +
745 +test_expect_success 'stdin -z fails delete with too many arguments' '
746 + printf $F "delete $a" "$m" "$m" >stdin &&
747 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
748 + grep "fatal: unknown command: $m" err
749 +'
750 +
751 +test_expect_success 'stdin -z fails verify with too many arguments' '
752 + printf $F "verify $a" "$m" "$m" >stdin &&
753 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
754 + grep "fatal: unknown command: $m" err
755 +'
756 +
757 +test_expect_success 'stdin -z fails verify with no old value' '
758 + printf $F "verify $a" >stdin &&
759 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
760 + grep "fatal: verify $a missing \\[<oldvalue>\\] NUL" err
761 +'
762 +
763 +test_expect_success 'stdin -z fails option with unknown name' '
764 + printf $F "option unknown" >stdin &&
765 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
766 + grep "fatal: option unknown: unknown" err
767 +'
768 +
769 +test_expect_success 'stdin -z fails with duplicate refs' '
770 + printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
771 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
772 + grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
773 +'
774 +
775 +test_expect_success 'stdin -z create ref works' '
776 + printf $F "create $a" "$m" >stdin &&
777 + git update-ref -z --stdin <stdin &&
778 + git rev-parse $m >expect &&
779 + git rev-parse $a >actual &&
780 + test_cmp expect actual
781 +'
782 +
783 +test_expect_success 'stdin -z update ref creates with zero old value' '
784 + printf $F "update $b" "$m" "$Z" >stdin &&
785 + git update-ref -z --stdin <stdin &&
786 + git rev-parse $m >expect &&
787 + git rev-parse $b >actual &&
788 + test_cmp expect actual &&
789 + git update-ref -d $b
790 +'
791 +
792 +test_expect_success 'stdin -z update ref creates with empty old value' '
793 + printf $F "update $b" "$m" "" >stdin &&
794 + git update-ref -z --stdin <stdin &&
795 + git rev-parse $m >expect &&
796 + git rev-parse $b >actual &&
797 + test_cmp expect actual
798 +'
799 +
800 +test_expect_success 'stdin -z create ref works with path with space to blob' '
801 + printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
802 + git update-ref -z --stdin <stdin &&
803 + git rev-parse "$m:$pws" >expect &&
804 + git rev-parse refs/blobs/pws >actual &&
805 + test_cmp expect actual &&
806 + git update-ref -d refs/blobs/pws
807 +'
808 +
809 +test_expect_success 'stdin -z update ref fails with wrong old value' '
810 + printf $F "update $c" "$m" "$m~1" >stdin &&
811 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
812 + grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
813 + test_must_fail git rev-parse --verify -q $c
814 +'
815 +
816 +test_expect_success 'stdin -z update ref fails with bad old value' '
817 + printf $F "update $c" "$m" "does-not-exist" >stdin &&
818 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
819 + grep "fatal: invalid old value for ref $c: does-not-exist" err &&
820 + test_must_fail git rev-parse --verify -q $c
821 +'
822 +
823 +test_expect_success 'stdin -z create ref fails with bad new value' '
824 + printf $F "create $c" "does-not-exist" >stdin &&
825 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
826 + grep "fatal: invalid new value for ref $c: does-not-exist" err &&
827 + test_must_fail git rev-parse --verify -q $c
828 +'
829 +
830 +test_expect_success 'stdin -z create ref fails with zero new value' '
831 + printf $F "create $c" "" >stdin &&
832 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
833 + grep "fatal: create $c given zero new value" err &&
834 + test_must_fail git rev-parse --verify -q $c
835 +'
836 +
837 +test_expect_success 'stdin -z update ref works with right old value' '
838 + printf $F "update $b" "$m~1" "$m" >stdin &&
839 + git update-ref -z --stdin <stdin &&
840 + git rev-parse $m~1 >expect &&
841 + git rev-parse $b >actual &&
842 + test_cmp expect actual
843 +'
844 +
845 +test_expect_success 'stdin -z delete ref fails with wrong old value' '
846 + printf $F "delete $a" "$m~1" >stdin &&
847 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
848 + grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
849 + git rev-parse $m >expect &&
850 + git rev-parse $a >actual &&
851 + test_cmp expect actual
852 +'
853 +
854 +test_expect_success 'stdin -z delete ref fails with zero old value' '
855 + printf $F "delete $a" "$Z" >stdin &&
856 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
857 + grep "fatal: delete $a given zero old value" err &&
858 + git rev-parse $m >expect &&
859 + git rev-parse $a >actual &&
860 + test_cmp expect actual
861 +'
862 +
863 +test_expect_success 'stdin -z update symref works option no-deref' '
864 + git symbolic-ref TESTSYMREF $b &&
865 + printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
866 + git update-ref -z --stdin <stdin &&
867 + git rev-parse TESTSYMREF >expect &&
868 + git rev-parse $a >actual &&
869 + test_cmp expect actual &&
870 + git rev-parse $m~1 >expect &&
871 + git rev-parse $b >actual &&
872 + test_cmp expect actual
873 +'
874 +
875 +test_expect_success 'stdin -z delete symref works option no-deref' '
876 + git symbolic-ref TESTSYMREF $b &&
877 + printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
878 + git update-ref -z --stdin <stdin &&
879 + test_must_fail git rev-parse --verify -q TESTSYMREF &&
880 + git rev-parse $m~1 >expect &&
881 + git rev-parse $b >actual &&
882 + test_cmp expect actual
883 +'
884 +
885 +test_expect_success 'stdin -z delete ref works with right old value' '
886 + printf $F "delete $b" "$m~1" >stdin &&
887 + git update-ref -z --stdin <stdin &&
888 + test_must_fail git rev-parse --verify -q $b
889 +'
890 +
891 +test_expect_success 'stdin -z update/create/verify combination works' '
892 + printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
893 + git update-ref -z --stdin <stdin &&
894 + git rev-parse $m >expect &&
895 + git rev-parse $a >actual &&
896 + test_cmp expect actual &&
897 + git rev-parse $b >actual &&
898 + test_cmp expect actual &&
899 + test_must_fail git rev-parse --verify -q $c
900 +'
901 +
902 +test_expect_success 'stdin -z update refs works with identity updates' '
903 + printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
904 + git update-ref -z --stdin <stdin &&
905 + git rev-parse $m >expect &&
906 + git rev-parse $a >actual &&
907 + test_cmp expect actual &&
908 + git rev-parse $b >actual &&
909 + test_cmp expect actual &&
910 + test_must_fail git rev-parse --verify -q $c
911 +'
912 +
913 +test_expect_success 'stdin -z update refs fails with wrong old value' '
914 + git update-ref $c $m &&
915 + printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "" "$Z" >stdin &&
916 + test_must_fail git update-ref -z --stdin <stdin 2>err &&
917 + grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
918 + git rev-parse $m >expect &&
919 + git rev-parse $a >actual &&
920 + test_cmp expect actual &&
921 + git rev-parse $b >actual &&
922 + test_cmp expect actual &&
923 + git rev-parse $c >actual &&
924 + test_cmp expect actual
925 +'
926 +
927 +test_expect_success 'stdin -z delete refs works with packed and loose refs' '
928 + git pack-refs --all &&
929 + git update-ref $c $m~1 &&
930 + printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
931 + git update-ref -z --stdin <stdin &&
932 + test_must_fail git rev-parse --verify -q $a &&
933 + test_must_fail git rev-parse --verify -q $b &&
934 + test_must_fail git rev-parse --verify -q $c
935 +'
936 +
937 test_done