t1404: move reffiles specific tests to t0600

These tests modify loose refs manually and are specific to the reffiles backend. Move these to t0600 to be part of a test suite of reffiles specific tests. Signed-off-by: John Cai <johncai86@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

John Cai committed Jan 19, 2024 at 20:18 UTC 102d7154a0546e79fa54b758db835dcfdcd1df2e
2 files changed +263 -237
t/t0600-reffiles-backend.sh new
+263
@@ -0,0 +1,263 @@
1 +#!/bin/sh
2 +
3 +test_description='Test reffiles backend'
4 +
5 +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 +
8 +TEST_PASSES_SANITIZE_LEAK=true
9 +. ./test-lib.sh
10 +
11 +if ! test_have_prereq REFFILES
12 +then
13 + skip_all='skipping reffiles specific tests'
14 + test_done
15 +fi
16 +
17 +test_expect_success 'setup' '
18 + git commit --allow-empty -m Initial &&
19 + C=$(git rev-parse HEAD) &&
20 + git commit --allow-empty -m Second &&
21 + D=$(git rev-parse HEAD) &&
22 + git commit --allow-empty -m Third &&
23 + E=$(git rev-parse HEAD)
24 +'
25 +
26 +test_expect_success 'empty directory should not fool rev-parse' '
27 + prefix=refs/e-rev-parse &&
28 + git update-ref $prefix/foo $C &&
29 + git pack-refs --all &&
30 + mkdir -p .git/$prefix/foo/bar/baz &&
31 + echo "$C" >expected &&
32 + git rev-parse $prefix/foo >actual &&
33 + test_cmp expected actual
34 +'
35 +
36 +test_expect_success 'empty directory should not fool for-each-ref' '
37 + prefix=refs/e-for-each-ref &&
38 + git update-ref $prefix/foo $C &&
39 + git for-each-ref $prefix >expected &&
40 + git pack-refs --all &&
41 + mkdir -p .git/$prefix/foo/bar/baz &&
42 + git for-each-ref $prefix >actual &&
43 + test_cmp expected actual
44 +'
45 +
46 +test_expect_success 'empty directory should not fool create' '
47 + prefix=refs/e-create &&
48 + mkdir -p .git/$prefix/foo/bar/baz &&
49 + printf "create %s $C\n" $prefix/foo |
50 + git update-ref --stdin
51 +'
52 +
53 +test_expect_success 'empty directory should not fool verify' '
54 + prefix=refs/e-verify &&
55 + git update-ref $prefix/foo $C &&
56 + git pack-refs --all &&
57 + mkdir -p .git/$prefix/foo/bar/baz &&
58 + printf "verify %s $C\n" $prefix/foo |
59 + git update-ref --stdin
60 +'
61 +
62 +test_expect_success 'empty directory should not fool 1-arg update' '
63 + prefix=refs/e-update-1 &&
64 + git update-ref $prefix/foo $C &&
65 + git pack-refs --all &&
66 + mkdir -p .git/$prefix/foo/bar/baz &&
67 + printf "update %s $D\n" $prefix/foo |
68 + git update-ref --stdin
69 +'
70 +
71 +test_expect_success 'empty directory should not fool 2-arg update' '
72 + prefix=refs/e-update-2 &&
73 + git update-ref $prefix/foo $C &&
74 + git pack-refs --all &&
75 + mkdir -p .git/$prefix/foo/bar/baz &&
76 + printf "update %s $D $C\n" $prefix/foo |
77 + git update-ref --stdin
78 +'
79 +
80 +test_expect_success 'empty directory should not fool 0-arg delete' '
81 + prefix=refs/e-delete-0 &&
82 + git update-ref $prefix/foo $C &&
83 + git pack-refs --all &&
84 + mkdir -p .git/$prefix/foo/bar/baz &&
85 + printf "delete %s\n" $prefix/foo |
86 + git update-ref --stdin
87 +'
88 +
89 +test_expect_success 'empty directory should not fool 1-arg delete' '
90 + prefix=refs/e-delete-1 &&
91 + git update-ref $prefix/foo $C &&
92 + git pack-refs --all &&
93 + mkdir -p .git/$prefix/foo/bar/baz &&
94 + printf "delete %s $C\n" $prefix/foo |
95 + git update-ref --stdin
96 +'
97 +
98 +test_expect_success 'non-empty directory blocks create' '
99 + prefix=refs/ne-create &&
100 + mkdir -p .git/$prefix/foo/bar &&
101 + : >.git/$prefix/foo/bar/baz.lock &&
102 + test_when_finished "rm -f .git/$prefix/foo/bar/baz.lock" &&
103 + cat >expected <<-EOF &&
104 + fatal: cannot lock ref $SQ$prefix/foo$SQ: there is a non-empty directory $SQ.git/$prefix/foo$SQ blocking reference $SQ$prefix/foo$SQ
105 + EOF
106 + printf "%s\n" "update $prefix/foo $C" |
107 + test_must_fail git update-ref --stdin 2>output.err &&
108 + test_cmp expected output.err &&
109 + cat >expected <<-EOF &&
110 + fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ
111 + EOF
112 + printf "%s\n" "update $prefix/foo $D $C" |
113 + test_must_fail git update-ref --stdin 2>output.err &&
114 + test_cmp expected output.err
115 +'
116 +
117 +test_expect_success 'broken reference blocks create' '
118 + prefix=refs/broken-create &&
119 + mkdir -p .git/$prefix &&
120 + echo "gobbledigook" >.git/$prefix/foo &&
121 + test_when_finished "rm -f .git/$prefix/foo" &&
122 + cat >expected <<-EOF &&
123 + fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken
124 + EOF
125 + printf "%s\n" "update $prefix/foo $C" |
126 + test_must_fail git update-ref --stdin 2>output.err &&
127 + test_cmp expected output.err &&
128 + cat >expected <<-EOF &&
129 + fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken
130 + EOF
131 + printf "%s\n" "update $prefix/foo $D $C" |
132 + test_must_fail git update-ref --stdin 2>output.err &&
133 + test_cmp expected output.err
134 +'
135 +
136 +test_expect_success 'non-empty directory blocks indirect create' '
137 + prefix=refs/ne-indirect-create &&
138 + git symbolic-ref $prefix/symref $prefix/foo &&
139 + mkdir -p .git/$prefix/foo/bar &&
140 + : >.git/$prefix/foo/bar/baz.lock &&
141 + test_when_finished "rm -f .git/$prefix/foo/bar/baz.lock" &&
142 + cat >expected <<-EOF &&
143 + fatal: cannot lock ref $SQ$prefix/symref$SQ: there is a non-empty directory $SQ.git/$prefix/foo$SQ blocking reference $SQ$prefix/foo$SQ
144 + EOF
145 + printf "%s\n" "update $prefix/symref $C" |
146 + test_must_fail git update-ref --stdin 2>output.err &&
147 + test_cmp expected output.err &&
148 + cat >expected <<-EOF &&
149 + fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ
150 + EOF
151 + printf "%s\n" "update $prefix/symref $D $C" |
152 + test_must_fail git update-ref --stdin 2>output.err &&
153 + test_cmp expected output.err
154 +'
155 +
156 +test_expect_success 'broken reference blocks indirect create' '
157 + prefix=refs/broken-indirect-create &&
158 + git symbolic-ref $prefix/symref $prefix/foo &&
159 + echo "gobbledigook" >.git/$prefix/foo &&
160 + test_when_finished "rm -f .git/$prefix/foo" &&
161 + cat >expected <<-EOF &&
162 + fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken
163 + EOF
164 + printf "%s\n" "update $prefix/symref $C" |
165 + test_must_fail git update-ref --stdin 2>output.err &&
166 + test_cmp expected output.err &&
167 + cat >expected <<-EOF &&
168 + fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken
169 + EOF
170 + printf "%s\n" "update $prefix/symref $D $C" |
171 + test_must_fail git update-ref --stdin 2>output.err &&
172 + test_cmp expected output.err
173 +'
174 +
175 +test_expect_success 'no bogus intermediate values during delete' '
176 + prefix=refs/slow-transaction &&
177 + # Set up a reference with differing loose and packed versions:
178 + git update-ref $prefix/foo $C &&
179 + git pack-refs --all &&
180 + git update-ref $prefix/foo $D &&
181 + # Now try to update the reference, but hold the `packed-refs` lock
182 + # for a while to see what happens while the process is blocked:
183 + : >.git/packed-refs.lock &&
184 + test_when_finished "rm -f .git/packed-refs.lock" &&
185 + {
186 + # Note: the following command is intentionally run in the
187 + # background. We increase the timeout so that `update-ref`
188 + # attempts to acquire the `packed-refs` lock for much longer
189 + # than it takes for us to do the check then delete it:
190 + git -c core.packedrefstimeout=30000 update-ref -d $prefix/foo &
191 + } &&
192 + pid2=$! &&
193 + # Give update-ref plenty of time to get to the point where it tries
194 + # to lock packed-refs:
195 + sleep 1 &&
196 + # Make sure that update-ref did not complete despite the lock:
197 + kill -0 $pid2 &&
198 + # Verify that the reference still has its old value:
199 + sha1=$(git rev-parse --verify --quiet $prefix/foo || echo undefined) &&
200 + case "$sha1" in
201 + $D)
202 + # This is what we hope for; it means that nothing
203 + # user-visible has changed yet.
204 + : ;;
205 + undefined)
206 + # This is not correct; it means the deletion has happened
207 + # already even though update-ref should not have been
208 + # able to acquire the lock yet.
209 + echo "$prefix/foo deleted prematurely" &&
210 + break
211 + ;;
212 + $C)
213 + # This value should never be seen. Probably the loose
214 + # reference has been deleted but the packed reference
215 + # is still there:
216 + echo "$prefix/foo incorrectly observed to be C" &&
217 + break
218 + ;;
219 + *)
220 + # WTF?
221 + echo "unexpected value observed for $prefix/foo: $sha1" &&
222 + break
223 + ;;
224 + esac >out &&
225 + rm -f .git/packed-refs.lock &&
226 + wait $pid2 &&
227 + test_must_be_empty out &&
228 + test_must_fail git rev-parse --verify --quiet $prefix/foo
229 +'
230 +
231 +test_expect_success 'delete fails cleanly if packed-refs file is locked' '
232 + prefix=refs/locked-packed-refs &&
233 + # Set up a reference with differing loose and packed versions:
234 + git update-ref $prefix/foo $C &&
235 + git pack-refs --all &&
236 + git update-ref $prefix/foo $D &&
237 + git for-each-ref $prefix >unchanged &&
238 + # Now try to delete it while the `packed-refs` lock is held:
239 + : >.git/packed-refs.lock &&
240 + test_when_finished "rm -f .git/packed-refs.lock" &&
241 + test_must_fail git update-ref -d $prefix/foo >out 2>err &&
242 + git for-each-ref $prefix >actual &&
243 + test_grep "Unable to create $SQ.*packed-refs.lock$SQ: " err &&
244 + test_cmp unchanged actual
245 +'
246 +
247 +test_expect_success 'delete fails cleanly if packed-refs.new write fails' '
248 + # Setup and expectations are similar to the test above.
249 + prefix=refs/failed-packed-refs &&
250 + git update-ref $prefix/foo $C &&
251 + git pack-refs --all &&
252 + git update-ref $prefix/foo $D &&
253 + git for-each-ref $prefix >unchanged &&
254 + # This should not happen in practice, but it is an easy way to get a
255 + # reliable error (we open with create_tempfile(), which uses O_EXCL).
256 + : >.git/packed-refs.new &&
257 + test_when_finished "rm -f .git/packed-refs.new" &&
258 + test_must_fail git update-ref -d $prefix/foo &&
259 + git for-each-ref $prefix >actual &&
260 + test_cmp unchanged actual
261 +'
262 +
263 +test_done
t/t1404-update-ref-errors.sh
-237
@@ -191,78 +191,6 @@ test_expect_success 'one new ref is a simple prefix of another' '
191
192 '
193
194 -test_expect_success REFFILES 'empty directory should not fool rev-parse' '
195 - prefix=refs/e-rev-parse &&
196 - git update-ref $prefix/foo $C &&
197 - git pack-refs --all &&
198 - mkdir -p .git/$prefix/foo/bar/baz &&
199 - echo "$C" >expected &&
200 - git rev-parse $prefix/foo >actual &&
201 - test_cmp expected actual
202 -'
203 -
204 -test_expect_success REFFILES 'empty directory should not fool for-each-ref' '
205 - prefix=refs/e-for-each-ref &&
206 - git update-ref $prefix/foo $C &&
207 - git for-each-ref $prefix >expected &&
208 - git pack-refs --all &&
209 - mkdir -p .git/$prefix/foo/bar/baz &&
210 - git for-each-ref $prefix >actual &&
211 - test_cmp expected actual
212 -'
213 -
214 -test_expect_success REFFILES 'empty directory should not fool create' '
215 - prefix=refs/e-create &&
216 - mkdir -p .git/$prefix/foo/bar/baz &&
217 - printf "create %s $C\n" $prefix/foo |
218 - git update-ref --stdin
219 -'
220 -
221 -test_expect_success REFFILES 'empty directory should not fool verify' '
222 - prefix=refs/e-verify &&
223 - git update-ref $prefix/foo $C &&
224 - git pack-refs --all &&
225 - mkdir -p .git/$prefix/foo/bar/baz &&
226 - printf "verify %s $C\n" $prefix/foo |
227 - git update-ref --stdin
228 -'
229 -
230 -test_expect_success REFFILES 'empty directory should not fool 1-arg update' '
231 - prefix=refs/e-update-1 &&
232 - git update-ref $prefix/foo $C &&
233 - git pack-refs --all &&
234 - mkdir -p .git/$prefix/foo/bar/baz &&
235 - printf "update %s $D\n" $prefix/foo |
236 - git update-ref --stdin
237 -'
238 -
239 -test_expect_success REFFILES 'empty directory should not fool 2-arg update' '
240 - prefix=refs/e-update-2 &&
241 - git update-ref $prefix/foo $C &&
242 - git pack-refs --all &&
243 - mkdir -p .git/$prefix/foo/bar/baz &&
244 - printf "update %s $D $C\n" $prefix/foo |
245 - git update-ref --stdin
246 -'
247 -
248 -test_expect_success REFFILES 'empty directory should not fool 0-arg delete' '
249 - prefix=refs/e-delete-0 &&
250 - git update-ref $prefix/foo $C &&
251 - git pack-refs --all &&
252 - mkdir -p .git/$prefix/foo/bar/baz &&
253 - printf "delete %s\n" $prefix/foo |
254 - git update-ref --stdin
255 -'
256 -
257 -test_expect_success REFFILES 'empty directory should not fool 1-arg delete' '
258 - prefix=refs/e-delete-1 &&
259 - git update-ref $prefix/foo $C &&
260 - git pack-refs --all &&
261 - mkdir -p .git/$prefix/foo/bar/baz &&
262 - printf "delete %s $C\n" $prefix/foo |
263 - git update-ref --stdin
264 -'
265 -
194 test_expect_success REFFILES 'D/F conflict prevents add long + delete short' '
195 df_test refs/df-al-ds --add-del foo/bar foo
196 '
@@ -468,169 +396,4 @@ test_expect_success 'incorrect old value blocks indirect no-deref delete' '
396 test_cmp expected output.err
397 '
398
471 -test_expect_success REFFILES 'non-empty directory blocks create' '
472 - prefix=refs/ne-create &&
473 - mkdir -p .git/$prefix/foo/bar &&
474 - : >.git/$prefix/foo/bar/baz.lock &&
475 - test_when_finished "rm -f .git/$prefix/foo/bar/baz.lock" &&
476 - cat >expected <<-EOF &&
477 - fatal: cannot lock ref $SQ$prefix/foo$SQ: there is a non-empty directory $SQ.git/$prefix/foo$SQ blocking reference $SQ$prefix/foo$SQ
478 - EOF
479 - printf "%s\n" "update $prefix/foo $C" |
480 - test_must_fail git update-ref --stdin 2>output.err &&
481 - test_cmp expected output.err &&
482 - cat >expected <<-EOF &&
483 - fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ
484 - EOF
485 - printf "%s\n" "update $prefix/foo $D $C" |
486 - test_must_fail git update-ref --stdin 2>output.err &&
487 - test_cmp expected output.err
488 -'
489 -
490 -test_expect_success REFFILES 'broken reference blocks create' '
491 - prefix=refs/broken-create &&
492 - mkdir -p .git/$prefix &&
493 - echo "gobbledigook" >.git/$prefix/foo &&
494 - test_when_finished "rm -f .git/$prefix/foo" &&
495 - cat >expected <<-EOF &&
496 - fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken
497 - EOF
498 - printf "%s\n" "update $prefix/foo $C" |
499 - test_must_fail git update-ref --stdin 2>output.err &&
500 - test_cmp expected output.err &&
501 - cat >expected <<-EOF &&
502 - fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken
503 - EOF
504 - printf "%s\n" "update $prefix/foo $D $C" |
505 - test_must_fail git update-ref --stdin 2>output.err &&
506 - test_cmp expected output.err
507 -'
508 -
509 -test_expect_success REFFILES 'non-empty directory blocks indirect create' '
510 - prefix=refs/ne-indirect-create &&
511 - git symbolic-ref $prefix/symref $prefix/foo &&
512 - mkdir -p .git/$prefix/foo/bar &&
513 - : >.git/$prefix/foo/bar/baz.lock &&
514 - test_when_finished "rm -f .git/$prefix/foo/bar/baz.lock" &&
515 - cat >expected <<-EOF &&
516 - fatal: cannot lock ref $SQ$prefix/symref$SQ: there is a non-empty directory $SQ.git/$prefix/foo$SQ blocking reference $SQ$prefix/foo$SQ
517 - EOF
518 - printf "%s\n" "update $prefix/symref $C" |
519 - test_must_fail git update-ref --stdin 2>output.err &&
520 - test_cmp expected output.err &&
521 - cat >expected <<-EOF &&
522 - fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ
523 - EOF
524 - printf "%s\n" "update $prefix/symref $D $C" |
525 - test_must_fail git update-ref --stdin 2>output.err &&
526 - test_cmp expected output.err
527 -'
528 -
529 -test_expect_success REFFILES 'broken reference blocks indirect create' '
530 - prefix=refs/broken-indirect-create &&
531 - git symbolic-ref $prefix/symref $prefix/foo &&
532 - echo "gobbledigook" >.git/$prefix/foo &&
533 - test_when_finished "rm -f .git/$prefix/foo" &&
534 - cat >expected <<-EOF &&
535 - fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken
536 - EOF
537 - printf "%s\n" "update $prefix/symref $C" |
538 - test_must_fail git update-ref --stdin 2>output.err &&
539 - test_cmp expected output.err &&
540 - cat >expected <<-EOF &&
541 - fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken
542 - EOF
543 - printf "%s\n" "update $prefix/symref $D $C" |
544 - test_must_fail git update-ref --stdin 2>output.err &&
545 - test_cmp expected output.err
546 -'
547 -
548 -test_expect_success REFFILES 'no bogus intermediate values during delete' '
549 - prefix=refs/slow-transaction &&
550 - # Set up a reference with differing loose and packed versions:
551 - git update-ref $prefix/foo $C &&
552 - git pack-refs --all &&
553 - git update-ref $prefix/foo $D &&
554 - # Now try to update the reference, but hold the `packed-refs` lock
555 - # for a while to see what happens while the process is blocked:
556 - : >.git/packed-refs.lock &&
557 - test_when_finished "rm -f .git/packed-refs.lock" &&
558 - {
559 - # Note: the following command is intentionally run in the
560 - # background. We increase the timeout so that `update-ref`
561 - # attempts to acquire the `packed-refs` lock for much longer
562 - # than it takes for us to do the check then delete it:
563 - git -c core.packedrefstimeout=30000 update-ref -d $prefix/foo &
564 - } &&
565 - pid2=$! &&
566 - # Give update-ref plenty of time to get to the point where it tries
567 - # to lock packed-refs:
568 - sleep 1 &&
569 - # Make sure that update-ref did not complete despite the lock:
570 - kill -0 $pid2 &&
571 - # Verify that the reference still has its old value:
572 - sha1=$(git rev-parse --verify --quiet $prefix/foo || echo undefined) &&
573 - case "$sha1" in
574 - $D)
575 - # This is what we hope for; it means that nothing
576 - # user-visible has changed yet.
577 - : ;;
578 - undefined)
579 - # This is not correct; it means the deletion has happened
580 - # already even though update-ref should not have been
581 - # able to acquire the lock yet.
582 - echo "$prefix/foo deleted prematurely" &&
583 - break
584 - ;;
585 - $C)
586 - # This value should never be seen. Probably the loose
587 - # reference has been deleted but the packed reference
588 - # is still there:
589 - echo "$prefix/foo incorrectly observed to be C" &&
590 - break
591 - ;;
592 - *)
593 - # WTF?
594 - echo "unexpected value observed for $prefix/foo: $sha1" &&
595 - break
596 - ;;
597 - esac >out &&
598 - rm -f .git/packed-refs.lock &&
599 - wait $pid2 &&
600 - test_must_be_empty out &&
601 - test_must_fail git rev-parse --verify --quiet $prefix/foo
602 -'
603 -
604 -test_expect_success REFFILES 'delete fails cleanly if packed-refs file is locked' '
605 - prefix=refs/locked-packed-refs &&
606 - # Set up a reference with differing loose and packed versions:
607 - git update-ref $prefix/foo $C &&
608 - git pack-refs --all &&
609 - git update-ref $prefix/foo $D &&
610 - git for-each-ref $prefix >unchanged &&
611 - # Now try to delete it while the `packed-refs` lock is held:
612 - : >.git/packed-refs.lock &&
613 - test_when_finished "rm -f .git/packed-refs.lock" &&
614 - test_must_fail git update-ref -d $prefix/foo >out 2>err &&
615 - git for-each-ref $prefix >actual &&
616 - test_grep "Unable to create $SQ.*packed-refs.lock$SQ: " err &&
617 - test_cmp unchanged actual
618 -'
619 -
620 -test_expect_success REFFILES 'delete fails cleanly if packed-refs.new write fails' '
621 - # Setup and expectations are similar to the test above.
622 - prefix=refs/failed-packed-refs &&
623 - git update-ref $prefix/foo $C &&
624 - git pack-refs --all &&
625 - git update-ref $prefix/foo $D &&
626 - git for-each-ref $prefix >unchanged &&
627 - # This should not happen in practice, but it is an easy way to get a
628 - # reliable error (we open with create_tempfile(), which uses O_EXCL).
629 - : >.git/packed-refs.new &&
630 - test_when_finished "rm -f .git/packed-refs.new" &&
631 - test_must_fail git update-ref -d $prefix/foo &&
632 - git for-each-ref $prefix >actual &&
633 - test_cmp unchanged actual
634 -'
635 -
399 test_done