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>
Han-Wen Nienhuys committed
May 20, 2020 at 17:36 UTC
cdb73ca56f21835b93345442a96c97f6a0589ef7
5 files changed
+21
-21
t/t0002-gitfile.sh
+1
-1
@@ -62,7 +62,7 @@ test_expect_success 'check commit-tree' '
62
'
63
64
test_expect_success 'check rev-list' '
65
- echo $SHA >"$REAL/HEAD" &&
65
+ git update-ref "HEAD" "$SHA" &&
66
test "$SHA" = "$(git rev-list HEAD)"
67
'
68
t/t1400-update-ref.sh
+16
-16
@@ -37,15 +37,15 @@ test_expect_success setup '
37
38
test_expect_success "create $m" '
39
git update-ref $m $A &&
40
- test $A = $(cat .git/$m)
40
+ test $A = $(git show-ref -s --verify $m)
41
'
42
test_expect_success "create $m with oldvalue verification" '
43
git update-ref $m $B $A &&
44
- test $B = $(cat .git/$m)
44
+ test $B = $(git show-ref -s --verify $m)
45
'
46
test_expect_success "fail to delete $m with stale ref" '
47
test_must_fail git update-ref -d $m $A &&
48
- test $B = "$(cat .git/$m)"
48
+ test $B = "$(git show-ref -s --verify $m)"
49
'
50
test_expect_success "delete $m" '
51
test_when_finished "rm -f .git/$m" &&
@@ -56,7 +56,7 @@ test_expect_success "delete $m" '
56
test_expect_success "delete $m without oldvalue verification" '
57
test_when_finished "rm -f .git/$m" &&
58
git update-ref $m $A &&
59
- test $A = $(cat .git/$m) &&
59
+ test $A = $(git show-ref -s --verify $m) &&
60
git update-ref -d $m &&
61
test_path_is_missing .git/$m
62
'
@@ -69,15 +69,15 @@ test_expect_success "fail to create $n" '
69
70
test_expect_success "create $m (by HEAD)" '
71
git update-ref HEAD $A &&
72
- test $A = $(cat .git/$m)
72
+ test $A = $(git show-ref -s --verify $m)
73
'
74
test_expect_success "create $m (by HEAD) with oldvalue verification" '
75
git update-ref HEAD $B $A &&
76
- test $B = $(cat .git/$m)
76
+ test $B = $(git show-ref -s --verify $m)
77
'
78
test_expect_success "fail to delete $m (by HEAD) with stale ref" '
79
test_must_fail git update-ref -d HEAD $A &&
80
- test $B = $(cat .git/$m)
80
+ test $B = $(git show-ref -s --verify $m)
81
'
82
test_expect_success "delete $m (by HEAD)" '
83
test_when_finished "rm -f .git/$m" &&
@@ -178,14 +178,14 @@ test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always'
178
179
test_expect_success "create $m (by HEAD)" '
180
git update-ref HEAD $A &&
181
- test $A = $(cat .git/$m)
181
+ test $A = $(git show-ref -s --verify $m)
182
'
183
test_expect_success 'pack refs' '
184
git pack-refs --all
185
'
186
test_expect_success "move $m (by HEAD)" '
187
git update-ref HEAD $B $A &&
188
- test $B = $(cat .git/$m)
188
+ test $B = $(git show-ref -s --verify $m)
189
'
190
test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" '
191
test_when_finished "rm -f .git/$m" &&
@@ -255,7 +255,7 @@ test_expect_success '(not) change HEAD with wrong SHA1' '
255
'
256
test_expect_success "(not) changed .git/$m" '
257
test_when_finished "rm -f .git/$m" &&
258
- ! test $B = $(cat .git/$m)
258
+ ! test $B = $(git show-ref -s --verify $m)
259
'
260
261
rm -f .git/logs/refs/heads/master
@@ -263,19 +263,19 @@ test_expect_success "create $m (logged by touch)" '
263
test_config core.logAllRefUpdates false &&
264
GIT_COMMITTER_DATE="2005-05-26 23:30" \
265
git update-ref --create-reflog HEAD $A -m "Initial Creation" &&
266
- test $A = $(cat .git/$m)
266
+ test $A = $(git show-ref -s --verify $m)
267
'
268
test_expect_success "update $m (logged by touch)" '
269
test_config core.logAllRefUpdates false &&
270
GIT_COMMITTER_DATE="2005-05-26 23:31" \
271
git update-ref HEAD $B $A -m "Switch" &&
272
- test $B = $(cat .git/$m)
272
+ test $B = $(git show-ref -s --verify $m)
273
'
274
test_expect_success "set $m (logged by touch)" '
275
test_config core.logAllRefUpdates false &&
276
GIT_COMMITTER_DATE="2005-05-26 23:41" \
277
git update-ref HEAD $A &&
278
- test $A = $(cat .git/$m)
278
+ test $A = $(git show-ref -s --verify $m)
279
'
280
281
test_expect_success 'empty directory removal' '
@@ -319,19 +319,19 @@ test_expect_success "create $m (logged by config)" '
319
test_config core.logAllRefUpdates true &&
320
GIT_COMMITTER_DATE="2005-05-26 23:32" \
321
git update-ref HEAD $A -m "Initial Creation" &&
322
- test $A = $(cat .git/$m)
322
+ test $A = $(git show-ref -s --verify $m)
323
'
324
test_expect_success "update $m (logged by config)" '
325
test_config core.logAllRefUpdates true &&
326
GIT_COMMITTER_DATE="2005-05-26 23:33" \
327
git update-ref HEAD'" $B $A "'-m "Switch" &&
328
- test $B = $(cat .git/$m)
328
+ test $B = $(git show-ref -s --verify $m)
329
'
330
test_expect_success "set $m (logged by config)" '
331
test_config core.logAllRefUpdates true &&
332
GIT_COMMITTER_DATE="2005-05-26 23:43" \
333
git update-ref HEAD $A &&
334
- test $A = $(cat .git/$m)
334
+ test $A = $(git show-ref -s --verify $m)
335
'
336
337
cat >expect <<EOF
t/t1506-rev-parse-diagnosis.sh
+1
-1
@@ -207,7 +207,7 @@ test_expect_success 'arg before dashdash must be a revision (ambiguous)' '
207
{
208
# we do not want to use rev-parse here, because
209
# we are testing it
210
- cat .git/refs/heads/foobar &&
210
+ git show-ref -s refs/heads/foobar &&
211
printf "%s\n" --
212
} >expect &&
213
git rev-parse foobar -- >actual &&
t/t6050-replace.sh
+1
-1
@@ -135,7 +135,7 @@ test_expect_success 'tag replaced commit' '
135
test_expect_success '"git fsck" works' '
136
git fsck master >fsck_master.out &&
137
test_i18ngrep "dangling commit $R" fsck_master.out &&
138
- test_i18ngrep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out &&
138
+ test_i18ngrep "dangling tag $(git show-ref -s refs/tags/mytag)" fsck_master.out &&
139
test -z "$(git fsck)"
140
'
141
t/t9020-remote-svn.sh
+2
-2
@@ -48,8 +48,8 @@ test_expect_success REMOTE_SVN 'simple fetch' '
48
'
49
50
test_debug '
51
- cat .git/refs/svn/svnsim/master
52
- cat .git/refs/remotes/svnsim/master
51
+ git show-ref -s refs/svn/svnsim/master
52
+ git show-ref -s refs/remotes/svnsim/master
53
'
54
55
test_expect_success REMOTE_SVN 'repeated fetch, nothing shall change' '