@@ -1360,6 +1360,7 @@ test_expect_success 'fails with duplicate HEAD update' '
1360
1360
'
1361
1361
1362
1362
test_expect_success ' fails with duplicate ref update via symref' '
1363
+ test_when_finished "git symbolic-ref -d refs/heads/symref2" &&
1363
1364
git branch target2 $A &&
1364
1365
git symbolic-ref refs/heads/symref2 refs/heads/target2 &&
1365
1366
cat >stdin <<-EOF &&
@@ -1862,6 +1863,208 @@ do
1862
1863
git reflog exists refs/heads/symref
1863
1864
'
1864
1865
1866
+ test_expect_success " stdin $type symref-update fails with too many arguments" '
1867
+ format_command $type "symref-update refs/heads/symref" "$a" "ref" "$a" "$a" >stdin &&
1868
+ test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1869
+ if test "$type" = "-z"
1870
+ then
1871
+ grep "fatal: unknown command: $a" err
1872
+ else
1873
+ grep "fatal: symref-update refs/heads/symref: extra input: $a" err
1874
+ fi
1875
+ '
1876
+
1877
+ test_expect_success " stdin $type symref-update fails with wrong old value argument" '
1878
+ format_command $type "symref-update refs/heads/symref" "$a" "foo" "$a" "$a" >stdin &&
1879
+ test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1880
+ grep "fatal: symref-update refs/heads/symref: invalid arg ${SQ}foo${SQ} for old value" err
1881
+ '
1882
+
1883
+ test_expect_success " stdin $type symref-update creates with zero old value" '
1884
+ test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1885
+ format_command $type "symref-update refs/heads/symref" "$a" "oid" "$Z" >stdin &&
1886
+ git update-ref --stdin $type --no-deref <stdin &&
1887
+ echo $a >expect &&
1888
+ git symbolic-ref refs/heads/symref >actual &&
1889
+ test_cmp expect actual
1890
+ '
1891
+
1892
+ test_expect_success " stdin $type symref-update creates with no old value" '
1893
+ test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1894
+ format_command $type "symref-update refs/heads/symref" "$a" >stdin &&
1895
+ git update-ref --stdin $type --no-deref <stdin &&
1896
+ echo $a >expect &&
1897
+ git symbolic-ref refs/heads/symref >actual &&
1898
+ test_cmp expect actual
1899
+ '
1900
+
1901
+ test_expect_success " stdin $type symref-update creates dangling" '
1902
+ test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1903
+ test_must_fail git rev-parse refs/heads/nonexistent &&
1904
+ format_command $type "symref-update refs/heads/symref" "refs/heads/nonexistent" >stdin &&
1905
+ git update-ref --stdin $type --no-deref <stdin &&
1906
+ echo refs/heads/nonexistent >expect &&
1907
+ git symbolic-ref refs/heads/symref >actual &&
1908
+ test_cmp expect actual
1909
+ '
1910
+
1911
+ test_expect_success " stdin $type symref-update fails with wrong old value" '
1912
+ test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1913
+ git symbolic-ref refs/heads/symref $a &&
1914
+ format_command $type "symref-update refs/heads/symref" "$m" "ref" "$b" >stdin &&
1915
+ test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1916
+ grep "fatal: verifying symref target: ${SQ}refs/heads/symref${SQ}: is at $a but expected $b" err &&
1917
+ test_must_fail git rev-parse --verify -q $c
1918
+ '
1919
+
1920
+ test_expect_success " stdin $type symref-update updates dangling ref" '
1921
+ test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1922
+ test_must_fail git rev-parse refs/heads/nonexistent &&
1923
+ git symbolic-ref refs/heads/symref refs/heads/nonexistent &&
1924
+ format_command $type "symref-update refs/heads/symref" "$a" >stdin &&
1925
+ git update-ref --stdin $type --no-deref <stdin &&
1926
+ echo $a >expect &&
1927
+ git symbolic-ref refs/heads/symref >actual &&
1928
+ test_cmp expect actual
1929
+ '
1930
+
1931
+ test_expect_success " stdin $type symref-update updates dangling ref with old value" '
1932
+ test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1933
+ test_must_fail git rev-parse refs/heads/nonexistent &&
1934
+ git symbolic-ref refs/heads/symref refs/heads/nonexistent &&
1935
+ format_command $type "symref-update refs/heads/symref" "$a" "ref" "refs/heads/nonexistent" >stdin &&
1936
+ git update-ref --stdin $type --no-deref <stdin &&
1937
+ echo $a >expect &&
1938
+ git symbolic-ref refs/heads/symref >actual &&
1939
+ test_cmp expect actual
1940
+ '
1941
+
1942
+ test_expect_success " stdin $type symref-update fails update dangling ref with wrong old value" '
1943
+ test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1944
+ test_must_fail git rev-parse refs/heads/nonexistent &&
1945
+ git symbolic-ref refs/heads/symref refs/heads/nonexistent &&
1946
+ format_command $type "symref-update refs/heads/symref" "$a" "ref" "refs/heads/wrongref" >stdin &&
1947
+ test_must_fail git update-ref --stdin $type --no-deref <stdin &&
1948
+ echo refs/heads/nonexistent >expect &&
1949
+ git symbolic-ref refs/heads/symref >actual &&
1950
+ test_cmp expect actual
1951
+ '
1952
+
1953
+ test_expect_success " stdin $type symref-update works with right old value" '
1954
+ test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1955
+ git symbolic-ref refs/heads/symref $a &&
1956
+ format_command $type "symref-update refs/heads/symref" "$m" "ref" "$a" >stdin &&
1957
+ git update-ref --stdin $type --no-deref <stdin &&
1958
+ echo $m >expect &&
1959
+ git symbolic-ref refs/heads/symref >actual &&
1960
+ test_cmp expect actual
1961
+ '
1962
+
1963
+ test_expect_success " stdin $type symref-update works with no old value" '
1964
+ test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1965
+ git symbolic-ref refs/heads/symref $a &&
1966
+ format_command $type "symref-update refs/heads/symref" "$m" >stdin &&
1967
+ git update-ref --stdin $type --no-deref <stdin &&
1968
+ echo $m >expect &&
1969
+ git symbolic-ref refs/heads/symref >actual &&
1970
+ test_cmp expect actual
1971
+ '
1972
+
1973
+ test_expect_success " stdin $type symref-update fails with empty old ref-target" '
1974
+ test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1975
+ git symbolic-ref refs/heads/symref $a &&
1976
+ format_command $type "symref-update refs/heads/symref" "$m" "ref" "" >stdin &&
1977
+ test_must_fail git update-ref --stdin $type --no-deref <stdin &&
1978
+ echo $a >expect &&
1979
+ git symbolic-ref refs/heads/symref >actual &&
1980
+ test_cmp expect actual
1981
+ '
1982
+
1983
+ test_expect_success " stdin $type symref-update creates (with deref)" '
1984
+ test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1985
+ format_command $type "symref-update refs/heads/symref" "$a" >stdin &&
1986
+ git update-ref --stdin $type <stdin &&
1987
+ echo $a >expect &&
1988
+ git symbolic-ref --no-recurse refs/heads/symref >actual &&
1989
+ test_cmp expect actual &&
1990
+ test-tool ref-store main for-each-reflog-ent refs/heads/symref >actual &&
1991
+ grep "$Z $(git rev-parse $a)" actual
1992
+ '
1993
+
1994
+ test_expect_success " stdin $type symref-update regular ref to symref with correct old-oid" '
1995
+ test_when_finished "git symbolic-ref -d --no-recurse refs/heads/regularref" &&
1996
+ git update-ref --no-deref refs/heads/regularref $a &&
1997
+ format_command $type "symref-update refs/heads/regularref" "$a" "oid" "$(git rev-parse $a)" >stdin &&
1998
+ git update-ref --stdin $type <stdin &&
1999
+ echo $a >expect &&
2000
+ git symbolic-ref --no-recurse refs/heads/regularref >actual &&
2001
+ test_cmp expect actual &&
2002
+ test-tool ref-store main for-each-reflog-ent refs/heads/regularref >actual &&
2003
+ grep "$(git rev-parse $a) $(git rev-parse $a)" actual
2004
+ '
2005
+
2006
+ test_expect_success " stdin $type symref-update regular ref to symref fails with wrong old-oid" '
2007
+ test_when_finished "git update-ref -d refs/heads/regularref" &&
2008
+ git update-ref --no-deref refs/heads/regularref $a &&
2009
+ format_command $type "symref-update refs/heads/regularref" "$a" "oid" "$(git rev-parse refs/heads/target2)" >stdin &&
2010
+ test_must_fail git update-ref --stdin $type <stdin 2>err &&
2011
+ grep "fatal: cannot lock ref ${SQ}refs/heads/regularref${SQ}: is at $(git rev-parse $a) but expected $(git rev-parse refs/heads/target2)" err &&
2012
+ echo $(git rev-parse $a) >expect &&
2013
+ git rev-parse refs/heads/regularref >actual &&
2014
+ test_cmp expect actual
2015
+ '
2016
+
2017
+ test_expect_success " stdin $type symref-update regular ref to symref fails with invalid old-oid" '
2018
+ test_when_finished "git update-ref -d refs/heads/regularref" &&
2019
+ git update-ref --no-deref refs/heads/regularref $a &&
2020
+ format_command $type "symref-update refs/heads/regularref" "$a" "oid" "not-a-ref-oid" >stdin &&
2021
+ test_must_fail git update-ref --stdin $type <stdin 2>err &&
2022
+ grep "fatal: symref-update refs/heads/regularref: invalid oid: not-a-ref-oid" err &&
2023
+ echo $(git rev-parse $a) >expect &&
2024
+ git rev-parse refs/heads/regularref >actual &&
2025
+ test_cmp expect actual
2026
+ '
2027
+
2028
+ test_expect_success " stdin $type symref-update existing symref with zero old-oid" '
2029
+ test_when_finished "git symbolic-ref -d --no-recurse refs/heads/symref" &&
2030
+ git symbolic-ref refs/heads/symref refs/heads/target2 &&
2031
+ format_command $type "symref-update refs/heads/symref" "$a" "oid" "$Z" >stdin &&
2032
+ test_must_fail git update-ref --stdin $type <stdin 2>err &&
2033
+ grep "fatal: cannot lock ref ${SQ}refs/heads/symref${SQ}: reference already exists" err &&
2034
+ echo refs/heads/target2 >expect &&
2035
+ git symbolic-ref refs/heads/symref >actual &&
2036
+ test_cmp expect actual
2037
+ '
2038
+
2039
+ test_expect_success " stdin $type symref-update regular ref to symref (with deref)" '
2040
+ test_when_finished "git symbolic-ref -d refs/heads/symref" &&
2041
+ test_when_finished "git update-ref -d --no-deref refs/heads/symref2" &&
2042
+ git update-ref refs/heads/symref2 $a &&
2043
+ git symbolic-ref --no-recurse refs/heads/symref refs/heads/symref2 &&
2044
+ format_command $type "symref-update refs/heads/symref" "$a" >stdin &&
2045
+ git update-ref $type --stdin <stdin &&
2046
+ echo $a >expect &&
2047
+ git symbolic-ref --no-recurse refs/heads/symref2 >actual &&
2048
+ test_cmp expect actual &&
2049
+ echo refs/heads/symref2 >expect &&
2050
+ git symbolic-ref --no-recurse refs/heads/symref >actual &&
2051
+ test_cmp expect actual &&
2052
+ test-tool ref-store main for-each-reflog-ent refs/heads/symref >actual &&
2053
+ grep "$(git rev-parse $a) $(git rev-parse $a)" actual
2054
+ '
2055
+
2056
+ test_expect_success " stdin $type symref-update regular ref to symref" '
2057
+ test_when_finished "git symbolic-ref -d --no-recurse refs/heads/regularref" &&
2058
+ git update-ref --no-deref refs/heads/regularref $a &&
2059
+ format_command $type "symref-update refs/heads/regularref" "$a" >stdin &&
2060
+ git update-ref $type --stdin <stdin &&
2061
+ echo $a >expect &&
2062
+ git symbolic-ref --no-recurse refs/heads/regularref >actual &&
2063
+ test_cmp expect actual &&
2064
+ test-tool ref-store main for-each-reflog-ent refs/heads/regularref >actual &&
2065
+ grep "$(git rev-parse $a) $(git rev-parse $a)" actual
2066
+ '
2067
+
1865
2068
done
1866
2069
1867
2070
test_done
0 commit comments