test_cmp expect actual
'
+test_expect_success REFFILES "FETCH_HEAD is updated even if ref updates fail" '
+ test_when_finished rm -rf base repo &&
+
+ git init base &&
+ (
+ cd base &&
+ test_commit "updated" &&
+
+ git update-ref refs/heads/foo @ &&
+ git update-ref refs/heads/branch @
+ ) &&
+
+ git init --bare repo &&
+ (
+ cd repo &&
+ rm -f FETCH_HEAD &&
+ git remote add origin ../base &&
+ >refs/heads/foo.lock &&
+ test_must_fail git fetch -f origin "refs/heads/*:refs/heads/*" 2>err &&
+ test_grep "error: fetching ref refs/heads/foo failed: reference already exists" err &&
+ test_grep "branch ${SQ}branch${SQ} of ../base" FETCH_HEAD &&
+ test_grep "branch ${SQ}foo${SQ} of ../base" FETCH_HEAD
+ )
+'
+
+test_expect_success "upstream tracking info is added with --set-upstream" '
+ test_when_finished rm -rf base repo &&
+
+ git init --initial-branch=main base &&
+ test_commit -C base "updated" &&
+
+ git init --bare --initial-branch=main repo &&
+ (
+ cd repo &&
+ git remote add origin ../base &&
+ git fetch origin --set-upstream main &&
+ git config get branch.main.remote >actual &&
+ echo "origin" >expect &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success REFFILES "upstream tracking info is added even with conflicts" '
+ test_when_finished rm -rf base repo &&
+
+ git init --initial-branch=main base &&
+ test_commit -C base "updated" &&
+
+ git init --bare --initial-branch=main repo &&
+ (
+ cd repo &&
+ git remote add origin ../base &&
+ test_must_fail git config get branch.main.remote &&
+
+ mkdir -p refs/remotes/origin &&
+ >refs/remotes/origin/main.lock &&
+ test_must_fail git fetch origin --set-upstream main &&
+ git config get branch.main.remote >actual &&
+ echo "origin" >expect &&
+ test_cmp expect actual
+ )
+'
+
+test_expect_success REFFILES "HEAD is updated even with conflicts" '
+ test_when_finished rm -rf base repo &&
+
+ git init base &&
+ (
+ cd base &&
+ test_commit "updated" &&
+
+ git update-ref refs/heads/foo @ &&
+ git update-ref refs/heads/branch @
+ ) &&
+
+ git init --bare repo &&
+ (
+ cd repo &&
+ git remote add origin ../base &&
+
+ test_path_is_missing refs/remotes/origin/HEAD &&
+ mkdir -p refs/remotes/origin &&
+ >refs/remotes/origin/branch.lock &&
+ test_must_fail git fetch origin &&
+ test -f refs/remotes/origin/HEAD
+ )
+'
+
. "$TEST_DIRECTORY"/lib-httpd.sh
start_httpd