Git fork

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>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
23937116 1c6667cb

+40 -25
+4 -4
t/t1400-update-ref.sh
··· 221 221 test_expect_success 'update-ref -d is not confused by self-reference' ' 222 222 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" && 223 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 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 227 ' 228 228 229 229 test_expect_success 'update-ref --no-deref -d can delete self-reference' ' 230 230 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" && 231 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 233 git update-ref --no-deref -d refs/heads/self && 234 234 test_must_fail git show-ref --verify -q refs/heads/self 235 235 ' ··· 239 239 test_when_finished "rm -f .git/refs/heads/bad" && 240 240 git symbolic-ref refs/heads/ref-to-bad refs/heads/bad && 241 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 243 git update-ref --no-deref -d refs/heads/ref-to-bad && 244 244 test_must_fail git show-ref --verify -q refs/heads/ref-to-bad 245 245 '
+6 -6
t/t1430-bad-ref-name.sh
··· 164 164 test_expect_success 'for-each-ref emits warnings for broken names' ' 165 165 test-tool ref-store main update-ref msg "refs/heads/broken...ref" $main_sha1 $ZERO_OID REF_SKIP_REFNAME_VERIFICATION && 166 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 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 170 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && 171 171 git for-each-ref >output 2>error && 172 172 ! grep -e "broken\.\.\.ref" output && ··· 257 257 ' 258 258 259 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 261 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && 262 262 test_ref_exists refs/heads/broken...symref && 263 263 git update-ref --no-deref -d refs/heads/broken...symref >output 2>error && ··· 267 267 ' 268 268 269 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 271 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && 272 272 test_ref_exists refs/heads/broken...symref && 273 273 git branch -d broken...symref >output 2>error && ··· 277 277 ' 278 278 279 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 281 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && 282 282 test_ref_exists refs/heads/broken...symref && 283 283 git update-ref --no-deref -d refs/heads/broken...symref >output 2>error && ··· 287 287 ' 288 288 289 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 291 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF msg refs/heads/broken...symref" && 292 292 test_ref_exists refs/heads/broken...symref && 293 293 git branch -d broken...symref >output 2>error &&
+2 -2
t/t1450-fsck.sh
··· 133 133 134 134 test_expect_success 'HEAD link pointing at a funny place' ' 135 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 137 # avoid corrupt/broken HEAD from interfering with repo discovery 138 138 test_must_fail env GIT_DIR=.git git fsck 2>out && 139 139 test_i18ngrep "HEAD points to something strange" out ··· 169 169 test_expect_success 'other worktree HEAD link pointing at a funny place' ' 170 170 test_when_finished "rm -rf .git/worktrees other" && 171 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 173 test_must_fail git fsck 2>out && 174 174 test_i18ngrep "worktrees/other/HEAD points to something strange" out 175 175 '
+6 -3
t/t3200-branch.sh
··· 215 215 cd orphan && 216 216 test_commit initial && 217 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 && 219 221 test_ref_missing refs/head/lonely && 220 222 git branch -M main mistress && 221 - grep lonely .git/HEAD 223 + git symbolic-ref HEAD >expect && 224 + test_cmp expect actual 222 225 ) 223 226 ' 224 227 ··· 809 812 810 813 test_expect_success 'deleting a dangling symref' ' 811 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 && 813 816 echo "Deleted branch dangling-symref (was nowhere)." >expect && 814 817 git branch -d dangling-symref >actual && 815 818 test_ref_missing refs/heads/dangling-symref &&
+1 -1
t/t4013-diff-various.sh
··· 522 522 ' 523 523 524 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 526 git diff --cached >result && 527 527 process_diffs result >actual && 528 528 process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
+1 -1
t/t4202-log.sh
··· 2265 2265 2266 2266 test_expect_success REFFILES 'log diagnoses bogus HEAD symref' ' 2267 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 2269 test_must_fail git -C empty log 2>stderr && 2270 2270 test_i18ngrep broken stderr && 2271 2271 test_must_fail git -C empty log --default totally-bogus 2>stderr &&
+1 -1
t/t5605-clone-local.sh
··· 65 65 ' 66 66 67 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 69 git clone a d && 70 70 (cd d && 71 71 git fetch &&
+18 -6
t/t5702-protocol-v2.sh
··· 221 221 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ 222 222 git -c init.defaultBranch=main -c protocol.version=2 \ 223 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 225 227 ' 226 228 227 229 test_expect_success '...but not if explicitly forbidden by config' ' ··· 234 236 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME= \ 235 237 git -c init.defaultBranch=main -c protocol.version=2 \ 236 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 238 242 ' 239 243 240 244 test_expect_success 'bare clone propagates empty default branch' ' ··· 247 251 git -c init.defaultBranch=main -c protocol.version=2 \ 248 252 clone --bare \ 249 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 251 257 ' 252 258 253 259 test_expect_success 'clone propagates unborn HEAD from non-empty repo' ' ··· 265 271 git -c init.defaultBranch=main -c protocol.version=2 \ 266 272 clone "file://$(pwd)/file_unborn_parent" \ 267 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 && 269 277 grep "warning: remote HEAD refers to nonexistent ref" stderr 270 278 ' 271 279 ··· 295 303 git -c init.defaultBranch=main -c protocol.version=2 \ 296 304 clone --bare "file://$(pwd)/file_unborn_parent" \ 297 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 && 299 309 ! grep "warning:" stderr 300 310 ' 301 311 ··· 315 325 git -c init.defaultBranch=branchwithstuff -c protocol.version=2 \ 316 326 clone "file://$(pwd)/file_unborn_parent" \ 317 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 && 319 331 test_path_is_file file_unborn_child/stuff.t && 320 332 ! grep "warning:" stderr 321 333 '
+1 -1
t/t9133-git-svn-nested-git-repo.sh
··· 11 11 ( 12 12 cd s && 13 13 git init && 14 - test -f .git/HEAD && 14 + git symbolic-ref HEAD && 15 15 > .git/a && 16 16 echo a > a && 17 17 svn_cmd add .git a &&