t1400: avoid touching refs on filesystem

The testcase t1400 exercises the git-update-ref(1) utility. To do so, many tests directly read and write references via the filesystem, assuming that we always use loose and/or packed references. While this is true now, it'll change with the introduction of the reftable backend. Convert those tests to use git-update-ref(1) and git-show-ref(1) where possible. Furthermore, two tests are converted to not delete HEAD anymore, as this results in a broken repository. They've instead been updated to create a non-mandatory symbolic reference and delete that one instead. Some tests remain which exercise behaviour with broken references, which cannot currently be converted to use regular git tooling. Signed-off-by: Patrick Steinhardt <ps@pks.im> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Nov 13, 2020 at 09:12 UTC c0e172612754db0ed4c83d82b44fbc61f766ad6f
1 file changed +42 -35
t/t1400-update-ref.sh
+42 -35
@@ -48,17 +48,17 @@ test_expect_success "fail to delete $m with stale ref" '
48 test $B = "$(git show-ref -s --verify $m)"
49 '
50 test_expect_success "delete $m" '
51 - test_when_finished "rm -f .git/$m" &&
51 + test_when_finished "git update-ref -d $m" &&
52 git update-ref -d $m $B &&
53 - test_path_is_missing .git/$m
53 + test_must_fail git show-ref --verify -q $m
54 '
55
56 test_expect_success "delete $m without oldvalue verification" '
57 - test_when_finished "rm -f .git/$m" &&
57 + test_when_finished "git update-ref -d $m" &&
58 git update-ref $m $A &&
59 test $A = $(git show-ref -s --verify $m) &&
60 git update-ref -d $m &&
61 - test_path_is_missing .git/$m
61 + test_must_fail git show-ref --verify -q $m
62 '
63
64 test_expect_success "fail to create $n" '
@@ -80,26 +80,26 @@ test_expect_success "fail to delete $m (by HEAD) with stale ref" '
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" &&
83 + test_when_finished "git update-ref -d $m" &&
84 git update-ref -d HEAD $B &&
85 - test_path_is_missing .git/$m
85 + test_must_fail git show-ref --verify -q $m
86 '
87
88 test_expect_success "deleting current branch adds message to HEAD's log" '
89 - test_when_finished "rm -f .git/$m" &&
89 + test_when_finished "git update-ref -d $m" &&
90 git update-ref $m $A &&
91 git symbolic-ref HEAD $m &&
92 git update-ref -m delete-$m -d $m &&
93 - test_path_is_missing .git/$m &&
93 + test_must_fail git show-ref --verify -q $m &&
94 grep "delete-$m$" .git/logs/HEAD
95 '
96
97 test_expect_success "deleting by HEAD adds message to HEAD's log" '
98 - test_when_finished "rm -f .git/$m" &&
98 + test_when_finished "git update-ref -d $m" &&
99 git update-ref $m $A &&
100 git symbolic-ref HEAD $m &&
101 git update-ref -m delete-by-head -d HEAD &&
102 - test_path_is_missing .git/$m &&
102 + test_must_fail git show-ref --verify -q $m &&
103 grep "delete-by-head$" .git/logs/HEAD
104 '
105
@@ -188,31 +188,37 @@ test_expect_success "move $m (by HEAD)" '
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" &&
191 + test_when_finished "git update-ref -d $m" &&
192 git update-ref -d HEAD $B &&
193 ! grep "$m" .git/packed-refs &&
194 - test_path_is_missing .git/$m
194 + test_must_fail git show-ref --verify -q $m
195 '
196
197 -cp -f .git/HEAD .git/HEAD.orig
197 test_expect_success 'delete symref without dereference' '
199 - test_when_finished "cp -f .git/HEAD.orig .git/HEAD" &&
200 - git update-ref --no-deref -d HEAD &&
201 - test_path_is_missing .git/HEAD
198 + test_when_finished "git update-ref -d $m" &&
199 + echo foo >foo.c &&
200 + git add foo.c &&
201 + git commit -m foo &&
202 + git symbolic-ref SYMREF $m &&
203 + git update-ref --no-deref -d SYMREF &&
204 + git show-ref --verify -q $m &&
205 + test_must_fail git show-ref --verify -q SYMREF &&
206 + test_must_fail git symbolic-ref SYMREF
207 '
208
209 test_expect_success 'delete symref without dereference when the referred ref is packed' '
205 - test_when_finished "cp -f .git/HEAD.orig .git/HEAD" &&
210 + test_when_finished "git update-ref -d $m" &&
211 echo foo >foo.c &&
212 git add foo.c &&
213 git commit -m foo &&
214 + git symbolic-ref SYMREF $m &&
215 git pack-refs --all &&
210 - git update-ref --no-deref -d HEAD &&
211 - test_path_is_missing .git/HEAD
216 + git update-ref --no-deref -d SYMREF &&
217 + git show-ref --verify -q $m &&
218 + test_must_fail git show-ref --verify -q SYMREF &&
219 + test_must_fail git symbolic-ref SYMREF
220 '
221
214 -git update-ref -d $m
215 -
222 test_expect_success 'update-ref -d is not confused by self-reference' '
223 git symbolic-ref refs/heads/self refs/heads/self &&
224 test_when_finished "rm -f .git/refs/heads/self" &&
@@ -226,25 +232,25 @@ test_expect_success 'update-ref --no-deref -d can delete self-reference' '
232 test_when_finished "rm -f .git/refs/heads/self" &&
233 test_path_is_file .git/refs/heads/self &&
234 git update-ref --no-deref -d refs/heads/self &&
229 - test_path_is_missing .git/refs/heads/self
235 + test_must_fail git show-ref --verify -q refs/heads/self
236 '
237
238 test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
239 >.git/refs/heads/bad &&
240 test_when_finished "rm -f .git/refs/heads/bad" &&
241 git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
236 - test_when_finished "rm -f .git/refs/heads/ref-to-bad" &&
242 + test_when_finished "git update-ref -d refs/heads/ref-to-bad" &&
243 test_path_is_file .git/refs/heads/ref-to-bad &&
244 git update-ref --no-deref -d refs/heads/ref-to-bad &&
239 - test_path_is_missing .git/refs/heads/ref-to-bad
245 + test_must_fail git show-ref --verify -q refs/heads/ref-to-bad
246 '
247
248 test_expect_success '(not) create HEAD with old sha1' '
249 test_must_fail git update-ref HEAD $A $B
250 '
251 test_expect_success "(not) prior created .git/$m" '
246 - test_when_finished "rm -f .git/$m" &&
247 - test_path_is_missing .git/$m
252 + test_when_finished "git update-ref -d $m" &&
253 + test_must_fail git show-ref --verify -q $m
254 '
255
256 test_expect_success 'create HEAD' '
@@ -254,7 +260,7 @@ test_expect_success '(not) change HEAD with wrong SHA1' '
260 test_must_fail git update-ref HEAD $B $Z
261 '
262 test_expect_success "(not) changed .git/$m" '
257 - test_when_finished "rm -f .git/$m" &&
263 + test_when_finished "git update-ref -d $m" &&
264 ! test $B = $(git show-ref -s --verify $m)
265 '
266
@@ -284,8 +290,8 @@ test_expect_success 'empty directory removal' '
290 test_path_is_file .git/refs/heads/d1/d2/r1 &&
291 test_path_is_file .git/logs/refs/heads/d1/d2/r1 &&
292 git branch -d d1/d2/r1 &&
287 - test_path_is_missing .git/refs/heads/d1/d2 &&
288 - test_path_is_missing .git/logs/refs/heads/d1/d2 &&
293 + test_must_fail git show-ref --verify -q refs/heads/d1/d2 &&
294 + test_must_fail git show-ref --verify -q logs/refs/heads/d1/d2 &&
295 test_path_is_file .git/refs/heads/d1/r2 &&
296 test_path_is_file .git/logs/refs/heads/d1/r2
297 '
@@ -298,8 +304,8 @@ test_expect_success 'symref empty directory removal' '
304 test_path_is_file .git/refs/heads/e1/e2/r1 &&
305 test_path_is_file .git/logs/refs/heads/e1/e2/r1 &&
306 git update-ref -d HEAD &&
301 - test_path_is_missing .git/refs/heads/e1/e2 &&
302 - test_path_is_missing .git/logs/refs/heads/e1/e2 &&
307 + test_must_fail git show-ref --verify -q refs/heads/e1/e2 &&
308 + test_must_fail git show-ref --verify -q logs/refs/heads/e1/e2 &&
309 test_path_is_file .git/refs/heads/e1/r2 &&
310 test_path_is_file .git/logs/refs/heads/e1/r2 &&
311 test_path_is_file .git/logs/HEAD
@@ -1388,7 +1394,8 @@ test_expect_success 'handle per-worktree refs in refs/bisect' '
1394 git rev-parse refs/bisect/something >../worktree-head &&
1395 git for-each-ref | grep refs/bisect/something
1396 ) &&
1391 - test_path_is_missing .git/refs/bisect &&
1397 + git show-ref >actual &&
1398 + ! grep 'refs/bisect' actual &&
1399 test_must_fail git rev-parse refs/bisect/something &&
1400 git update-ref refs/bisect/something HEAD &&
1401 git rev-parse refs/bisect/something >main-head &&
@@ -1500,7 +1507,7 @@ test_expect_success 'transaction can handle abort' '
1507 git update-ref --stdin <stdin >actual &&
1508 printf "%s: ok\n" start abort >expect &&
1509 test_cmp expect actual &&
1503 - test_path_is_missing .git/$b
1510 + test_must_fail git show-ref --verify -q $b
1511 '
1512
1513 test_expect_success 'transaction aborts by default' '
@@ -1511,7 +1518,7 @@ test_expect_success 'transaction aborts by default' '
1518 git update-ref --stdin <stdin >actual &&
1519 printf "%s: ok\n" start >expect &&
1520 test_cmp expect actual &&
1514 - test_path_is_missing .git/$b
1521 + test_must_fail git show-ref --verify -q $b
1522 '
1523
1524 test_expect_success 'transaction with prepare aborts by default' '
@@ -1523,7 +1530,7 @@ test_expect_success 'transaction with prepare aborts by default' '
1530 git update-ref --stdin <stdin >actual &&
1531 printf "%s: ok\n" start prepare >expect &&
1532 test_cmp expect actual &&
1526 - test_path_is_missing .git/$b
1533 + test_must_fail git show-ref --verify -q $b
1534 '
1535
1536 test_done