t: use update-ref and show-ref to reading/writing refs

Reading and writing .git/refs/* assumes that refs are stored in the 'files'
ref backend.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Han-Wen Nienhuys 2020-05-20 17:36:08 +00:00 committed by Junio C Hamano
parent d1eb22da09
commit cdb73ca56f
5 changed files with 21 additions and 21 deletions

View File

@ -62,7 +62,7 @@ test_expect_success 'check commit-tree' '
' '


test_expect_success 'check rev-list' ' test_expect_success 'check rev-list' '
echo $SHA >"$REAL/HEAD" && git update-ref "HEAD" "$SHA" &&
test "$SHA" = "$(git rev-list HEAD)" test "$SHA" = "$(git rev-list HEAD)"
' '



View File

@ -37,15 +37,15 @@ test_expect_success setup '


test_expect_success "create $m" ' test_expect_success "create $m" '
git update-ref $m $A && git update-ref $m $A &&
test $A = $(cat .git/$m) test $A = $(git show-ref -s --verify $m)
' '
test_expect_success "create $m with oldvalue verification" ' test_expect_success "create $m with oldvalue verification" '
git update-ref $m $B $A && git update-ref $m $B $A &&
test $B = $(cat .git/$m) test $B = $(git show-ref -s --verify $m)
' '
test_expect_success "fail to delete $m with stale ref" ' test_expect_success "fail to delete $m with stale ref" '
test_must_fail git update-ref -d $m $A && test_must_fail git update-ref -d $m $A &&
test $B = "$(cat .git/$m)" test $B = "$(git show-ref -s --verify $m)"
' '
test_expect_success "delete $m" ' test_expect_success "delete $m" '
test_when_finished "rm -f .git/$m" && test_when_finished "rm -f .git/$m" &&
@ -56,7 +56,7 @@ test_expect_success "delete $m" '
test_expect_success "delete $m without oldvalue verification" ' test_expect_success "delete $m without oldvalue verification" '
test_when_finished "rm -f .git/$m" && test_when_finished "rm -f .git/$m" &&
git update-ref $m $A && git update-ref $m $A &&
test $A = $(cat .git/$m) && test $A = $(git show-ref -s --verify $m) &&
git update-ref -d $m && git update-ref -d $m &&
test_path_is_missing .git/$m test_path_is_missing .git/$m
' '
@ -69,15 +69,15 @@ test_expect_success "fail to create $n" '


test_expect_success "create $m (by HEAD)" ' test_expect_success "create $m (by HEAD)" '
git update-ref HEAD $A && git update-ref HEAD $A &&
test $A = $(cat .git/$m) test $A = $(git show-ref -s --verify $m)
' '
test_expect_success "create $m (by HEAD) with oldvalue verification" ' test_expect_success "create $m (by HEAD) with oldvalue verification" '
git update-ref HEAD $B $A && git update-ref HEAD $B $A &&
test $B = $(cat .git/$m) test $B = $(git show-ref -s --verify $m)
' '
test_expect_success "fail to delete $m (by HEAD) with stale ref" ' test_expect_success "fail to delete $m (by HEAD) with stale ref" '
test_must_fail git update-ref -d HEAD $A && test_must_fail git update-ref -d HEAD $A &&
test $B = $(cat .git/$m) test $B = $(git show-ref -s --verify $m)
' '
test_expect_success "delete $m (by HEAD)" ' test_expect_success "delete $m (by HEAD)" '
test_when_finished "rm -f .git/$m" && test_when_finished "rm -f .git/$m" &&
@ -178,14 +178,14 @@ test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always'


test_expect_success "create $m (by HEAD)" ' test_expect_success "create $m (by HEAD)" '
git update-ref HEAD $A && git update-ref HEAD $A &&
test $A = $(cat .git/$m) test $A = $(git show-ref -s --verify $m)
' '
test_expect_success 'pack refs' ' test_expect_success 'pack refs' '
git pack-refs --all git pack-refs --all
' '
test_expect_success "move $m (by HEAD)" ' test_expect_success "move $m (by HEAD)" '
git update-ref HEAD $B $A && git update-ref HEAD $B $A &&
test $B = $(cat .git/$m) test $B = $(git show-ref -s --verify $m)
' '
test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" ' test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" '
test_when_finished "rm -f .git/$m" && test_when_finished "rm -f .git/$m" &&
@ -255,7 +255,7 @@ test_expect_success '(not) change HEAD with wrong SHA1' '
' '
test_expect_success "(not) changed .git/$m" ' test_expect_success "(not) changed .git/$m" '
test_when_finished "rm -f .git/$m" && test_when_finished "rm -f .git/$m" &&
! test $B = $(cat .git/$m) ! test $B = $(git show-ref -s --verify $m)
' '


rm -f .git/logs/refs/heads/master rm -f .git/logs/refs/heads/master
@ -263,19 +263,19 @@ test_expect_success "create $m (logged by touch)" '
test_config core.logAllRefUpdates false && test_config core.logAllRefUpdates false &&
GIT_COMMITTER_DATE="2005-05-26 23:30" \ GIT_COMMITTER_DATE="2005-05-26 23:30" \
git update-ref --create-reflog HEAD $A -m "Initial Creation" && git update-ref --create-reflog HEAD $A -m "Initial Creation" &&
test $A = $(cat .git/$m) test $A = $(git show-ref -s --verify $m)
' '
test_expect_success "update $m (logged by touch)" ' test_expect_success "update $m (logged by touch)" '
test_config core.logAllRefUpdates false && test_config core.logAllRefUpdates false &&
GIT_COMMITTER_DATE="2005-05-26 23:31" \ GIT_COMMITTER_DATE="2005-05-26 23:31" \
git update-ref HEAD $B $A -m "Switch" && git update-ref HEAD $B $A -m "Switch" &&
test $B = $(cat .git/$m) test $B = $(git show-ref -s --verify $m)
' '
test_expect_success "set $m (logged by touch)" ' test_expect_success "set $m (logged by touch)" '
test_config core.logAllRefUpdates false && test_config core.logAllRefUpdates false &&
GIT_COMMITTER_DATE="2005-05-26 23:41" \ GIT_COMMITTER_DATE="2005-05-26 23:41" \
git update-ref HEAD $A && git update-ref HEAD $A &&
test $A = $(cat .git/$m) test $A = $(git show-ref -s --verify $m)
' '


test_expect_success 'empty directory removal' ' test_expect_success 'empty directory removal' '
@ -319,19 +319,19 @@ test_expect_success "create $m (logged by config)" '
test_config core.logAllRefUpdates true && test_config core.logAllRefUpdates true &&
GIT_COMMITTER_DATE="2005-05-26 23:32" \ GIT_COMMITTER_DATE="2005-05-26 23:32" \
git update-ref HEAD $A -m "Initial Creation" && git update-ref HEAD $A -m "Initial Creation" &&
test $A = $(cat .git/$m) test $A = $(git show-ref -s --verify $m)
' '
test_expect_success "update $m (logged by config)" ' test_expect_success "update $m (logged by config)" '
test_config core.logAllRefUpdates true && test_config core.logAllRefUpdates true &&
GIT_COMMITTER_DATE="2005-05-26 23:33" \ GIT_COMMITTER_DATE="2005-05-26 23:33" \
git update-ref HEAD'" $B $A "'-m "Switch" && git update-ref HEAD'" $B $A "'-m "Switch" &&
test $B = $(cat .git/$m) test $B = $(git show-ref -s --verify $m)
' '
test_expect_success "set $m (logged by config)" ' test_expect_success "set $m (logged by config)" '
test_config core.logAllRefUpdates true && test_config core.logAllRefUpdates true &&
GIT_COMMITTER_DATE="2005-05-26 23:43" \ GIT_COMMITTER_DATE="2005-05-26 23:43" \
git update-ref HEAD $A && git update-ref HEAD $A &&
test $A = $(cat .git/$m) test $A = $(git show-ref -s --verify $m)
' '


cat >expect <<EOF cat >expect <<EOF

View File

@ -207,7 +207,7 @@ test_expect_success 'arg before dashdash must be a revision (ambiguous)' '
{ {
# we do not want to use rev-parse here, because # we do not want to use rev-parse here, because
# we are testing it # we are testing it
cat .git/refs/heads/foobar && git show-ref -s refs/heads/foobar &&
printf "%s\n" -- printf "%s\n" --
} >expect && } >expect &&
git rev-parse foobar -- >actual && git rev-parse foobar -- >actual &&

View File

@ -135,7 +135,7 @@ test_expect_success 'tag replaced commit' '
test_expect_success '"git fsck" works' ' test_expect_success '"git fsck" works' '
git fsck master >fsck_master.out && git fsck master >fsck_master.out &&
test_i18ngrep "dangling commit $R" fsck_master.out && test_i18ngrep "dangling commit $R" fsck_master.out &&
test_i18ngrep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out && test_i18ngrep "dangling tag $(git show-ref -s refs/tags/mytag)" fsck_master.out &&
test -z "$(git fsck)" test -z "$(git fsck)"
' '



View File

@ -48,8 +48,8 @@ test_expect_success REMOTE_SVN 'simple fetch' '
' '


test_debug ' test_debug '
cat .git/refs/svn/svnsim/master git show-ref -s refs/svn/svnsim/master
cat .git/refs/remotes/svnsim/master git show-ref -s refs/remotes/svnsim/master
' '


test_expect_success REMOTE_SVN 'repeated fetch, nothing shall change' ' test_expect_success REMOTE_SVN 'repeated fetch, nothing shall change' '