1729
test_cmp expect actual
1730
'
1731
1732
+ test_expect_success "stdin $type symref-delete fails without --no-deref" '
1733
+ git symbolic-ref refs/heads/symref $a &&
1734
+ format_command $type "symref-delete refs/heads/symref" "$a" >stdin &&
1735
+ test_must_fail git update-ref --stdin $type <stdin 2>err &&
1736
+ grep "fatal: symref-delete: cannot operate with deref mode" err
1737
+ '
1738
+
1739
+ test_expect_success "stdin $type symref-delete fails with no ref" '
1740
+ format_command $type "symref-delete " >stdin &&
1741
+ test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1742
+ grep "fatal: symref-delete: missing <ref>" err
1743
+ '
1744
+
1745
+ test_expect_success "stdin $type symref-delete fails deleting regular ref" '
1746
+ test_when_finished "git update-ref -d refs/heads/regularref" &&
1747
+ git update-ref refs/heads/regularref $a &&
1748
+ format_command $type "symref-delete refs/heads/regularref" "$a" >stdin &&
1749
+ test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1750
+ grep "fatal: cannot lock ref ${SQ}refs/heads/regularref${SQ}: expected symref with target ${SQ}$a${SQ}: but is a regular ref" err
1751
+ '
1752
+
1753
+ test_expect_success "stdin $type symref-delete fails with too many arguments" '
1754
+ format_command $type "symref-delete refs/heads/symref" "$a" "$a" >stdin &&
1755
+ test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1756
+ if test "$type" = "-z"
1757
+ then
1758
+ grep "fatal: unknown command: $a" err
1759
+ else
1760
+ grep "fatal: symref-delete refs/heads/symref: extra input: $a" err
1761
+ fi
1762
+ '
1763
+
1764
+ test_expect_success "stdin $type symref-delete fails with wrong old value" '
1765
+ format_command $type "symref-delete refs/heads/symref" "$m" >stdin &&
1766
+ test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1767
+ grep "fatal: verifying symref target: ${SQ}refs/heads/symref${SQ}: is at $a but expected refs/heads/main" err &&
1768
+ git symbolic-ref refs/heads/symref >expect &&
1769
+ echo $a >actual &&
1770
+ test_cmp expect actual
1771
+ '
1772
+
1773
+ test_expect_success "stdin $type symref-delete works with right old value" '
1774
+ format_command $type "symref-delete refs/heads/symref" "$a" >stdin &&
1775
+ git update-ref --stdin $type --no-deref <stdin &&
1776
+ test_must_fail git rev-parse --verify -q refs/heads/symref
1777
+ '
1778
+
1779
+ test_expect_success "stdin $type symref-delete works with empty old value" '
1780
+ git symbolic-ref refs/heads/symref $a >stdin &&
1781
+ format_command $type "symref-delete refs/heads/symref" "" >stdin &&
1782
+ git update-ref --stdin $type --no-deref <stdin &&
1783
+ test_must_fail git rev-parse --verify -q $b
1784
+ '
1785
+
1786
+ test_expect_success "stdin $type symref-delete succeeds for dangling reference" '
1787
+ test_must_fail git symbolic-ref refs/heads/nonexistent &&
1788
+ git symbolic-ref refs/heads/symref2 refs/heads/nonexistent &&
1789
+ format_command $type "symref-delete refs/heads/symref2" "refs/heads/nonexistent" >stdin &&
1790
+ git update-ref --stdin $type --no-deref <stdin &&
1791
+ test_must_fail git symbolic-ref -d refs/heads/symref2
1792
+ '
1793
+
1794
+ test_expect_success "stdin $type symref-delete deletes regular ref without target" '
1795
+ git update-ref refs/heads/regularref $a &&
1796
+ format_command $type "symref-delete refs/heads/regularref" >stdin &&
1797
+ git update-ref --stdin $type --no-deref <stdin
1798
+ '
1799
+
1800
done
1801
1802
test_done