t: convert tests to not access symrefs via the filesystem
Some of our tests access symbolic references via the filesystem directly. While this works with the current files reference backend, it this will break once we have a second reference backend in our codebase. Refactor these tests to instead use git-symbolic-ref(1) or our `ref-store` test tool. The latter is required in some cases where safety checks of git-symbolic-ref(1) would otherwise reject writing a symbolic reference. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Nov 2, 2023 at 09:46 UTC
239371168173da9a9556617fced1e053ac618a85
9 files changed
+40
-25
t/t1400-update-ref.sh
+4
-4
@@ -221,15 +221,15 @@ test_expect_success 'delete symref without dereference when the referred ref is
221
test_expect_success 'update-ref -d is not confused by self-reference' '
222
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" &&
223
git symbolic-ref refs/heads/self refs/heads/self &&
224
- test_path_is_file .git/refs/heads/self &&
224
+ git symbolic-ref --no-recurse refs/heads/self &&
225
test_must_fail git update-ref -d refs/heads/self &&
226
- test_path_is_file .git/refs/heads/self
226
+ git symbolic-ref --no-recurse refs/heads/self
227
'
228
229
test_expect_success 'update-ref --no-deref -d can delete self-reference' '
230
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" &&
231
git symbolic-ref refs/heads/self refs/heads/self &&
232
- test_path_is_file .git/refs/heads/self &&
232
+ git symbolic-ref --no-recurse refs/heads/self &&
233
git update-ref --no-deref -d refs/heads/self &&
234
test_must_fail git show-ref --verify -q refs/heads/self
235
'
@@ -239,7 +239,7 @@ test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
239
test_when_finished "rm -f .git/refs/heads/bad" &&
240
git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
241
test_when_finished "git update-ref -d refs/heads/ref-to-bad" &&
242
- test_path_is_file .git/refs/heads/ref-to-bad &&
242
+ git symbolic-ref --no-recurse refs/heads/ref-to-bad &&
243
git update-ref --no-deref -d refs/heads/ref-to-bad &&
244
test_must_fail git show-ref --verify -q refs/heads/ref-to-bad
245
'
t/t1430-bad-ref-name.sh
+6
-6
@@ -164,9 +164,9 @@ test_expect_success 'rev-parse skips symref pointing to broken name' '
164
test_expect_success 'for-each-ref emits warnings for broken names' '
165
test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION &&
166
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...ref" &&
167
- printf "ref: refs/heads/broken...ref\n" >.git/refs/heads/badname &&
167
+ test-tool ref-store main create-symref refs/heads/badname refs/heads/broken...ref &&
168
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/badname" &&
169
- printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref &&
169
+ test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/main &&
170
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
171
git for-each-ref >output 2>error &&
172
! grep -e "broken\.\.\.ref" output &&
@@ -257,7 +257,7 @@ test_expect_success 'update-ref -d can delete broken name through symref' '
257
'
258
259
test_expect_success 'update-ref --no-deref -d can delete symref with broken name' '
260
- printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref &&
260
+ test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/main &&
261
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
262
test_ref_exists refs/heads/broken...symref &&
263
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
267
'
268
269
test_expect_success 'branch -d can delete symref with broken name' '
270
- printf "ref: refs/heads/main\n" >.git/refs/heads/broken...symref &&
270
+ test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/main &&
271
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
272
test_ref_exists refs/heads/broken...symref &&
273
git branch -d broken...symref >output 2>error &&
@@ -277,7 +277,7 @@ test_expect_success 'branch -d can delete symref with broken name' '
277
'
278
279
test_expect_success 'update-ref --no-deref -d can delete dangling symref with broken name' '
280
- printf "ref: refs/heads/idonotexist\n" >.git/refs/heads/broken...symref &&
280
+ test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/idonotexist &&
281
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
282
test_ref_exists refs/heads/broken...symref &&
283
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
287
'
288
289
test_expect_success 'branch -d can delete dangling symref with broken name' '
290
- printf "ref: refs/heads/idonotexist\n" >.git/refs/heads/broken...symref &&
290
+ test-tool ref-store main create-symref refs/heads/broken...symref refs/heads/idonotexist &&
291
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
292
test_ref_exists refs/heads/broken...symref &&
293
git branch -d broken...symref >output 2>error &&
t/t1450-fsck.sh
+2
-2
@@ -133,7 +133,7 @@ test_expect_success 'HEAD link pointing at a funny object' '
133
134
test_expect_success 'HEAD link pointing at a funny place' '
135
test_when_finished "git update-ref --no-deref HEAD $orig_head" &&
136
- echo "ref: refs/funny/place" >.git/HEAD &&
136
+ test-tool ref-store main create-symref HEAD refs/funny/place &&
137
# avoid corrupt/broken HEAD from interfering with repo discovery
138
test_must_fail env GIT_DIR=.git git fsck 2>out &&
139
test_i18ngrep "HEAD points to something strange" out
@@ -169,7 +169,7 @@ test_expect_success 'other worktree HEAD link pointing at missing object' '
169
test_expect_success 'other worktree HEAD link pointing at a funny place' '
170
test_when_finished "rm -rf .git/worktrees other" &&
171
git worktree add other &&
172
- echo "ref: refs/funny/place" >.git/worktrees/other/HEAD &&
172
+ git -C other symbolic-ref HEAD refs/funny/place &&
173
test_must_fail git fsck 2>out &&
174
test_i18ngrep "worktrees/other/HEAD points to something strange" out
175
'
t/t3200-branch.sh
+6
-3
@@ -215,10 +215,13 @@ test_expect_success 'git branch -M should leave orphaned HEAD alone' '
215
cd orphan &&
216
test_commit initial &&
217
git checkout --orphan lonely &&
218
- grep lonely .git/HEAD &&
218
+ git symbolic-ref HEAD >expect &&
219
+ echo refs/heads/lonely >actual &&
220
+ test_cmp expect actual &&
221
test_ref_missing refs/head/lonely &&
222
git branch -M main mistress &&
221
- grep lonely .git/HEAD
223
+ git symbolic-ref HEAD >expect &&
224
+ test_cmp expect actual
225
)
226
'
227
@@ -809,7 +812,7 @@ test_expect_success 'deleting a symref' '
812
813
test_expect_success 'deleting a dangling symref' '
814
git symbolic-ref refs/heads/dangling-symref nowhere &&
812
- test_path_is_file .git/refs/heads/dangling-symref &&
815
+ git symbolic-ref --no-recurse refs/heads/dangling-symref &&
816
echo "Deleted branch dangling-symref (was nowhere)." >expect &&
817
git branch -d dangling-symref >actual &&
818
test_ref_missing refs/heads/dangling-symref &&
t/t4013-diff-various.sh
+1
-1
@@ -522,7 +522,7 @@ test_expect_success 'log -S requires an argument' '
522
'
523
524
test_expect_success 'diff --cached on unborn branch' '
525
- echo ref: refs/heads/unborn >.git/HEAD &&
525
+ git symbolic-ref HEAD refs/heads/unborn &&
526
git diff --cached >result &&
527
process_diffs result >actual &&
528
process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
t/t4202-log.sh
+1
-1
@@ -2265,7 +2265,7 @@ test_expect_success REFFILES 'log diagnoses bogus HEAD hash' '
2265
2266
test_expect_success REFFILES 'log diagnoses bogus HEAD symref' '
2267
git init empty &&
2268
- echo "ref: refs/heads/invalid.lock" > empty/.git/HEAD &&
2268
+ test-tool -C empty ref-store main create-symref HEAD refs/heads/invalid.lock &&
2269
test_must_fail git -C empty log 2>stderr &&
2270
test_i18ngrep broken stderr &&
2271
test_must_fail git -C empty log --default totally-bogus 2>stderr &&
t/t5605-clone-local.sh
+1
-1
@@ -65,7 +65,7 @@ test_expect_success 'Even without -l, local will make a hardlink' '
65
'
66
67
test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
68
- echo "ref: refs/heads/nonexistent" > a.git/HEAD &&
68
+ git -C a.git symbolic-ref HEAD refs/heads/nonexistent &&
69
git clone a d &&
70
(cd d &&
71
git fetch &&
t/t5702-protocol-v2.sh
+18
-6
@@ -221,7 +221,9 @@ test_expect_success 'clone of empty repo propagates name of default branch' '
221
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
222
git -c init.defaultBranch=main -c protocol.version=2 \
223
clone "file://$(pwd)/file_empty_parent" file_empty_child &&
224
- grep "refs/heads/mydefaultbranch" file_empty_child/.git/HEAD
224
+ echo refs/heads/mydefaultbranch >expect &&
225
+ git -C file_empty_child symbolic-ref HEAD >actual &&
226
+ test_cmp expect actual
227
'
228
229
test_expect_success '...but not if explicitly forbidden by config' '
@@ -234,7 +236,9 @@ test_expect_success '...but not if explicitly forbidden by config' '
236
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
237
git -c init.defaultBranch=main -c protocol.version=2 \
238
clone "file://$(pwd)/file_empty_parent" file_empty_child &&
237
- ! grep "refs/heads/mydefaultbranch" file_empty_child/.git/HEAD
239
+ echo refs/heads/main >expect &&
240
+ git -C file_empty_child symbolic-ref HEAD >actual &&
241
+ test_cmp expect actual
242
'
243
244
test_expect_success 'bare clone propagates empty default branch' '
@@ -247,7 +251,9 @@ test_expect_success 'bare clone propagates empty default branch' '
251
git -c init.defaultBranch=main -c protocol.version=2 \
252
clone --bare \
253
"file://$(pwd)/file_empty_parent" file_empty_child.git &&
250
- grep "refs/heads/mydefaultbranch" file_empty_child.git/HEAD
254
+ echo "refs/heads/mydefaultbranch" >expect &&
255
+ git -C file_empty_child.git symbolic-ref HEAD >actual &&
256
+ test_cmp expect actual
257
'
258
259
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' '
271
git -c init.defaultBranch=main -c protocol.version=2 \
272
clone "file://$(pwd)/file_unborn_parent" \
273
file_unborn_child 2>stderr &&
268
- grep "refs/heads/mydefaultbranch" file_unborn_child/.git/HEAD &&
274
+ echo "refs/heads/mydefaultbranch" >expect &&
275
+ git -C file_unborn_child symbolic-ref HEAD >actual &&
276
+ test_cmp expect actual &&
277
grep "warning: remote HEAD refers to nonexistent ref" stderr
278
'
279
@@ -295,7 +303,9 @@ test_expect_success 'bare clone propagates unborn HEAD from non-empty repo' '
303
git -c init.defaultBranch=main -c protocol.version=2 \
304
clone --bare "file://$(pwd)/file_unborn_parent" \
305
file_unborn_child.git 2>stderr &&
298
- grep "refs/heads/mydefaultbranch" file_unborn_child.git/HEAD &&
306
+ echo "refs/heads/mydefaultbranch" >expect &&
307
+ git -C file_unborn_child.git symbolic-ref HEAD >actual &&
308
+ test_cmp expect actual &&
309
! grep "warning:" stderr
310
'
311
@@ -315,7 +325,9 @@ test_expect_success 'defaulted HEAD uses remote branch if available' '
325
git -c init.defaultBranch=branchwithstuff -c protocol.version=2 \
326
clone "file://$(pwd)/file_unborn_parent" \
327
file_unborn_child 2>stderr &&
318
- grep "refs/heads/branchwithstuff" file_unborn_child/.git/HEAD &&
328
+ echo "refs/heads/branchwithstuff" >expect &&
329
+ git -C file_unborn_child symbolic-ref HEAD >actual &&
330
+ test_cmp expect actual &&
331
test_path_is_file file_unborn_child/stuff.t &&
332
! grep "warning:" stderr
333
'
t/t9133-git-svn-nested-git-repo.sh
+1
-1
@@ -11,7 +11,7 @@ test_expect_success 'setup repo with a git repo inside it' '
11
(
12
cd s &&
13
git init &&
14
- test -f .git/HEAD &&
14
+ git symbolic-ref HEAD &&
15
> .git/a &&
16
echo a > a &&
17
svn_cmd add .git a &&