1834
test_cmp_rev HEAD refs/heads/no-conflict-branch
1835
'
1836
1837
+test_expect_success 'respect user edits to update-ref steps' '
1838
+ git checkout -B update-refs-break no-conflict-branch &&
1839
+ git branch -f base HEAD~4 &&
1840
+ git branch -f first HEAD~3 &&
1841
+ git branch -f second HEAD~3 &&
1842
+ git branch -f third HEAD~1 &&
1843
+ git branch -f unseen base &&
1844
+
1845
+ # First, we will add breaks to the expected todo file
1846
+ cat >fake-todo-1 <<-EOF &&
1847
+ pick $(git rev-parse HEAD~3)
1848
+ break
1849
+ update-ref refs/heads/second
1850
+ update-ref refs/heads/first
1851
+
1852
+ pick $(git rev-parse HEAD~2)
1853
+ pick $(git rev-parse HEAD~1)
1854
+ update-ref refs/heads/third
1855
+
1856
+ pick $(git rev-parse HEAD)
1857
+ update-ref refs/heads/no-conflict-branch
1858
+ EOF
1859
+
1860
+ # Second, we will drop some update-refs commands (and move one)
1861
+ cat >fake-todo-2 <<-EOF &&
1862
+ update-ref refs/heads/second
1863
+
1864
+ pick $(git rev-parse HEAD~2)
1865
+ update-ref refs/heads/third
1866
+ pick $(git rev-parse HEAD~1)
1867
+ break
1868
+
1869
+ pick $(git rev-parse HEAD)
1870
+ EOF
1871
+
1872
+ # Third, we will:
1873
+ # * insert a new one (new-branch),
1874
+ # * re-add an old one (first), and
1875
+ # * add a second instance of a previously-stored one (second)
1876
+ cat >fake-todo-3 <<-EOF &&
1877
+ update-ref refs/heads/unseen
1878
+ update-ref refs/heads/new-branch
1879
+ pick $(git rev-parse HEAD)
1880
+ update-ref refs/heads/first
1881
+ update-ref refs/heads/second
1882
+ EOF
1883
+
1884
+ (
1885
+ set_replace_editor fake-todo-1 &&
1886
+ git rebase -i --update-refs primary &&
1887
+
1888
+ # These branches are currently locked.
1889
+ for b in first second third no-conflict-branch
1890
+ do
1891
+ test_must_fail git branch -f $b base || return 1
1892
+ done &&
1893
+
1894
+ set_replace_editor fake-todo-2 &&
1895
+ git rebase --edit-todo &&
1896
+
1897
+ # These branches are currently locked.
1898
+ for b in second third
1899
+ do
1900
+ test_must_fail git branch -f $b base || return 1
1901
+ done &&
1902
+
1903
+ # These branches are currently unlocked for checkout.
1904
+ for b in first no-conflict-branch
1905
+ do
1906
+ git worktree add wt-$b $b &&
1907
+ git worktree remove wt-$b || return 1
1908
+ done &&
1909
+
1910
+ git rebase --continue &&
1911
+
1912
+ set_replace_editor fake-todo-3 &&
1913
+ git rebase --edit-todo &&
1914
+
1915
+ # These branches are currently locked.
1916
+ for b in second third first unseen
1917
+ do
1918
+ test_must_fail git branch -f $b base || return 1
1919
+ done &&
1920
+
1921
+ # These branches are currently unlocked for checkout.
1922
+ for b in no-conflict-branch
1923
+ do
1924
+ git worktree add wt-$b $b &&
1925
+ git worktree remove wt-$b || return 1
1926
+ done &&
1927
+
1928
+ git rebase --continue
1929
+ ) &&
1930
+
1931
+ test_cmp_rev HEAD~2 refs/heads/third &&
1932
+ test_cmp_rev HEAD~1 refs/heads/unseen &&
1933
+ test_cmp_rev HEAD~1 refs/heads/new-branch &&
1934
+ test_cmp_rev HEAD refs/heads/first &&
1935
+ test_cmp_rev HEAD refs/heads/second &&
1936
+ test_cmp_rev HEAD refs/heads/no-conflict-branch
1937
+'
1938
+
1939
+test_expect_success '--update-refs: check failed ref update' '
1940
+ git checkout -B update-refs-error no-conflict-branch &&
1941
+ git branch -f base HEAD~4 &&
1942
+ git branch -f first HEAD~3 &&
1943
+ git branch -f second HEAD~2 &&
1944
+ git branch -f third HEAD~1 &&
1945
+
1946
+ cat >fake-todo <<-EOF &&
1947
+ pick $(git rev-parse HEAD~3)
1948
+ break
1949
+ update-ref refs/heads/first
1950
+
1951
+ pick $(git rev-parse HEAD~2)
1952
+ update-ref refs/heads/second
1953
+
1954
+ pick $(git rev-parse HEAD~1)
1955
+ update-ref refs/heads/third
1956
+
1957
+ pick $(git rev-parse HEAD)
1958
+ update-ref refs/heads/no-conflict-branch
1959
+ EOF
1960
+
1961
+ (
1962
+ set_replace_editor fake-todo &&
1963
+ git rebase -i --update-refs base
1964
+ ) &&
1965
+
1966
+ # At this point, the values of first, second, and third are
1967
+ # recorded in the update-refs file. We will force-update the
1968
+ # "second" ref, but "git branch -f" will not work because of
1969
+ # the lock in the update-refs file.
1970
+ git rev-parse third >.git/refs/heads/second &&
1971
+
1972
+ git rebase --continue 2>err &&
1973
+ grep "update_ref failed for ref '\''refs/heads/second'\''" err
1974
+'
1975
+
1976
# This must be the last test in this file
1977
test_expect_success '$EDITOR and friends are unchanged' '
1978
test_editor_unchanged