diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index 48552e6a9e..702ec1f128 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -298,16 +298,19 @@ static int cmd_update_ref(struct ref_store *refs, const char **argv) const char *new_sha1_buf = notnull(*argv++, "new-sha1"); const char *old_sha1_buf = notnull(*argv++, "old-sha1"); unsigned int flags = arg_flags(*argv++, "flags", transaction_flags); - struct object_id old_oid; + struct object_id old_oid, *old_oid_ptr = NULL; struct object_id new_oid; - if (get_oid_hex(old_sha1_buf, &old_oid)) - die("cannot parse %s as %s", old_sha1_buf, the_hash_algo->name); + if (*old_sha1_buf) { + if (get_oid_hex(old_sha1_buf, &old_oid)) + die("cannot parse %s as %s", old_sha1_buf, the_hash_algo->name); + old_oid_ptr = &old_oid; + } if (get_oid_hex(new_sha1_buf, &new_oid)) die("cannot parse %s as %s", new_sha1_buf, the_hash_algo->name); return refs_update_ref(refs, msg, refname, - &new_oid, &old_oid, + &new_oid, old_oid_ptr, flags, UPDATE_REFS_DIE_ON_ERR); } diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 9ac4b7036b..6d1810c358 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -9,8 +9,6 @@ test_description='Test git update-ref and basic ref logging' Z=$ZERO_OID m=refs/heads/main -n_dir=refs/heads/gu -n=$n_dir/fixes outside=refs/foo bare=bare-repo @@ -62,10 +60,10 @@ test_expect_success "delete $m without oldvalue verification" ' test_must_fail git show-ref --verify -q $m ' -test_expect_success "fail to create $n" ' - test_when_finished "rm -f .git/$n_dir" && - touch .git/$n_dir && - test_must_fail git update-ref $n $A +test_expect_success "fail to create $n due to file/directory conflict" ' + test_when_finished "git update-ref -d refs/heads/gu" && + git update-ref refs/heads/gu $A && + test_must_fail git update-ref refs/heads/gu/fixes $A ' test_expect_success "create $m (by HEAD)" ' @@ -92,7 +90,8 @@ test_expect_success "deleting current branch adds message to HEAD's log" ' git symbolic-ref HEAD $m && git update-ref -m delete-$m -d $m && test_must_fail git show-ref --verify -q $m && - grep "delete-$m$" .git/logs/HEAD + test-tool ref-store main for-each-reflog-ent HEAD >actual && + grep "delete-$m$" actual ' test_expect_success "deleting by HEAD adds message to HEAD's log" ' @@ -101,7 +100,8 @@ test_expect_success "deleting by HEAD adds message to HEAD's log" ' git symbolic-ref HEAD $m && git update-ref -m delete-by-head -d HEAD && test_must_fail git show-ref --verify -q $m && - grep "delete-by-head$" .git/logs/HEAD + test-tool ref-store main for-each-reflog-ent HEAD >actual && + grep "delete-by-head$" actual ' test_expect_success 'update-ref does not create reflogs by default' ' @@ -132,7 +132,7 @@ test_expect_success 'creates no reflog in bare repository' ' test_expect_success 'core.logAllRefUpdates=true creates reflog in bare repository' ' test_when_finished "git -C $bare config --unset core.logAllRefUpdates && \ - rm $bare/logs/$m" && + test-tool ref-store main delete-reflog $m" && git -C $bare config core.logAllRefUpdates true && git -C $bare update-ref $m $bareB && git -C $bare rev-parse $bareB >expect && @@ -221,27 +221,27 @@ test_expect_success 'delete symref without dereference when the referred ref is ' test_expect_success 'update-ref -d is not confused by self-reference' ' + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" && git symbolic-ref refs/heads/self refs/heads/self && - test_when_finished "rm -f .git/refs/heads/self" && - test_path_is_file .git/refs/heads/self && + git symbolic-ref --no-recurse refs/heads/self && test_must_fail git update-ref -d refs/heads/self && - test_path_is_file .git/refs/heads/self + git symbolic-ref --no-recurse refs/heads/self ' test_expect_success 'update-ref --no-deref -d can delete self-reference' ' + test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" && git symbolic-ref refs/heads/self refs/heads/self && - test_when_finished "rm -f .git/refs/heads/self" && - test_path_is_file .git/refs/heads/self && + git symbolic-ref --no-recurse refs/heads/self && git update-ref --no-deref -d refs/heads/self && test_must_fail git show-ref --verify -q refs/heads/self ' -test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' ' +test_expect_success REFFILES 'update-ref --no-deref -d can delete reference to bad ref' ' >.git/refs/heads/bad && test_when_finished "rm -f .git/refs/heads/bad" && git symbolic-ref refs/heads/ref-to-bad refs/heads/bad && test_when_finished "git update-ref -d refs/heads/ref-to-bad" && - test_path_is_file .git/refs/heads/ref-to-bad && + git symbolic-ref --no-recurse refs/heads/ref-to-bad && git update-ref --no-deref -d refs/heads/ref-to-bad && test_must_fail git show-ref --verify -q refs/heads/ref-to-bad ' @@ -265,7 +265,10 @@ test_expect_success "(not) changed .git/$m" ' ! test $B = $(git show-ref -s --verify $m) ' -rm -f .git/logs/refs/heads/main +test_expect_success "clean up reflog" ' + test-tool ref-store main delete-reflog $m +' + test_expect_success "create $m (logged by touch)" ' test_config core.logAllRefUpdates false && GIT_COMMITTER_DATE="2005-05-26 23:30" \ @@ -285,7 +288,7 @@ test_expect_success "set $m (logged by touch)" ' test $A = $(git show-ref -s --verify $m) ' -test_expect_success 'empty directory removal' ' +test_expect_success REFFILES 'empty directory removal' ' git branch d1/d2/r1 HEAD && git branch d1/r2 HEAD && test_path_is_file .git/refs/heads/d1/d2/r1 && @@ -297,7 +300,7 @@ test_expect_success 'empty directory removal' ' test_path_is_file .git/logs/refs/heads/d1/r2 ' -test_expect_success 'symref empty directory removal' ' +test_expect_success REFFILES 'symref empty directory removal' ' git branch e1/e2/r1 HEAD && git branch e1/r2 HEAD && git checkout e1/e2/r1 && @@ -318,7 +321,7 @@ $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 EOF test_expect_success "verifying $m's log (logged by touch)" ' - test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" && + test_when_finished "git update-ref -d $m && git reflog expire --expire=all --all && rm -rf actual expect" && test-tool ref-store main for-each-reflog-ent $m >actual && test_cmp actual expect ' @@ -348,7 +351,7 @@ $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000 EOF test_expect_success "verifying $m's log (logged by config)" ' - test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" && + test_when_finished "git update-ref -d $m && git reflog expire --expire=all --all && rm -rf actual expect" && test-tool ref-store main for-each-reflog-ent $m >actual && test_cmp actual expect ' @@ -434,7 +437,8 @@ test_expect_success 'Query "main@{2005-05-28}" (past end of history)' ' test_grep -F "warning: log for ref $m unexpectedly ended on $ld" e ' -rm -f .git/$m .git/logs/$m expect +rm -f expect +git update-ref -d $m test_expect_success 'creating initial files' ' test_when_finished rm -f M && @@ -1635,7 +1639,7 @@ test_expect_success PIPE 'transaction flushes status updates' ' test_cmp expected actual ' -test_expect_success 'directory not created deleting packed ref' ' +test_expect_success REFFILES 'directory not created deleting packed ref' ' git branch d1/d2/r1 HEAD && git pack-refs --all && test_path_is_missing .git/refs/heads/d1/d2 && diff --git a/t/t1430-bad-ref-name.sh b/t/t1430-bad-ref-name.sh index 68cc9e73d0..0c00118c2b 100755 --- a/t/t1430-bad-ref-name.sh +++ b/t/t1430-bad-ref-name.sh @@ -164,9 +164,9 @@ test_expect_success 'rev-parse skips symref pointing to broken name' ' test_expect_success 'for-each-ref emits warnings for broken names' ' test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" && - printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname && + test-tool ref-store main create-symref refs/heads/badname refs/heads/broken...ref && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" && - printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref && + test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/main && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && git for-each-ref >output 2>error && ! grep -e "broken\.\.\.ref" output && @@ -257,7 +257,7 @@ test_expect_success 'update-ref -d can delete broken name through symref' ' ' test_expect_success 'update-ref --no-deref -d can delete symref with broken name' ' - printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref && + test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/main && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && test_ref_exists refs/heads/broken...symref && git update-ref --no-deref -d refs/heads/broken...symref >output 2>error && @@ -267,7 +267,7 @@ test_expect_success 'update-ref --no-deref -d can delete symref with broken name ' test_expect_success 'branch -d can delete symref with broken name' ' - printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref && + test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/main && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && test_ref_exists refs/heads/broken...symref && git branch -d broken...symref >output 2>error && @@ -277,7 +277,7 @@ test_expect_success 'branch -d can delete symref with broken name' ' ' test_expect_success 'update-ref --no-deref -d can delete dangling symref with broken name' ' - printf "ref: refs/heads/idonotexist\n" >.git/refs/heads/broken...symref && + test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/idonotexist && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && test_ref_exists refs/heads/broken...symref && git update-ref --no-deref -d refs/heads/broken...symref >output 2>error && @@ -287,7 +287,7 @@ test_expect_success 'update-ref --no-deref -d can delete dangling symref with br ' test_expect_success 'branch -d can delete dangling symref with broken name' ' - printf "ref: refs/heads/idonotexist\n" >.git/refs/heads/broken...symref && + test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/idonotexist && test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && test_ref_exists refs/heads/broken...symref && git branch -d broken...symref >output 2>error && diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 0e3e87d37a..8a456b1142 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -15,6 +15,7 @@ test_expect_success setup ' git config --unset i18n.commitencoding && git checkout HEAD^0 && test_commit B fileB two && + orig_head=$(git rev-parse HEAD) && git tag -d A B && git reflog expire --expire=now --all ' @@ -115,15 +116,15 @@ test_expect_success 'zlib corrupt loose object output ' ' ' test_expect_success 'branch pointing to non-commit' ' - git rev-parse HEAD^{tree} >.git/refs/heads/invalid && + tree_oid=$(git rev-parse --verify HEAD^{tree}) && test_when_finished "git update-ref -d refs/heads/invalid" && + test-tool ref-store main update-ref msg refs/heads/invalid $tree_oid $ZERO_OID REF_SKIP_OID_VERIFICATION && test_must_fail git fsck 2>out && test_grep "not a commit" out ' -test_expect_success 'HEAD link pointing at a funny object' ' - test_when_finished "mv .git/SAVED_HEAD .git/HEAD" && - mv .git/HEAD .git/SAVED_HEAD && +test_expect_success REFFILES 'HEAD link pointing at a funny object' ' + test_when_finished "git update-ref HEAD $orig_head" && echo $ZERO_OID >.git/HEAD && # avoid corrupt/broken HEAD from interfering with repo discovery test_must_fail env GIT_DIR=.git git fsck 2>out && @@ -131,27 +132,25 @@ test_expect_success 'HEAD link pointing at a funny object' ' ' test_expect_success 'HEAD link pointing at a funny place' ' - test_when_finished "mv .git/SAVED_HEAD .git/HEAD" && - mv .git/HEAD .git/SAVED_HEAD && - echo "ref: refs/funny/place" >.git/HEAD && + test_when_finished "git update-ref --no-deref HEAD $orig_head" && + test-tool ref-store main create-symref HEAD refs/funny/place && # avoid corrupt/broken HEAD from interfering with repo discovery test_must_fail env GIT_DIR=.git git fsck 2>out && test_grep "HEAD points to something strange" out ' -test_expect_success 'HEAD link pointing at a funny object (from different wt)' ' - test_when_finished "mv .git/SAVED_HEAD .git/HEAD" && - test_when_finished "rm -rf .git/worktrees wt" && +test_expect_success REFFILES 'HEAD link pointing at a funny object (from different wt)' ' + test_when_finished "git update-ref HEAD $orig_head" && + test_when_finished "git worktree remove -f wt" && git worktree add wt && - mv .git/HEAD .git/SAVED_HEAD && echo $ZERO_OID >.git/HEAD && # avoid corrupt/broken HEAD from interfering with repo discovery test_must_fail git -C wt fsck 2>out && test_grep "main-worktree/HEAD: detached HEAD points" out ' -test_expect_success 'other worktree HEAD link pointing at a funny object' ' - test_when_finished "rm -rf .git/worktrees other" && +test_expect_success REFFILES 'other worktree HEAD link pointing at a funny object' ' + test_when_finished "git worktree remove -f other" && git worktree add other && echo $ZERO_OID >.git/worktrees/other/HEAD && test_must_fail git fsck 2>out && @@ -159,17 +158,18 @@ test_expect_success 'other worktree HEAD link pointing at a funny object' ' ' test_expect_success 'other worktree HEAD link pointing at missing object' ' - test_when_finished "rm -rf .git/worktrees other" && + test_when_finished "git worktree remove -f other" && git worktree add other && - echo "Contents missing from repo" | git hash-object --stdin >.git/worktrees/other/HEAD && + object_id=$(echo "Contents missing from repo" | git hash-object --stdin) && + test-tool -C other ref-store main update-ref msg HEAD $object_id "" REF_NO_DEREF,REF_SKIP_OID_VERIFICATION && test_must_fail git fsck 2>out && test_grep "worktrees/other/HEAD: invalid sha1 pointer" out ' test_expect_success 'other worktree HEAD link pointing at a funny place' ' - test_when_finished "rm -rf .git/worktrees other" && + test_when_finished "git worktree remove -f other" && git worktree add other && - echo "ref: refs/funny/place" >.git/worktrees/other/HEAD && + git -C other symbolic-ref HEAD refs/funny/place && test_must_fail git fsck 2>out && test_grep "worktrees/other/HEAD points to something strange" out ' @@ -391,7 +391,7 @@ test_expect_success 'tag pointing to nonexistent' ' tag=$(git hash-object -t tag -w --stdin .git/refs/tags/invalid && + git update-ref refs/tags/invalid $tag && test_when_finished "git update-ref -d refs/tags/invalid" && test_must_fail git fsck --tags >out && test_grep "broken link" out @@ -411,7 +411,7 @@ test_expect_success 'tag pointing to something else than its type' ' tag=$(git hash-object -t tag -w --stdin .git/refs/tags/wrong && + git update-ref refs/tags/wrong $tag && test_when_finished "git update-ref -d refs/tags/wrong" && test_must_fail git fsck --tags ' @@ -428,7 +428,7 @@ test_expect_success 'tag with incorrect tag name & missing tagger' ' tag=$(git hash-object --literally -t tag -w --stdin .git/refs/tags/wrong && + git update-ref refs/tags/wrong $tag && test_when_finished "git update-ref -d refs/tags/wrong" && git fsck --tags 2>out && @@ -452,7 +452,7 @@ test_expect_success 'tag with bad tagger' ' tag=$(git hash-object --literally -t tag -w --stdin .git/refs/tags/wrong && + git update-ref refs/tags/wrong $tag && test_when_finished "git update-ref -d refs/tags/wrong" && test_must_fail git fsck --tags 2>out && test_grep "error in tag .*: invalid author/committer" out @@ -471,7 +471,7 @@ test_expect_success 'tag with NUL in header' ' tag=$(git hash-object --literally -t tag -w --stdin .git/refs/tags/wrong && + git update-ref refs/tags/wrong $tag && test_when_finished "git update-ref -d refs/tags/wrong" && test_must_fail git fsck --tags 2>out && test_grep "error in tag $tag.*unterminated header: NUL at offset" out diff --git a/t/t2011-checkout-invalid-head.sh b/t/t2011-checkout-invalid-head.sh index d9997e7b6b..3c8135831b 100755 --- a/t/t2011-checkout-invalid-head.sh +++ b/t/t2011-checkout-invalid-head.sh @@ -18,18 +18,18 @@ test_expect_success 'checkout should not start branch from a tree' ' test_must_fail git checkout -b newbranch main^{tree} ' -test_expect_success 'checkout main from invalid HEAD' ' +test_expect_success REFFILES 'checkout main from invalid HEAD' ' echo $ZERO_OID >.git/HEAD && git checkout main -- ' -test_expect_success 'checkout notices failure to lock HEAD' ' +test_expect_success REFFILES 'checkout notices failure to lock HEAD' ' test_when_finished "rm -f .git/HEAD.lock" && >.git/HEAD.lock && test_must_fail git checkout -b other ' -test_expect_success 'create ref directory/file conflict scenario' ' +test_expect_success REFFILES 'create ref directory/file conflict scenario' ' git update-ref refs/heads/outer/inner main && # do not rely on symbolic-ref to get a known state, @@ -39,26 +39,26 @@ test_expect_success 'create ref directory/file conflict scenario' ' } ' -test_expect_success 'checkout away from d/f HEAD (unpacked, to branch)' ' +test_expect_success REFFILES 'checkout away from d/f HEAD (unpacked, to branch)' ' reset_to_df && git checkout main ' -test_expect_success 'checkout away from d/f HEAD (unpacked, to detached)' ' +test_expect_success REFFILES 'checkout away from d/f HEAD (unpacked, to detached)' ' reset_to_df && git checkout --detach main ' -test_expect_success 'pack refs' ' +test_expect_success REFFILES 'pack refs' ' git pack-refs --all --prune ' -test_expect_success 'checkout away from d/f HEAD (packed, to branch)' ' +test_expect_success REFFILES 'checkout away from d/f HEAD (packed, to branch)' ' reset_to_df && git checkout main ' -test_expect_success 'checkout away from d/f HEAD (packed, to detached)' ' +test_expect_success REFFILES 'checkout away from d/f HEAD (packed, to detached)' ' reset_to_df && git checkout --detach main ' diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index c54fd9ea06..c7b4e49465 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -28,7 +28,7 @@ test_expect_success 'git branch --help should not have created a bogus branch' ' test_ref_missing refs/heads/--help ' -test_expect_success 'branch -h in broken repository' ' +test_expect_success REFFILES 'branch -h in broken repository' ' mkdir broken && ( cd broken && @@ -76,14 +76,14 @@ test_expect_success 'git branch HEAD should fail' ' ' cat >expect < 1117150200 +0000 branch: Created from main +$HEAD refs/heads/d/e/f@{0}: branch: Created from main EOF test_expect_success 'git branch --create-reflog d/e/f should create a branch and a log' ' GIT_COMMITTER_DATE="2005-05-26 23:30" \ git -c core.logallrefupdates=false branch --create-reflog d/e/f && test_ref_exists refs/heads/d/e/f && - test_path_is_file .git/logs/refs/heads/d/e/f && - test_cmp expect .git/logs/refs/heads/d/e/f + git reflog show --no-abbrev-commit refs/heads/d/e/f >actual && + test_cmp expect actual ' test_expect_success 'git branch -d d/e/f should delete a branch and a log' ' @@ -203,10 +203,9 @@ test_expect_success 'git branch -M baz bam should succeed when baz is checked ou test $(git rev-parse --abbrev-ref HEAD) = bam ' -test_expect_success 'git branch -M baz bam should add entries to .git/logs/HEAD' ' - msg="Branch: renamed refs/heads/baz to refs/heads/bam" && - grep " $ZERO_OID.*$msg$" .git/logs/HEAD && - grep "^$ZERO_OID.*$msg$" .git/logs/HEAD +test_expect_success 'git branch -M baz bam should add entries to HEAD reflog' ' + git reflog show HEAD >actual && + grep "HEAD@{0}: Branch: renamed refs/heads/baz to refs/heads/bam" actual ' test_expect_success 'git branch -M should leave orphaned HEAD alone' ' @@ -215,17 +214,20 @@ test_expect_success 'git branch -M should leave orphaned HEAD alone' ' cd orphan && test_commit initial && git checkout --orphan lonely && - grep lonely .git/HEAD && + git symbolic-ref HEAD >expect && + echo refs/heads/lonely >actual && + test_cmp expect actual && test_ref_missing refs/head/lonely && git branch -M main mistress && - grep lonely .git/HEAD + git symbolic-ref HEAD >expect && + test_cmp expect actual ) ' test_expect_success 'resulting reflog can be shown by log -g' ' oid=$(git rev-parse HEAD) && cat >expect <<-EOF && - HEAD@{0} $oid $msg + HEAD@{0} $oid Branch: renamed refs/heads/baz to refs/heads/bam HEAD@{2} $oid checkout: moving from foo to baz EOF git log -g --format="%gd %H %gs" -2 HEAD >actual && @@ -243,7 +245,7 @@ test_expect_success 'git branch -M baz bam should succeed when baz is checked ou git worktree prune ' -test_expect_success 'git branch -M fails if updating any linked working tree fails' ' +test_expect_success REFFILES 'git branch -M fails if updating any linked working tree fails' ' git worktree add -b baz bazdir1 && git worktree add -f bazdir2 baz && touch .git/worktrees/bazdir1/HEAD.lock && @@ -699,7 +701,8 @@ test_expect_success 'git branch -C c1 c2 should succeed when c1 is checked out' test_expect_success 'git branch -C c1 c2 should never touch HEAD' ' msg="Branch: copied refs/heads/c1 to refs/heads/c2" && - ! grep "$msg$" .git/logs/HEAD + git reflog HEAD >actual && + ! grep "$msg$" actual ' test_expect_success 'git branch -C main should work when main is checked out' ' @@ -809,7 +812,7 @@ test_expect_success 'deleting a symref' ' test_expect_success 'deleting a dangling symref' ' git symbolic-ref refs/heads/dangling-symref nowhere && - test_path_is_file .git/refs/heads/dangling-symref && + git symbolic-ref --no-recurse refs/heads/dangling-symref && echo "Deleted branch dangling-symref (was nowhere)." >expect && git branch -d dangling-symref >actual && test_ref_missing refs/heads/dangling-symref && @@ -833,14 +836,14 @@ test_expect_success 'renaming a symref is not allowed' ' test_ref_missing refs/heads/new-topic ' -test_expect_success SYMLINKS 'git branch -m u v should fail when the reflog for u is a symlink' ' +test_expect_success SYMLINKS,REFFILES 'git branch -m u v should fail when the reflog for u is a symlink' ' git branch --create-reflog u && mv .git/logs/refs/heads/u real-u && ln -s real-u .git/logs/refs/heads/u && test_must_fail git branch -m u v ' -test_expect_success SYMLINKS 'git branch -m with symlinked .git/refs' ' +test_expect_success SYMLINKS,REFFILES 'git branch -m with symlinked .git/refs' ' test_when_finished "rm -rf subdir" && git init --bare subdir && @@ -1140,14 +1143,14 @@ test_expect_success '--set-upstream-to notices an error to set branch as own ups # Keep this test last, as it changes the current branch cat >expect < 1117150200 +0000 branch: Created from main +$HEAD refs/heads/g/h/i@{0}: branch: Created from main EOF test_expect_success 'git checkout -b g/h/i -l should create a branch and a log' ' GIT_COMMITTER_DATE="2005-05-26 23:30" \ git checkout -b g/h/i -l main && test_ref_exists refs/heads/g/h/i && - test_path_is_file .git/logs/refs/heads/g/h/i && - test_cmp expect .git/logs/refs/heads/g/h/i + git reflog show --no-abbrev-commit refs/heads/g/h/i >actual && + test_cmp expect actual ' test_expect_success 'checkout -b makes reflog by default' ' diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index 24a539c662..57f1392926 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -424,7 +424,7 @@ test_expect_success 'refuse to switch to branch checked out elsewhere' ' test_grep "already used by worktree at" err ' -test_expect_success MINGW,SYMLINKS_WINDOWS 'rebase when .git/logs is a symlink' ' +test_expect_success REFFILES,MINGW,SYMLINKS_WINDOWS 'rebase when .git/logs is a symlink' ' git checkout main && mv .git/logs actual_logs && cmd //c "mklink /D .git\logs ..\actual_logs" && diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index c5f30554c6..64b641002e 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -2160,7 +2160,7 @@ test_expect_success '--update-refs: check failed ref update' ' # recorded in the update-refs file. We will force-update the # "second" ref, but "git branch -f" will not work because of # the lock in the update-refs file. - git rev-parse third >.git/refs/heads/second && + git update-ref refs/heads/second third && test_must_fail git rebase --continue 2>err && grep "update_ref failed for ref '\''refs/heads/second'\''" err && diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 5cc17c2e0d..c4d508e00a 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -522,7 +522,7 @@ test_expect_success 'log -S requires an argument' ' ' test_expect_success 'diff --cached on unborn branch' ' - echo ref: refs/heads/unborn >.git/HEAD && + git symbolic-ref HEAD refs/heads/unborn && git diff --cached >result && process_diffs result >actual && process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected && diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 708636671a..ddd205f98a 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -2265,7 +2265,7 @@ test_expect_success REFFILES 'log diagnoses bogus HEAD hash' ' test_expect_success REFFILES 'log diagnoses bogus HEAD symref' ' git init empty && - echo "ref: refs/heads/invalid.lock" > empty/.git/HEAD && + test-tool -C empty ref-store main create-symref HEAD refs/heads/invalid.lock && test_must_fail git -C empty log 2>stderr && test_grep broken stderr && test_must_fail git -C empty log --default totally-bogus 2>stderr && diff --git a/t/t4207-log-decoration-colors.sh b/t/t4207-log-decoration-colors.sh index 21986a866d..73ea9e5155 100755 --- a/t/t4207-log-decoration-colors.sh +++ b/t/t4207-log-decoration-colors.sh @@ -70,8 +70,14 @@ ${c_tag}tag: ${c_reset}${c_tag}A${c_reset}${c_commit})${c_reset} A cmp_filtered_decorations ' +remove_replace_refs () { + git for-each-ref 'refs/replace*/**' --format='delete %(refname)' >in && + git update-ref --stdin a.git/HEAD && + git -C a.git symbolic-ref HEAD refs/heads/nonexistent && git clone a d && (cd d && git fetch && @@ -157,7 +157,7 @@ test_expect_success 'cloning locally respects "-u" for fetching refs' ' test_must_fail git clone --bare -u false a should_not_work.git ' -test_expect_success 'local clone from repo with corrupt refs fails gracefully' ' +test_expect_success REFFILES 'local clone from repo with corrupt refs fails gracefully' ' git init corrupt && test_commit -C corrupt one && echo a >corrupt/.git/refs/heads/topic && diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh index 3c0c6047d5..6ef4971845 100755 --- a/t/t5702-protocol-v2.sh +++ b/t/t5702-protocol-v2.sh @@ -221,7 +221,9 @@ test_expect_success 'clone of empty repo propagates name of default branch' ' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ git -c init.defaultBranch=main -c protocol.version=2 \ clone "file://$(pwd)/file_empty_parent" file_empty_child && - grep "refs/heads/mydefaultbranch" file_empty_child/.git/HEAD + echo refs/heads/mydefaultbranch >expect && + git -C file_empty_child symbolic-ref HEAD >actual && + test_cmp expect actual ' test_expect_success '...but not if explicitly forbidden by config' ' @@ -234,7 +236,9 @@ test_expect_success '...but not if explicitly forbidden by config' ' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ git -c init.defaultBranch=main -c protocol.version=2 \ clone "file://$(pwd)/file_empty_parent" file_empty_child && - ! grep "refs/heads/mydefaultbranch" file_empty_child/.git/HEAD + echo refs/heads/main >expect && + git -C file_empty_child symbolic-ref HEAD >actual && + test_cmp expect actual ' test_expect_success 'bare clone propagates empty default branch' ' @@ -247,7 +251,9 @@ test_expect_success 'bare clone propagates empty default branch' ' git -c init.defaultBranch=main -c protocol.version=2 \ clone --bare \ "file://$(pwd)/file_empty_parent" file_empty_child.git && - grep "refs/heads/mydefaultbranch" file_empty_child.git/HEAD + echo "refs/heads/mydefaultbranch" >expect && + git -C file_empty_child.git symbolic-ref HEAD >actual && + test_cmp expect actual ' test_expect_success 'clone propagates unborn HEAD from non-empty repo' ' @@ -265,7 +271,9 @@ test_expect_success 'clone propagates unborn HEAD from non-empty repo' ' git -c init.defaultBranch=main -c protocol.version=2 \ clone "file://$(pwd)/file_unborn_parent" \ file_unborn_child 2>stderr && - grep "refs/heads/mydefaultbranch" file_unborn_child/.git/HEAD && + echo "refs/heads/mydefaultbranch" >expect && + git -C file_unborn_child symbolic-ref HEAD >actual && + test_cmp expect actual && grep "warning: remote HEAD refers to nonexistent ref" stderr ' @@ -295,7 +303,9 @@ test_expect_success 'bare clone propagates unborn HEAD from non-empty repo' ' git -c init.defaultBranch=main -c protocol.version=2 \ clone --bare "file://$(pwd)/file_unborn_parent" \ file_unborn_child.git 2>stderr && - grep "refs/heads/mydefaultbranch" file_unborn_child.git/HEAD && + echo "refs/heads/mydefaultbranch" >expect && + git -C file_unborn_child.git symbolic-ref HEAD >actual && + test_cmp expect actual && ! grep "warning:" stderr ' @@ -315,7 +325,9 @@ test_expect_success 'defaulted HEAD uses remote branch if available' ' git -c init.defaultBranch=branchwithstuff -c protocol.version=2 \ clone "file://$(pwd)/file_unborn_parent" \ file_unborn_child 2>stderr && - grep "refs/heads/branchwithstuff" file_unborn_child/.git/HEAD && + echo "refs/heads/branchwithstuff" >expect && + git -C file_unborn_child symbolic-ref HEAD >actual && + test_cmp expect actual && test_path_is_file file_unborn_child/stuff.t && ! grep "warning:" stderr ' diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 1a310a45fd..611b3dd3ae 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -517,8 +517,12 @@ test_expect_success 'nested (empty) git should be kept' ' git init empty_repo && mkdir to_clean && >to_clean/should_clean.this && + # Note that we put the expect file in the .git directory so that it + # does not get cleaned. + find empty_repo | sort >.git/expect && git clean -f -d && - test_path_is_file empty_repo/.git/HEAD && + find empty_repo | sort >actual && + test_cmp .git/expect actual && test_path_is_missing to_clean ' @@ -559,10 +563,10 @@ test_expect_success 'giving path in nested git work tree will NOT remove it' ' mkdir -p bar/baz && test_commit msg bar/baz/hello.world ) && + find repo | sort >expect && git clean -f -d repo/bar/baz && - test_path_is_file repo/.git/HEAD && - test_path_is_dir repo/bar/ && - test_path_is_file repo/bar/baz/hello.world + find repo | sort >actual && + test_cmp expect actual ' test_expect_success 'giving path to nested .git will not remove it' ' @@ -573,10 +577,10 @@ test_expect_success 'giving path to nested .git will not remove it' ' git init && test_commit msg hello.world ) && + find repo | sort >expect && git clean -f -d repo/.git && - test_path_is_file repo/.git/HEAD && - test_path_is_dir repo/.git/refs && - test_path_is_dir repo/.git/objects && + find repo | sort >actual && + test_cmp expect actual && test_path_is_dir untracked/ ' @@ -588,9 +592,10 @@ test_expect_success 'giving path to nested .git/ will NOT remove contents' ' git init && test_commit msg hello.world ) && + find repo | sort >expect && git clean -f -d repo/.git/ && - test_path_is_dir repo/.git && - test_path_is_file repo/.git/HEAD && + find repo | sort >actual && + test_cmp expect actual && test_path_is_dir untracked/ ' diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 935df6a1db..00d29871e6 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -157,7 +157,8 @@ test_expect_success 'prefetch multiple remotes' ' fetchargs="--prefetch --prune --no-tags --no-write-fetch-head --recurse-submodules=no --quiet" && test_subcommand git fetch remote1 $fetchargs actual && + test_must_be_empty actual && git log prefetch/remotes/remote1/one && git log prefetch/remotes/remote2/two && git fetch --all && diff --git a/t/t9133-git-svn-nested-git-repo.sh b/t/t9133-git-svn-nested-git-repo.sh index d8d536269c..8ca24670ac 100755 --- a/t/t9133-git-svn-nested-git-repo.sh +++ b/t/t9133-git-svn-nested-git-repo.sh @@ -11,7 +11,7 @@ test_expect_success 'setup repo with a git repo inside it' ' ( cd s && git init && - test -f .git/HEAD && + git symbolic-ref HEAD && > .git/a && echo a > a && svn_cmd add .git a &&