1639
test_cmp expect actual
1640
'
1641
1642
+test_expect_success REFFILES "FETCH_HEAD is updated even if ref updates fail" '
1643
+ test_when_finished rm -rf base repo &&
1644
+
1645
+ git init base &&
1646
+ (
1647
+ cd base &&
1648
+ test_commit "updated" &&
1649
+
1650
+ git update-ref refs/heads/foo @ &&
1651
+ git update-ref refs/heads/branch @
1652
+ ) &&
1653
+
1654
+ git init --bare repo &&
1655
+ (
1656
+ cd repo &&
1657
+ rm -f FETCH_HEAD &&
1658
+ git remote add origin ../base &&
1659
+ >refs/heads/foo.lock &&
1660
+ test_must_fail git fetch -f origin "refs/heads/*:refs/heads/*" 2>err &&
1661
+ test_grep "error: fetching ref refs/heads/foo failed: reference already exists" err &&
1662
+ test_grep "branch ${SQ}branch${SQ} of ../base" FETCH_HEAD &&
1663
+ test_grep "branch ${SQ}foo${SQ} of ../base" FETCH_HEAD
1664
+ )
1665
+'
1666
+
1667
+test_expect_success "upstream tracking info is added with --set-upstream" '
1668
+ test_when_finished rm -rf base repo &&
1669
+
1670
+ git init --initial-branch=main base &&
1671
+ test_commit -C base "updated" &&
1672
+
1673
+ git init --bare --initial-branch=main repo &&
1674
+ (
1675
+ cd repo &&
1676
+ git remote add origin ../base &&
1677
+ git fetch origin --set-upstream main &&
1678
+ git config get branch.main.remote >actual &&
1679
+ echo "origin" >expect &&
1680
+ test_cmp expect actual
1681
+ )
1682
+'
1683
+
1684
+test_expect_success REFFILES "upstream tracking info is added even with conflicts" '
1685
+ test_when_finished rm -rf base repo &&
1686
+
1687
+ git init --initial-branch=main base &&
1688
+ test_commit -C base "updated" &&
1689
+
1690
+ git init --bare --initial-branch=main repo &&
1691
+ (
1692
+ cd repo &&
1693
+ git remote add origin ../base &&
1694
+ test_must_fail git config get branch.main.remote &&
1695
+
1696
+ mkdir -p refs/remotes/origin &&
1697
+ >refs/remotes/origin/main.lock &&
1698
+ test_must_fail git fetch origin --set-upstream main &&
1699
+ git config get branch.main.remote >actual &&
1700
+ echo "origin" >expect &&
1701
+ test_cmp expect actual
1702
+ )
1703
+'
1704
+
1705
+test_expect_success REFFILES "HEAD is updated even with conflicts" '
1706
+ test_when_finished rm -rf base repo &&
1707
+
1708
+ git init base &&
1709
+ (
1710
+ cd base &&
1711
+ test_commit "updated" &&
1712
+
1713
+ git update-ref refs/heads/foo @ &&
1714
+ git update-ref refs/heads/branch @
1715
+ ) &&
1716
+
1717
+ git init --bare repo &&
1718
+ (
1719
+ cd repo &&
1720
+ git remote add origin ../base &&
1721
+
1722
+ test_path_is_missing refs/remotes/origin/HEAD &&
1723
+ mkdir -p refs/remotes/origin &&
1724
+ >refs/remotes/origin/branch.lock &&
1725
+ test_must_fail git fetch origin &&
1726
+ test -f refs/remotes/origin/HEAD
1727
+ )
1728
+'
1729
+
1730
. "$TEST_DIRECTORY"/lib-httpd.sh
1731
start_httpd
1732