Skip to content

Commit 2393711

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1c6667c commit 2393711

9 files changed

+40
-25
lines changed

t/t1400-update-ref.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,15 @@ test_expect_success 'delete symref without dereference when the referred ref is
221221
test_expect_success 'update-ref -d is not confused by self-reference' '
222222
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" &&
223223
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 &&
225225
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
227227
'
228228

229229
test_expect_success 'update-ref --no-deref -d can delete self-reference' '
230230
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" &&
231231
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 &&
233233
git update-ref --no-deref -d refs/heads/self &&
234234
test_must_fail git show-ref --verify -q refs/heads/self
235235
'
@@ -239,7 +239,7 @@ test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
239239
test_when_finished "rm -f .git/refs/heads/bad" &&
240240
git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
241241
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 &&
243243
git update-ref --no-deref -d refs/heads/ref-to-bad &&
244244
test_must_fail git show-ref --verify -q refs/heads/ref-to-bad
245245
'

t/t1430-bad-ref-name.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ test_expect_success 'rev-parse skips symref pointing to broken name' '
164164
test_expect_success 'for-each-ref emits warnings for broken names' '
165165
test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION &&
166166
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 &&
168168
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 &&
170170
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
171171
git for-each-ref >output 2>error &&
172172
! grep -e "broken\.\.\.ref" output &&
@@ -257,7 +257,7 @@ test_expect_success 'update-ref -d can delete broken name through symref' '
257257
'
258258

259259
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 &&
261261
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
262262
test_ref_exists refs/heads/broken...symref &&
263263
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
267267
'
268268

269269
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 &&
271271
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
272272
test_ref_exists refs/heads/broken...symref &&
273273
git branch -d broken...symref >output 2>error &&
@@ -277,7 +277,7 @@ test_expect_success 'branch -d can delete symref with broken name' '
277277
'
278278

279279
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 &&
281281
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
282282
test_ref_exists refs/heads/broken...symref &&
283283
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
287287
'
288288

289289
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 &&
291291
test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" &&
292292
test_ref_exists refs/heads/broken...symref &&
293293
git branch -d broken...symref >output 2>error &&

t/t1450-fsck.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ test_expect_success 'HEAD link pointing at a funny object' '
133133

134134
test_expect_success 'HEAD link pointing at a funny place' '
135135
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 &&
137137
# avoid corrupt/broken HEAD from interfering with repo discovery
138138
test_must_fail env GIT_DIR=.git git fsck 2>out &&
139139
test_i18ngrep "HEAD points to something strange" out
@@ -169,7 +169,7 @@ test_expect_success 'other worktree HEAD link pointing at missing object' '
169169
test_expect_success 'other worktree HEAD link pointing at a funny place' '
170170
test_when_finished "rm -rf .git/worktrees other" &&
171171
git worktree add other &&
172-
echo "ref: refs/funny/place" >.git/worktrees/other/HEAD &&
172+
git -C other symbolic-ref HEAD refs/funny/place &&
173173
test_must_fail git fsck 2>out &&
174174
test_i18ngrep "worktrees/other/HEAD points to something strange" out
175175
'

t/t3200-branch.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,13 @@ test_expect_success 'git branch -M should leave orphaned HEAD alone' '
215215
cd orphan &&
216216
test_commit initial &&
217217
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 &&
219221
test_ref_missing refs/head/lonely &&
220222
git branch -M main mistress &&
221-
grep lonely .git/HEAD
223+
git symbolic-ref HEAD >expect &&
224+
test_cmp expect actual
222225
)
223226
'
224227

@@ -809,7 +812,7 @@ test_expect_success 'deleting a symref' '
809812

810813
test_expect_success 'deleting a dangling symref' '
811814
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 &&
813816
echo "Deleted branch dangling-symref (was nowhere)." >expect &&
814817
git branch -d dangling-symref >actual &&
815818
test_ref_missing refs/heads/dangling-symref &&

t/t4013-diff-various.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ test_expect_success 'log -S requires an argument' '
522522
'
523523

524524
test_expect_success 'diff --cached on unborn branch' '
525-
echo ref: refs/heads/unborn >.git/HEAD &&
525+
git symbolic-ref HEAD refs/heads/unborn &&
526526
git diff --cached >result &&
527527
process_diffs result >actual &&
528528
process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&

t/t4202-log.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,7 @@ test_expect_success REFFILES 'log diagnoses bogus HEAD hash' '
22652265

22662266
test_expect_success REFFILES 'log diagnoses bogus HEAD symref' '
22672267
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 &&
22692269
test_must_fail git -C empty log 2>stderr &&
22702270
test_i18ngrep broken stderr &&
22712271
test_must_fail git -C empty log --default totally-bogus 2>stderr &&

t/t5605-clone-local.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test_expect_success 'Even without -l, local will make a hardlink' '
6565
'
6666

6767
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 &&
6969
git clone a d &&
7070
(cd d &&
7171
git fetch &&

t/t5702-protocol-v2.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ test_expect_success 'clone of empty repo propagates name of default branch' '
221221
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
222222
git -c init.defaultBranch=main -c protocol.version=2 \
223223
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
225227
'
226228

227229
test_expect_success '...but not if explicitly forbidden by config' '
@@ -234,7 +236,9 @@ test_expect_success '...but not if explicitly forbidden by config' '
234236
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \
235237
git -c init.defaultBranch=main -c protocol.version=2 \
236238
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
238242
'
239243

240244
test_expect_success 'bare clone propagates empty default branch' '
@@ -247,7 +251,9 @@ test_expect_success 'bare clone propagates empty default branch' '
247251
git -c init.defaultBranch=main -c protocol.version=2 \
248252
clone --bare \
249253
"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
251257
'
252258

253259
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' '
265271
git -c init.defaultBranch=main -c protocol.version=2 \
266272
clone "file://$(pwd)/file_unborn_parent" \
267273
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 &&
269277
grep "warning: remote HEAD refers to nonexistent ref" stderr
270278
'
271279

@@ -295,7 +303,9 @@ test_expect_success 'bare clone propagates unborn HEAD from non-empty repo' '
295303
git -c init.defaultBranch=main -c protocol.version=2 \
296304
clone --bare "file://$(pwd)/file_unborn_parent" \
297305
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 &&
299309
! grep "warning:" stderr
300310
'
301311

@@ -315,7 +325,9 @@ test_expect_success 'defaulted HEAD uses remote branch if available' '
315325
git -c init.defaultBranch=branchwithstuff -c protocol.version=2 \
316326
clone "file://$(pwd)/file_unborn_parent" \
317327
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 &&
319331
test_path_is_file file_unborn_child/stuff.t &&
320332
! grep "warning:" stderr
321333
'

t/t9133-git-svn-nested-git-repo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test_expect_success 'setup repo with a git repo inside it' '
1111
(
1212
cd s &&
1313
git init &&
14-
test -f .git/HEAD &&
14+
git symbolic-ref HEAD &&
1515
> .git/a &&
1616
echo a > a &&
1717
svn_cmd add .git a &&

0 commit comments

Comments
 (0)