Git fork

t0602: use subshell to ensure working directory unchanged

For every test, we would execute the command "cd repo" in the first but
we never execute the command "cd .." to restore the working directory.
However, it's either not a good idea use above way. Because if any test
fails between "cd repo" and "cd ..", the "cd .." will never be reached.
And we cannot correctly restore the working directory.

Let's use subshell to ensure that the current working directory could be
restored to the correct path.

Mentored-by: Patrick Steinhardt <ps@pks.im>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: shejialuo <shejialuo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

shejialuo and committed by
Junio C Hamano
320f2061 e63e6217

+468 -447
+468 -447
t/t0602-reffiles-fsck.sh
··· 14 git init repo && 15 branch_dir_prefix=.git/refs/heads && 16 tag_dir_prefix=.git/refs/tags && 17 - cd repo && 18 19 - git commit --allow-empty -m initial && 20 - git checkout -b default-branch && 21 - git tag default-tag && 22 - git tag multi_hierarchy/default-tag && 23 24 - cp $branch_dir_prefix/default-branch $branch_dir_prefix/@ && 25 - git refs verify 2>err && 26 - test_must_be_empty err && 27 - rm $branch_dir_prefix/@ && 28 29 - cp $tag_dir_prefix/default-tag $tag_dir_prefix/tag-1.lock && 30 - git refs verify 2>err && 31 - rm $tag_dir_prefix/tag-1.lock && 32 - test_must_be_empty err && 33 - 34 - cp $tag_dir_prefix/default-tag $tag_dir_prefix/.lock && 35 - test_must_fail git refs verify 2>err && 36 - cat >expect <<-EOF && 37 - error: refs/tags/.lock: badRefName: invalid refname format 38 - EOF 39 - rm $tag_dir_prefix/.lock && 40 - test_cmp expect err && 41 42 - for refname in ".refname-starts-with-dot" "~refname-has-stride" 43 - do 44 - cp $branch_dir_prefix/default-branch "$branch_dir_prefix/$refname" && 45 test_must_fail git refs verify 2>err && 46 cat >expect <<-EOF && 47 - error: refs/heads/$refname: badRefName: invalid refname format 48 EOF 49 - rm "$branch_dir_prefix/$refname" && 50 - test_cmp expect err || return 1 51 - done && 52 53 - for refname in ".refname-starts-with-dot" "~refname-has-stride" 54 - do 55 - cp $tag_dir_prefix/default-tag "$tag_dir_prefix/$refname" && 56 - test_must_fail git refs verify 2>err && 57 - cat >expect <<-EOF && 58 - error: refs/tags/$refname: badRefName: invalid refname format 59 - EOF 60 - rm "$tag_dir_prefix/$refname" && 61 - test_cmp expect err || return 1 62 - done && 63 64 - for refname in ".refname-starts-with-dot" "~refname-has-stride" 65 - do 66 - cp $tag_dir_prefix/multi_hierarchy/default-tag "$tag_dir_prefix/multi_hierarchy/$refname" && 67 - test_must_fail git refs verify 2>err && 68 - cat >expect <<-EOF && 69 - error: refs/tags/multi_hierarchy/$refname: badRefName: invalid refname format 70 - EOF 71 - rm "$tag_dir_prefix/multi_hierarchy/$refname" && 72 - test_cmp expect err || return 1 73 - done && 74 75 - for refname in ".refname-starts-with-dot" "~refname-has-stride" 76 - do 77 - mkdir "$branch_dir_prefix/$refname" && 78 - cp $branch_dir_prefix/default-branch "$branch_dir_prefix/$refname/default-branch" && 79 - test_must_fail git refs verify 2>err && 80 - cat >expect <<-EOF && 81 - error: refs/heads/$refname/default-branch: badRefName: invalid refname format 82 - EOF 83 - rm -r "$branch_dir_prefix/$refname" && 84 - test_cmp expect err || return 1 85 - done 86 ' 87 88 test_expect_success 'ref name check should be adapted into fsck messages' ' 89 test_when_finished "rm -rf repo" && 90 git init repo && 91 branch_dir_prefix=.git/refs/heads && 92 - cd repo && 93 - git commit --allow-empty -m initial && 94 - git checkout -b branch-1 && 95 96 - cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && 97 - git -c fsck.badRefName=warn refs verify 2>err && 98 - cat >expect <<-EOF && 99 - warning: refs/heads/.branch-1: badRefName: invalid refname format 100 - EOF 101 - rm $branch_dir_prefix/.branch-1 && 102 - test_cmp expect err && 103 104 - cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && 105 - git -c fsck.badRefName=ignore refs verify 2>err && 106 - test_must_be_empty err 107 ' 108 109 test_expect_success 'ref name check should work for multiple worktrees' ' 110 test_when_finished "rm -rf repo" && 111 git init repo && 112 - 113 - cd repo && 114 - test_commit initial && 115 - git checkout -b branch-1 && 116 - test_commit second && 117 - git checkout -b branch-2 && 118 - test_commit third && 119 - git checkout -b branch-3 && 120 - git worktree add ./worktree-1 branch-1 && 121 - git worktree add ./worktree-2 branch-2 && 122 - worktree1_refdir_prefix=.git/worktrees/worktree-1/refs/worktree && 123 - worktree2_refdir_prefix=.git/worktrees/worktree-2/refs/worktree && 124 - 125 - ( 126 - cd worktree-1 && 127 - git update-ref refs/worktree/branch-4 refs/heads/branch-3 128 - ) && 129 ( 130 - cd worktree-2 && 131 - git update-ref refs/worktree/branch-4 refs/heads/branch-3 132 - ) && 133 134 - cp $worktree1_refdir_prefix/branch-4 $worktree1_refdir_prefix/'\'' branch-5'\'' && 135 - cp $worktree2_refdir_prefix/branch-4 $worktree2_refdir_prefix/'\''~branch-6'\'' && 136 137 - test_must_fail git refs verify 2>err && 138 - cat >expect <<-EOF && 139 - error: worktrees/worktree-1/refs/worktree/ branch-5: badRefName: invalid refname format 140 - error: worktrees/worktree-2/refs/worktree/~branch-6: badRefName: invalid refname format 141 - EOF 142 - sort err >sorted_err && 143 - test_cmp expect sorted_err && 144 145 - for worktree in "worktree-1" "worktree-2" 146 - do 147 - ( 148 - cd $worktree && 149 - test_must_fail git refs verify 2>err && 150 - cat >expect <<-EOF && 151 - error: worktrees/worktree-1/refs/worktree/ branch-5: badRefName: invalid refname format 152 - error: worktrees/worktree-2/refs/worktree/~branch-6: badRefName: invalid refname format 153 - EOF 154 - sort err >sorted_err && 155 - test_cmp expect sorted_err || return 1 156 - ) 157 - done 158 ' 159 160 test_expect_success 'regular ref content should be checked (individual)' ' 161 test_when_finished "rm -rf repo" && 162 git init repo && 163 branch_dir_prefix=.git/refs/heads && 164 - cd repo && 165 - test_commit default && 166 - mkdir -p "$branch_dir_prefix/a/b" && 167 168 - git refs verify 2>err && 169 - test_must_be_empty err && 170 171 - for bad_content in "$(git rev-parse main)x" "xfsazqfxcadas" "Xfsazqfxcadas" 172 - do 173 - printf "%s" $bad_content >$branch_dir_prefix/branch-bad && 174 - test_must_fail git refs verify 2>err && 175 - cat >expect <<-EOF && 176 - error: refs/heads/branch-bad: badRefContent: $bad_content 177 - EOF 178 - rm $branch_dir_prefix/branch-bad && 179 - test_cmp expect err || return 1 180 - done && 181 182 - for bad_content in "$(git rev-parse main)x" "xfsazqfxcadas" "Xfsazqfxcadas" 183 - do 184 - printf "%s" $bad_content >$branch_dir_prefix/a/b/branch-bad && 185 - test_must_fail git refs verify 2>err && 186 cat >expect <<-EOF && 187 - error: refs/heads/a/b/branch-bad: badRefContent: $bad_content 188 EOF 189 - rm $branch_dir_prefix/a/b/branch-bad && 190 - test_cmp expect err || return 1 191 - done && 192 193 - printf "%s" "$(git rev-parse main)" >$branch_dir_prefix/branch-no-newline && 194 - git refs verify 2>err && 195 - cat >expect <<-EOF && 196 - warning: refs/heads/branch-no-newline: refMissingNewline: misses LF at the end 197 - EOF 198 - rm $branch_dir_prefix/branch-no-newline && 199 - test_cmp expect err && 200 201 - for trailing_content in " garbage" " more garbage" 202 - do 203 - printf "%s" "$(git rev-parse main)$trailing_content" >$branch_dir_prefix/branch-garbage && 204 git refs verify 2>err && 205 cat >expect <<-EOF && 206 - warning: refs/heads/branch-garbage: trailingRefContent: has trailing garbage: '\''$trailing_content'\'' 207 - EOF 208 - rm $branch_dir_prefix/branch-garbage && 209 - test_cmp expect err || return 1 210 - done && 211 212 - printf "%s\n\n\n" "$(git rev-parse main)" >$branch_dir_prefix/branch-garbage-special && 213 - git refs verify 2>err && 214 - cat >expect <<-EOF && 215 - warning: refs/heads/branch-garbage-special: trailingRefContent: has trailing garbage: '\'' 216 217 - 218 - '\'' 219 - EOF 220 - rm $branch_dir_prefix/branch-garbage-special && 221 - test_cmp expect err && 222 223 - printf "%s\n\n\n garbage" "$(git rev-parse main)" >$branch_dir_prefix/branch-garbage-special && 224 - git refs verify 2>err && 225 - cat >expect <<-EOF && 226 - warning: refs/heads/branch-garbage-special: trailingRefContent: has trailing garbage: '\'' 227 228 229 - garbage'\'' 230 - EOF 231 - rm $branch_dir_prefix/branch-garbage-special && 232 - test_cmp expect err 233 ' 234 235 test_expect_success 'regular ref content should be checked (aggregate)' ' ··· 237 git init repo && 238 branch_dir_prefix=.git/refs/heads && 239 tag_dir_prefix=.git/refs/tags && 240 - cd repo && 241 - test_commit default && 242 - mkdir -p "$branch_dir_prefix/a/b" && 243 244 - bad_content_1=$(git rev-parse main)x && 245 - bad_content_2=xfsazqfxcadas && 246 - bad_content_3=Xfsazqfxcadas && 247 - printf "%s" $bad_content_1 >$tag_dir_prefix/tag-bad-1 && 248 - printf "%s" $bad_content_2 >$tag_dir_prefix/tag-bad-2 && 249 - printf "%s" $bad_content_3 >$branch_dir_prefix/a/b/branch-bad && 250 - printf "%s" "$(git rev-parse main)" >$branch_dir_prefix/branch-no-newline && 251 - printf "%s garbage" "$(git rev-parse main)" >$branch_dir_prefix/branch-garbage && 252 253 - test_must_fail git refs verify 2>err && 254 - cat >expect <<-EOF && 255 - error: refs/heads/a/b/branch-bad: badRefContent: $bad_content_3 256 - error: refs/tags/tag-bad-1: badRefContent: $bad_content_1 257 - error: refs/tags/tag-bad-2: badRefContent: $bad_content_2 258 - warning: refs/heads/branch-garbage: trailingRefContent: has trailing garbage: '\'' garbage'\'' 259 - warning: refs/heads/branch-no-newline: refMissingNewline: misses LF at the end 260 - EOF 261 - sort err >sorted_err && 262 - test_cmp expect sorted_err 263 ' 264 265 test_expect_success 'textual symref content should be checked (individual)' ' 266 test_when_finished "rm -rf repo" && 267 git init repo && 268 branch_dir_prefix=.git/refs/heads && 269 - cd repo && 270 - test_commit default && 271 - mkdir -p "$branch_dir_prefix/a/b" && 272 273 - for good_referent in "refs/heads/branch" "HEAD" 274 - do 275 - printf "ref: %s\n" $good_referent >$branch_dir_prefix/branch-good && 276 git refs verify 2>err && 277 - rm $branch_dir_prefix/branch-good && 278 - test_must_be_empty err || return 1 279 - done && 280 281 - for bad_referent in "refs/heads/.branch" "refs/heads/~branch" "refs/heads/?branch" 282 - do 283 - printf "ref: %s\n" $bad_referent >$branch_dir_prefix/branch-bad && 284 - test_must_fail git refs verify 2>err && 285 cat >expect <<-EOF && 286 - error: refs/heads/branch-bad: badReferentName: points to invalid refname '\''$bad_referent'\'' 287 EOF 288 - rm $branch_dir_prefix/branch-bad && 289 - test_cmp expect err || return 1 290 - done && 291 292 - printf "ref: refs/heads/branch" >$branch_dir_prefix/branch-no-newline && 293 - git refs verify 2>err && 294 - cat >expect <<-EOF && 295 - warning: refs/heads/branch-no-newline: refMissingNewline: misses LF at the end 296 - EOF 297 - rm $branch_dir_prefix/branch-no-newline && 298 - test_cmp expect err && 299 300 - printf "ref: refs/heads/branch " >$branch_dir_prefix/a/b/branch-trailing-1 && 301 - git refs verify 2>err && 302 - cat >expect <<-EOF && 303 - warning: refs/heads/a/b/branch-trailing-1: refMissingNewline: misses LF at the end 304 - warning: refs/heads/a/b/branch-trailing-1: trailingRefContent: has trailing whitespaces or newlines 305 - EOF 306 - rm $branch_dir_prefix/a/b/branch-trailing-1 && 307 - test_cmp expect err && 308 309 - printf "ref: refs/heads/branch\n\n" >$branch_dir_prefix/a/b/branch-trailing-2 && 310 - git refs verify 2>err && 311 - cat >expect <<-EOF && 312 - warning: refs/heads/a/b/branch-trailing-2: trailingRefContent: has trailing whitespaces or newlines 313 - EOF 314 - rm $branch_dir_prefix/a/b/branch-trailing-2 && 315 - test_cmp expect err && 316 - 317 - printf "ref: refs/heads/branch \n" >$branch_dir_prefix/a/b/branch-trailing-3 && 318 - git refs verify 2>err && 319 - cat >expect <<-EOF && 320 - warning: refs/heads/a/b/branch-trailing-3: trailingRefContent: has trailing whitespaces or newlines 321 - EOF 322 - rm $branch_dir_prefix/a/b/branch-trailing-3 && 323 - test_cmp expect err && 324 - 325 - printf "ref: refs/heads/branch \n " >$branch_dir_prefix/a/b/branch-complicated && 326 - git refs verify 2>err && 327 - cat >expect <<-EOF && 328 - warning: refs/heads/a/b/branch-complicated: refMissingNewline: misses LF at the end 329 - warning: refs/heads/a/b/branch-complicated: trailingRefContent: has trailing whitespaces or newlines 330 - EOF 331 - rm $branch_dir_prefix/a/b/branch-complicated && 332 - test_cmp expect err 333 ' 334 335 test_expect_success 'textual symref content should be checked (aggregate)' ' ··· 337 git init repo && 338 branch_dir_prefix=.git/refs/heads && 339 tag_dir_prefix=.git/refs/tags && 340 - cd repo && 341 - test_commit default && 342 - mkdir -p "$branch_dir_prefix/a/b" && 343 344 - printf "ref: refs/heads/branch\n" >$branch_dir_prefix/branch-good && 345 - printf "ref: HEAD\n" >$branch_dir_prefix/branch-head && 346 - printf "ref: refs/heads/branch" >$branch_dir_prefix/branch-no-newline-1 && 347 - printf "ref: refs/heads/branch " >$branch_dir_prefix/a/b/branch-trailing-1 && 348 - printf "ref: refs/heads/branch\n\n" >$branch_dir_prefix/a/b/branch-trailing-2 && 349 - printf "ref: refs/heads/branch \n" >$branch_dir_prefix/a/b/branch-trailing-3 && 350 - printf "ref: refs/heads/branch \n " >$branch_dir_prefix/a/b/branch-complicated && 351 - printf "ref: refs/heads/.branch\n" >$branch_dir_prefix/branch-bad-1 && 352 353 - test_must_fail git refs verify 2>err && 354 - cat >expect <<-EOF && 355 - error: refs/heads/branch-bad-1: badReferentName: points to invalid refname '\''refs/heads/.branch'\'' 356 - warning: refs/heads/a/b/branch-complicated: refMissingNewline: misses LF at the end 357 - warning: refs/heads/a/b/branch-complicated: trailingRefContent: has trailing whitespaces or newlines 358 - warning: refs/heads/a/b/branch-trailing-1: refMissingNewline: misses LF at the end 359 - warning: refs/heads/a/b/branch-trailing-1: trailingRefContent: has trailing whitespaces or newlines 360 - warning: refs/heads/a/b/branch-trailing-2: trailingRefContent: has trailing whitespaces or newlines 361 - warning: refs/heads/a/b/branch-trailing-3: trailingRefContent: has trailing whitespaces or newlines 362 - warning: refs/heads/branch-no-newline-1: refMissingNewline: misses LF at the end 363 - EOF 364 - sort err >sorted_err && 365 - test_cmp expect sorted_err 366 ' 367 368 test_expect_success 'the target of the textual symref should be checked' ' ··· 370 git init repo && 371 branch_dir_prefix=.git/refs/heads && 372 tag_dir_prefix=.git/refs/tags && 373 - cd repo && 374 - test_commit default && 375 - mkdir -p "$branch_dir_prefix/a/b" && 376 377 - for good_referent in "refs/heads/branch" "HEAD" "refs/tags/tag" 378 - do 379 - printf "ref: %s\n" $good_referent >$branch_dir_prefix/branch-good && 380 - git refs verify 2>err && 381 - rm $branch_dir_prefix/branch-good && 382 - test_must_be_empty err || return 1 383 - done && 384 385 - for nonref_referent in "refs-back/heads/branch" "refs-back/tags/tag" "reflogs/refs/heads/branch" 386 - do 387 - printf "ref: %s\n" $nonref_referent >$branch_dir_prefix/branch-bad-1 && 388 - git refs verify 2>err && 389 - cat >expect <<-EOF && 390 - warning: refs/heads/branch-bad-1: symrefTargetIsNotARef: points to non-ref target '\''$nonref_referent'\'' 391 - EOF 392 - rm $branch_dir_prefix/branch-bad-1 && 393 - test_cmp expect err || return 1 394 - done 395 ' 396 397 test_expect_success SYMLINKS 'symlink symref content should be checked' ' ··· 399 git init repo && 400 branch_dir_prefix=.git/refs/heads && 401 tag_dir_prefix=.git/refs/tags && 402 - cd repo && 403 - test_commit default && 404 - mkdir -p "$branch_dir_prefix/a/b" && 405 406 - ln -sf ./main $branch_dir_prefix/branch-symbolic-good && 407 - git refs verify 2>err && 408 - cat >expect <<-EOF && 409 - warning: refs/heads/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref 410 - EOF 411 - rm $branch_dir_prefix/branch-symbolic-good && 412 - test_cmp expect err && 413 414 - ln -sf ../../logs/branch-escape $branch_dir_prefix/branch-symbolic && 415 - git refs verify 2>err && 416 - cat >expect <<-EOF && 417 - warning: refs/heads/branch-symbolic: symlinkRef: use deprecated symbolic link for symref 418 - warning: refs/heads/branch-symbolic: symrefTargetIsNotARef: points to non-ref target '\''logs/branch-escape'\'' 419 - EOF 420 - rm $branch_dir_prefix/branch-symbolic && 421 - test_cmp expect err && 422 423 - ln -sf ./"branch " $branch_dir_prefix/branch-symbolic-bad && 424 - test_must_fail git refs verify 2>err && 425 - cat >expect <<-EOF && 426 - warning: refs/heads/branch-symbolic-bad: symlinkRef: use deprecated symbolic link for symref 427 - error: refs/heads/branch-symbolic-bad: badReferentName: points to invalid refname '\''refs/heads/branch '\'' 428 - EOF 429 - rm $branch_dir_prefix/branch-symbolic-bad && 430 - test_cmp expect err && 431 432 - ln -sf ./".tag" $tag_dir_prefix/tag-symbolic-1 && 433 - test_must_fail git refs verify 2>err && 434 - cat >expect <<-EOF && 435 - warning: refs/tags/tag-symbolic-1: symlinkRef: use deprecated symbolic link for symref 436 - error: refs/tags/tag-symbolic-1: badReferentName: points to invalid refname '\''refs/tags/.tag'\'' 437 - EOF 438 - rm $tag_dir_prefix/tag-symbolic-1 && 439 - test_cmp expect err 440 ' 441 442 test_expect_success SYMLINKS 'symlink symref content should be checked (worktree)' ' 443 test_when_finished "rm -rf repo" && 444 git init repo && 445 - cd repo && 446 - test_commit default && 447 - git branch branch-1 && 448 - git branch branch-2 && 449 - git branch branch-3 && 450 - git worktree add ./worktree-1 branch-2 && 451 - git worktree add ./worktree-2 branch-3 && 452 - main_worktree_refdir_prefix=.git/refs/heads && 453 - worktree1_refdir_prefix=.git/worktrees/worktree-1/refs/worktree && 454 - worktree2_refdir_prefix=.git/worktrees/worktree-2/refs/worktree && 455 - 456 ( 457 - cd worktree-1 && 458 - git update-ref refs/worktree/branch-4 refs/heads/branch-1 459 - ) && 460 - ( 461 - cd worktree-2 && 462 - git update-ref refs/worktree/branch-4 refs/heads/branch-1 463 - ) && 464 465 - ln -sf ../../../../refs/heads/good-branch $worktree1_refdir_prefix/branch-symbolic-good && 466 - git refs verify 2>err && 467 - cat >expect <<-EOF && 468 - warning: worktrees/worktree-1/refs/worktree/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref 469 - EOF 470 - rm $worktree1_refdir_prefix/branch-symbolic-good && 471 - test_cmp expect err && 472 473 - ln -sf ../../../../worktrees/worktree-1/good-branch $worktree2_refdir_prefix/branch-symbolic-good && 474 - git refs verify 2>err && 475 - cat >expect <<-EOF && 476 - warning: worktrees/worktree-2/refs/worktree/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref 477 - EOF 478 - rm $worktree2_refdir_prefix/branch-symbolic-good && 479 - test_cmp expect err && 480 - 481 - ln -sf ../../worktrees/worktree-2/good-branch $main_worktree_refdir_prefix/branch-symbolic-good && 482 - git refs verify 2>err && 483 - cat >expect <<-EOF && 484 - warning: refs/heads/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref 485 - EOF 486 - rm $main_worktree_refdir_prefix/branch-symbolic-good && 487 - test_cmp expect err && 488 - 489 - ln -sf ../../../../logs/branch-escape $worktree1_refdir_prefix/branch-symbolic && 490 - git refs verify 2>err && 491 - cat >expect <<-EOF && 492 - warning: worktrees/worktree-1/refs/worktree/branch-symbolic: symlinkRef: use deprecated symbolic link for symref 493 - warning: worktrees/worktree-1/refs/worktree/branch-symbolic: symrefTargetIsNotARef: points to non-ref target '\''logs/branch-escape'\'' 494 - EOF 495 - rm $worktree1_refdir_prefix/branch-symbolic && 496 - test_cmp expect err && 497 - 498 - for bad_referent_name in ".tag" "branch " 499 - do 500 - ln -sf ./"$bad_referent_name" $worktree1_refdir_prefix/bad-symbolic && 501 - test_must_fail git refs verify 2>err && 502 cat >expect <<-EOF && 503 - warning: worktrees/worktree-1/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref 504 - error: worktrees/worktree-1/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''worktrees/worktree-1/refs/worktree/$bad_referent_name'\'' 505 EOF 506 - rm $worktree1_refdir_prefix/bad-symbolic && 507 test_cmp expect err && 508 509 - ln -sf ../../../../refs/heads/"$bad_referent_name" $worktree1_refdir_prefix/bad-symbolic && 510 - test_must_fail git refs verify 2>err && 511 cat >expect <<-EOF && 512 - warning: worktrees/worktree-1/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref 513 - error: worktrees/worktree-1/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''refs/heads/$bad_referent_name'\'' 514 EOF 515 - rm $worktree1_refdir_prefix/bad-symbolic && 516 test_cmp expect err && 517 518 - ln -sf ./"$bad_referent_name" $worktree2_refdir_prefix/bad-symbolic && 519 - test_must_fail git refs verify 2>err && 520 cat >expect <<-EOF && 521 - warning: worktrees/worktree-2/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref 522 - error: worktrees/worktree-2/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''worktrees/worktree-2/refs/worktree/$bad_referent_name'\'' 523 EOF 524 - rm $worktree2_refdir_prefix/bad-symbolic && 525 test_cmp expect err && 526 527 - ln -sf ../../../../refs/heads/"$bad_referent_name" $worktree2_refdir_prefix/bad-symbolic && 528 - test_must_fail git refs verify 2>err && 529 cat >expect <<-EOF && 530 - warning: worktrees/worktree-2/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref 531 - error: worktrees/worktree-2/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''refs/heads/$bad_referent_name'\'' 532 EOF 533 - rm $worktree2_refdir_prefix/bad-symbolic && 534 - test_cmp expect err || return 1 535 - done 536 ' 537 538 test_expect_success 'ref content checks should work with worktrees' ' 539 test_when_finished "rm -rf repo" && 540 git init repo && 541 - cd repo && 542 - test_commit default && 543 - git branch branch-1 && 544 - git branch branch-2 && 545 - git branch branch-3 && 546 - git worktree add ./worktree-1 branch-2 && 547 - git worktree add ./worktree-2 branch-3 && 548 - worktree1_refdir_prefix=.git/worktrees/worktree-1/refs/worktree && 549 - worktree2_refdir_prefix=.git/worktrees/worktree-2/refs/worktree && 550 551 - ( 552 - cd worktree-1 && 553 - git update-ref refs/worktree/branch-4 refs/heads/branch-1 554 - ) && 555 - ( 556 - cd worktree-2 && 557 - git update-ref refs/worktree/branch-4 refs/heads/branch-1 558 - ) && 559 560 - for bad_content in "$(git rev-parse HEAD)x" "xfsazqfxcadas" "Xfsazqfxcadas" 561 - do 562 - printf "%s" $bad_content >$worktree1_refdir_prefix/bad-branch-1 && 563 - test_must_fail git refs verify 2>err && 564 cat >expect <<-EOF && 565 - error: worktrees/worktree-1/refs/worktree/bad-branch-1: badRefContent: $bad_content 566 EOF 567 - rm $worktree1_refdir_prefix/bad-branch-1 && 568 - test_cmp expect err || return 1 569 - done && 570 571 - for bad_content in "$(git rev-parse HEAD)x" "xfsazqfxcadas" "Xfsazqfxcadas" 572 - do 573 - printf "%s" $bad_content >$worktree2_refdir_prefix/bad-branch-2 && 574 - test_must_fail git refs verify 2>err && 575 cat >expect <<-EOF && 576 - error: worktrees/worktree-2/refs/worktree/bad-branch-2: badRefContent: $bad_content 577 EOF 578 - rm $worktree2_refdir_prefix/bad-branch-2 && 579 - test_cmp expect err || return 1 580 - done && 581 - 582 - printf "%s" "$(git rev-parse HEAD)" >$worktree1_refdir_prefix/branch-no-newline && 583 - git refs verify 2>err && 584 - cat >expect <<-EOF && 585 - warning: worktrees/worktree-1/refs/worktree/branch-no-newline: refMissingNewline: misses LF at the end 586 - EOF 587 - rm $worktree1_refdir_prefix/branch-no-newline && 588 - test_cmp expect err && 589 - 590 - printf "%s garbage" "$(git rev-parse HEAD)" >$worktree1_refdir_prefix/branch-garbage && 591 - git refs verify 2>err && 592 - cat >expect <<-EOF && 593 - warning: worktrees/worktree-1/refs/worktree/branch-garbage: trailingRefContent: has trailing garbage: '\'' garbage'\'' 594 - EOF 595 - rm $worktree1_refdir_prefix/branch-garbage && 596 - test_cmp expect err 597 ' 598 599 test_done
··· 14 git init repo && 15 branch_dir_prefix=.git/refs/heads && 16 tag_dir_prefix=.git/refs/tags && 17 + ( 18 + cd repo && 19 20 + git commit --allow-empty -m initial && 21 + git checkout -b default-branch && 22 + git tag default-tag && 23 + git tag multi_hierarchy/default-tag && 24 25 + cp $branch_dir_prefix/default-branch $branch_dir_prefix/@ && 26 + git refs verify 2>err && 27 + test_must_be_empty err && 28 + rm $branch_dir_prefix/@ && 29 30 + cp $tag_dir_prefix/default-tag $tag_dir_prefix/tag-1.lock && 31 + git refs verify 2>err && 32 + rm $tag_dir_prefix/tag-1.lock && 33 + test_must_be_empty err && 34 35 + cp $tag_dir_prefix/default-tag $tag_dir_prefix/.lock && 36 test_must_fail git refs verify 2>err && 37 cat >expect <<-EOF && 38 + error: refs/tags/.lock: badRefName: invalid refname format 39 EOF 40 + rm $tag_dir_prefix/.lock && 41 + test_cmp expect err && 42 + 43 + for refname in ".refname-starts-with-dot" "~refname-has-stride" 44 + do 45 + cp $branch_dir_prefix/default-branch "$branch_dir_prefix/$refname" && 46 + test_must_fail git refs verify 2>err && 47 + cat >expect <<-EOF && 48 + error: refs/heads/$refname: badRefName: invalid refname format 49 + EOF 50 + rm "$branch_dir_prefix/$refname" && 51 + test_cmp expect err || return 1 52 + done && 53 54 + for refname in ".refname-starts-with-dot" "~refname-has-stride" 55 + do 56 + cp $tag_dir_prefix/default-tag "$tag_dir_prefix/$refname" && 57 + test_must_fail git refs verify 2>err && 58 + cat >expect <<-EOF && 59 + error: refs/tags/$refname: badRefName: invalid refname format 60 + EOF 61 + rm "$tag_dir_prefix/$refname" && 62 + test_cmp expect err || return 1 63 + done && 64 65 + for refname in ".refname-starts-with-dot" "~refname-has-stride" 66 + do 67 + cp $tag_dir_prefix/multi_hierarchy/default-tag "$tag_dir_prefix/multi_hierarchy/$refname" && 68 + test_must_fail git refs verify 2>err && 69 + cat >expect <<-EOF && 70 + error: refs/tags/multi_hierarchy/$refname: badRefName: invalid refname format 71 + EOF 72 + rm "$tag_dir_prefix/multi_hierarchy/$refname" && 73 + test_cmp expect err || return 1 74 + done && 75 76 + for refname in ".refname-starts-with-dot" "~refname-has-stride" 77 + do 78 + mkdir "$branch_dir_prefix/$refname" && 79 + cp $branch_dir_prefix/default-branch "$branch_dir_prefix/$refname/default-branch" && 80 + test_must_fail git refs verify 2>err && 81 + cat >expect <<-EOF && 82 + error: refs/heads/$refname/default-branch: badRefName: invalid refname format 83 + EOF 84 + rm -r "$branch_dir_prefix/$refname" && 85 + test_cmp expect err || return 1 86 + done 87 + ) 88 ' 89 90 test_expect_success 'ref name check should be adapted into fsck messages' ' 91 test_when_finished "rm -rf repo" && 92 git init repo && 93 branch_dir_prefix=.git/refs/heads && 94 + ( 95 + cd repo && 96 + git commit --allow-empty -m initial && 97 + git checkout -b branch-1 && 98 99 + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && 100 + git -c fsck.badRefName=warn refs verify 2>err && 101 + cat >expect <<-EOF && 102 + warning: refs/heads/.branch-1: badRefName: invalid refname format 103 + EOF 104 + rm $branch_dir_prefix/.branch-1 && 105 + test_cmp expect err && 106 107 + cp $branch_dir_prefix/branch-1 $branch_dir_prefix/.branch-1 && 108 + git -c fsck.badRefName=ignore refs verify 2>err && 109 + test_must_be_empty err 110 + ) 111 ' 112 113 test_expect_success 'ref name check should work for multiple worktrees' ' 114 test_when_finished "rm -rf repo" && 115 git init repo && 116 ( 117 + cd repo && 118 + test_commit initial && 119 + git checkout -b branch-1 && 120 + test_commit second && 121 + git checkout -b branch-2 && 122 + test_commit third && 123 + git checkout -b branch-3 && 124 + git worktree add ./worktree-1 branch-1 && 125 + git worktree add ./worktree-2 branch-2 && 126 + worktree1_refdir_prefix=.git/worktrees/worktree-1/refs/worktree && 127 + worktree2_refdir_prefix=.git/worktrees/worktree-2/refs/worktree && 128 129 + ( 130 + cd worktree-1 && 131 + git update-ref refs/worktree/branch-4 refs/heads/branch-3 132 + ) && 133 + ( 134 + cd worktree-2 && 135 + git update-ref refs/worktree/branch-4 refs/heads/branch-3 136 + ) && 137 + 138 + cp $worktree1_refdir_prefix/branch-4 $worktree1_refdir_prefix/'\'' branch-5'\'' && 139 + cp $worktree2_refdir_prefix/branch-4 $worktree2_refdir_prefix/'\''~branch-6'\'' && 140 141 + test_must_fail git refs verify 2>err && 142 + cat >expect <<-EOF && 143 + error: worktrees/worktree-1/refs/worktree/ branch-5: badRefName: invalid refname format 144 + error: worktrees/worktree-2/refs/worktree/~branch-6: badRefName: invalid refname format 145 + EOF 146 + sort err >sorted_err && 147 + test_cmp expect sorted_err && 148 149 + for worktree in "worktree-1" "worktree-2" 150 + do 151 + ( 152 + cd $worktree && 153 + test_must_fail git refs verify 2>err && 154 + cat >expect <<-EOF && 155 + error: worktrees/worktree-1/refs/worktree/ branch-5: badRefName: invalid refname format 156 + error: worktrees/worktree-2/refs/worktree/~branch-6: badRefName: invalid refname format 157 + EOF 158 + sort err >sorted_err && 159 + test_cmp expect sorted_err || return 1 160 + ) 161 + done 162 + ) 163 ' 164 165 test_expect_success 'regular ref content should be checked (individual)' ' 166 test_when_finished "rm -rf repo" && 167 git init repo && 168 branch_dir_prefix=.git/refs/heads && 169 + ( 170 + cd repo && 171 + test_commit default && 172 + mkdir -p "$branch_dir_prefix/a/b" && 173 174 + git refs verify 2>err && 175 + test_must_be_empty err && 176 177 + for bad_content in "$(git rev-parse main)x" "xfsazqfxcadas" "Xfsazqfxcadas" 178 + do 179 + printf "%s" $bad_content >$branch_dir_prefix/branch-bad && 180 + test_must_fail git refs verify 2>err && 181 + cat >expect <<-EOF && 182 + error: refs/heads/branch-bad: badRefContent: $bad_content 183 + EOF 184 + rm $branch_dir_prefix/branch-bad && 185 + test_cmp expect err || return 1 186 + done && 187 188 + for bad_content in "$(git rev-parse main)x" "xfsazqfxcadas" "Xfsazqfxcadas" 189 + do 190 + printf "%s" $bad_content >$branch_dir_prefix/a/b/branch-bad && 191 + test_must_fail git refs verify 2>err && 192 + cat >expect <<-EOF && 193 + error: refs/heads/a/b/branch-bad: badRefContent: $bad_content 194 + EOF 195 + rm $branch_dir_prefix/a/b/branch-bad && 196 + test_cmp expect err || return 1 197 + done && 198 + 199 + printf "%s" "$(git rev-parse main)" >$branch_dir_prefix/branch-no-newline && 200 + git refs verify 2>err && 201 cat >expect <<-EOF && 202 + warning: refs/heads/branch-no-newline: refMissingNewline: misses LF at the end 203 EOF 204 + rm $branch_dir_prefix/branch-no-newline && 205 + test_cmp expect err && 206 207 + for trailing_content in " garbage" " more garbage" 208 + do 209 + printf "%s" "$(git rev-parse main)$trailing_content" >$branch_dir_prefix/branch-garbage && 210 + git refs verify 2>err && 211 + cat >expect <<-EOF && 212 + warning: refs/heads/branch-garbage: trailingRefContent: has trailing garbage: '\''$trailing_content'\'' 213 + EOF 214 + rm $branch_dir_prefix/branch-garbage && 215 + test_cmp expect err || return 1 216 + done && 217 218 + printf "%s\n\n\n" "$(git rev-parse main)" >$branch_dir_prefix/branch-garbage-special && 219 git refs verify 2>err && 220 cat >expect <<-EOF && 221 + warning: refs/heads/branch-garbage-special: trailingRefContent: has trailing garbage: '\'' 222 223 224 + '\'' 225 + EOF 226 + rm $branch_dir_prefix/branch-garbage-special && 227 + test_cmp expect err && 228 229 + printf "%s\n\n\n garbage" "$(git rev-parse main)" >$branch_dir_prefix/branch-garbage-special && 230 + git refs verify 2>err && 231 + cat >expect <<-EOF && 232 + warning: refs/heads/branch-garbage-special: trailingRefContent: has trailing garbage: '\'' 233 234 235 + garbage'\'' 236 + EOF 237 + rm $branch_dir_prefix/branch-garbage-special && 238 + test_cmp expect err 239 + ) 240 ' 241 242 test_expect_success 'regular ref content should be checked (aggregate)' ' ··· 244 git init repo && 245 branch_dir_prefix=.git/refs/heads && 246 tag_dir_prefix=.git/refs/tags && 247 + ( 248 + cd repo && 249 + test_commit default && 250 + mkdir -p "$branch_dir_prefix/a/b" && 251 252 + bad_content_1=$(git rev-parse main)x && 253 + bad_content_2=xfsazqfxcadas && 254 + bad_content_3=Xfsazqfxcadas && 255 + printf "%s" $bad_content_1 >$tag_dir_prefix/tag-bad-1 && 256 + printf "%s" $bad_content_2 >$tag_dir_prefix/tag-bad-2 && 257 + printf "%s" $bad_content_3 >$branch_dir_prefix/a/b/branch-bad && 258 + printf "%s" "$(git rev-parse main)" >$branch_dir_prefix/branch-no-newline && 259 + printf "%s garbage" "$(git rev-parse main)" >$branch_dir_prefix/branch-garbage && 260 261 + test_must_fail git refs verify 2>err && 262 + cat >expect <<-EOF && 263 + error: refs/heads/a/b/branch-bad: badRefContent: $bad_content_3 264 + error: refs/tags/tag-bad-1: badRefContent: $bad_content_1 265 + error: refs/tags/tag-bad-2: badRefContent: $bad_content_2 266 + warning: refs/heads/branch-garbage: trailingRefContent: has trailing garbage: '\'' garbage'\'' 267 + warning: refs/heads/branch-no-newline: refMissingNewline: misses LF at the end 268 + EOF 269 + sort err >sorted_err && 270 + test_cmp expect sorted_err 271 + ) 272 ' 273 274 test_expect_success 'textual symref content should be checked (individual)' ' 275 test_when_finished "rm -rf repo" && 276 git init repo && 277 branch_dir_prefix=.git/refs/heads && 278 + ( 279 + cd repo && 280 + test_commit default && 281 + mkdir -p "$branch_dir_prefix/a/b" && 282 283 + for good_referent in "refs/heads/branch" "HEAD" 284 + do 285 + printf "ref: %s\n" $good_referent >$branch_dir_prefix/branch-good && 286 + git refs verify 2>err && 287 + rm $branch_dir_prefix/branch-good && 288 + test_must_be_empty err || return 1 289 + done && 290 + 291 + for bad_referent in "refs/heads/.branch" "refs/heads/~branch" "refs/heads/?branch" 292 + do 293 + printf "ref: %s\n" $bad_referent >$branch_dir_prefix/branch-bad && 294 + test_must_fail git refs verify 2>err && 295 + cat >expect <<-EOF && 296 + error: refs/heads/branch-bad: badReferentName: points to invalid refname '\''$bad_referent'\'' 297 + EOF 298 + rm $branch_dir_prefix/branch-bad && 299 + test_cmp expect err || return 1 300 + done && 301 + 302 + printf "ref: refs/heads/branch" >$branch_dir_prefix/branch-no-newline && 303 git refs verify 2>err && 304 + cat >expect <<-EOF && 305 + warning: refs/heads/branch-no-newline: refMissingNewline: misses LF at the end 306 + EOF 307 + rm $branch_dir_prefix/branch-no-newline && 308 + test_cmp expect err && 309 310 + printf "ref: refs/heads/branch " >$branch_dir_prefix/a/b/branch-trailing-1 && 311 + git refs verify 2>err && 312 cat >expect <<-EOF && 313 + warning: refs/heads/a/b/branch-trailing-1: refMissingNewline: misses LF at the end 314 + warning: refs/heads/a/b/branch-trailing-1: trailingRefContent: has trailing whitespaces or newlines 315 EOF 316 + rm $branch_dir_prefix/a/b/branch-trailing-1 && 317 + test_cmp expect err && 318 319 + printf "ref: refs/heads/branch\n\n" >$branch_dir_prefix/a/b/branch-trailing-2 && 320 + git refs verify 2>err && 321 + cat >expect <<-EOF && 322 + warning: refs/heads/a/b/branch-trailing-2: trailingRefContent: has trailing whitespaces or newlines 323 + EOF 324 + rm $branch_dir_prefix/a/b/branch-trailing-2 && 325 + test_cmp expect err && 326 327 + printf "ref: refs/heads/branch \n" >$branch_dir_prefix/a/b/branch-trailing-3 && 328 + git refs verify 2>err && 329 + cat >expect <<-EOF && 330 + warning: refs/heads/a/b/branch-trailing-3: trailingRefContent: has trailing whitespaces or newlines 331 + EOF 332 + rm $branch_dir_prefix/a/b/branch-trailing-3 && 333 + test_cmp expect err && 334 335 + printf "ref: refs/heads/branch \n " >$branch_dir_prefix/a/b/branch-complicated && 336 + git refs verify 2>err && 337 + cat >expect <<-EOF && 338 + warning: refs/heads/a/b/branch-complicated: refMissingNewline: misses LF at the end 339 + warning: refs/heads/a/b/branch-complicated: trailingRefContent: has trailing whitespaces or newlines 340 + EOF 341 + rm $branch_dir_prefix/a/b/branch-complicated && 342 + test_cmp expect err 343 + ) 344 ' 345 346 test_expect_success 'textual symref content should be checked (aggregate)' ' ··· 348 git init repo && 349 branch_dir_prefix=.git/refs/heads && 350 tag_dir_prefix=.git/refs/tags && 351 + ( 352 + cd repo && 353 + test_commit default && 354 + mkdir -p "$branch_dir_prefix/a/b" && 355 356 + printf "ref: refs/heads/branch\n" >$branch_dir_prefix/branch-good && 357 + printf "ref: HEAD\n" >$branch_dir_prefix/branch-head && 358 + printf "ref: refs/heads/branch" >$branch_dir_prefix/branch-no-newline-1 && 359 + printf "ref: refs/heads/branch " >$branch_dir_prefix/a/b/branch-trailing-1 && 360 + printf "ref: refs/heads/branch\n\n" >$branch_dir_prefix/a/b/branch-trailing-2 && 361 + printf "ref: refs/heads/branch \n" >$branch_dir_prefix/a/b/branch-trailing-3 && 362 + printf "ref: refs/heads/branch \n " >$branch_dir_prefix/a/b/branch-complicated && 363 + printf "ref: refs/heads/.branch\n" >$branch_dir_prefix/branch-bad-1 && 364 365 + test_must_fail git refs verify 2>err && 366 + cat >expect <<-EOF && 367 + error: refs/heads/branch-bad-1: badReferentName: points to invalid refname '\''refs/heads/.branch'\'' 368 + warning: refs/heads/a/b/branch-complicated: refMissingNewline: misses LF at the end 369 + warning: refs/heads/a/b/branch-complicated: trailingRefContent: has trailing whitespaces or newlines 370 + warning: refs/heads/a/b/branch-trailing-1: refMissingNewline: misses LF at the end 371 + warning: refs/heads/a/b/branch-trailing-1: trailingRefContent: has trailing whitespaces or newlines 372 + warning: refs/heads/a/b/branch-trailing-2: trailingRefContent: has trailing whitespaces or newlines 373 + warning: refs/heads/a/b/branch-trailing-3: trailingRefContent: has trailing whitespaces or newlines 374 + warning: refs/heads/branch-no-newline-1: refMissingNewline: misses LF at the end 375 + EOF 376 + sort err >sorted_err && 377 + test_cmp expect sorted_err 378 + ) 379 ' 380 381 test_expect_success 'the target of the textual symref should be checked' ' ··· 383 git init repo && 384 branch_dir_prefix=.git/refs/heads && 385 tag_dir_prefix=.git/refs/tags && 386 + ( 387 + cd repo && 388 + test_commit default && 389 + mkdir -p "$branch_dir_prefix/a/b" && 390 391 + for good_referent in "refs/heads/branch" "HEAD" "refs/tags/tag" 392 + do 393 + printf "ref: %s\n" $good_referent >$branch_dir_prefix/branch-good && 394 + git refs verify 2>err && 395 + rm $branch_dir_prefix/branch-good && 396 + test_must_be_empty err || return 1 397 + done && 398 399 + for nonref_referent in "refs-back/heads/branch" "refs-back/tags/tag" "reflogs/refs/heads/branch" 400 + do 401 + printf "ref: %s\n" $nonref_referent >$branch_dir_prefix/branch-bad-1 && 402 + git refs verify 2>err && 403 + cat >expect <<-EOF && 404 + warning: refs/heads/branch-bad-1: symrefTargetIsNotARef: points to non-ref target '\''$nonref_referent'\'' 405 + EOF 406 + rm $branch_dir_prefix/branch-bad-1 && 407 + test_cmp expect err || return 1 408 + done 409 + ) 410 ' 411 412 test_expect_success SYMLINKS 'symlink symref content should be checked' ' ··· 414 git init repo && 415 branch_dir_prefix=.git/refs/heads && 416 tag_dir_prefix=.git/refs/tags && 417 + ( 418 + cd repo && 419 + test_commit default && 420 + mkdir -p "$branch_dir_prefix/a/b" && 421 422 + ln -sf ./main $branch_dir_prefix/branch-symbolic-good && 423 + git refs verify 2>err && 424 + cat >expect <<-EOF && 425 + warning: refs/heads/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref 426 + EOF 427 + rm $branch_dir_prefix/branch-symbolic-good && 428 + test_cmp expect err && 429 430 + ln -sf ../../logs/branch-escape $branch_dir_prefix/branch-symbolic && 431 + git refs verify 2>err && 432 + cat >expect <<-EOF && 433 + warning: refs/heads/branch-symbolic: symlinkRef: use deprecated symbolic link for symref 434 + warning: refs/heads/branch-symbolic: symrefTargetIsNotARef: points to non-ref target '\''logs/branch-escape'\'' 435 + EOF 436 + rm $branch_dir_prefix/branch-symbolic && 437 + test_cmp expect err && 438 439 + ln -sf ./"branch " $branch_dir_prefix/branch-symbolic-bad && 440 + test_must_fail git refs verify 2>err && 441 + cat >expect <<-EOF && 442 + warning: refs/heads/branch-symbolic-bad: symlinkRef: use deprecated symbolic link for symref 443 + error: refs/heads/branch-symbolic-bad: badReferentName: points to invalid refname '\''refs/heads/branch '\'' 444 + EOF 445 + rm $branch_dir_prefix/branch-symbolic-bad && 446 + test_cmp expect err && 447 448 + ln -sf ./".tag" $tag_dir_prefix/tag-symbolic-1 && 449 + test_must_fail git refs verify 2>err && 450 + cat >expect <<-EOF && 451 + warning: refs/tags/tag-symbolic-1: symlinkRef: use deprecated symbolic link for symref 452 + error: refs/tags/tag-symbolic-1: badReferentName: points to invalid refname '\''refs/tags/.tag'\'' 453 + EOF 454 + rm $tag_dir_prefix/tag-symbolic-1 && 455 + test_cmp expect err 456 + ) 457 ' 458 459 test_expect_success SYMLINKS 'symlink symref content should be checked (worktree)' ' 460 test_when_finished "rm -rf repo" && 461 git init repo && 462 ( 463 + cd repo && 464 + test_commit default && 465 + git branch branch-1 && 466 + git branch branch-2 && 467 + git branch branch-3 && 468 + git worktree add ./worktree-1 branch-2 && 469 + git worktree add ./worktree-2 branch-3 && 470 + main_worktree_refdir_prefix=.git/refs/heads && 471 + worktree1_refdir_prefix=.git/worktrees/worktree-1/refs/worktree && 472 + worktree2_refdir_prefix=.git/worktrees/worktree-2/refs/worktree && 473 474 + ( 475 + cd worktree-1 && 476 + git update-ref refs/worktree/branch-4 refs/heads/branch-1 477 + ) && 478 + ( 479 + cd worktree-2 && 480 + git update-ref refs/worktree/branch-4 refs/heads/branch-1 481 + ) && 482 483 + ln -sf ../../../../refs/heads/good-branch $worktree1_refdir_prefix/branch-symbolic-good && 484 + git refs verify 2>err && 485 cat >expect <<-EOF && 486 + warning: worktrees/worktree-1/refs/worktree/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref 487 EOF 488 + rm $worktree1_refdir_prefix/branch-symbolic-good && 489 test_cmp expect err && 490 491 + ln -sf ../../../../worktrees/worktree-1/good-branch $worktree2_refdir_prefix/branch-symbolic-good && 492 + git refs verify 2>err && 493 cat >expect <<-EOF && 494 + warning: worktrees/worktree-2/refs/worktree/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref 495 EOF 496 + rm $worktree2_refdir_prefix/branch-symbolic-good && 497 test_cmp expect err && 498 499 + ln -sf ../../worktrees/worktree-2/good-branch $main_worktree_refdir_prefix/branch-symbolic-good && 500 + git refs verify 2>err && 501 cat >expect <<-EOF && 502 + warning: refs/heads/branch-symbolic-good: symlinkRef: use deprecated symbolic link for symref 503 EOF 504 + rm $main_worktree_refdir_prefix/branch-symbolic-good && 505 test_cmp expect err && 506 507 + ln -sf ../../../../logs/branch-escape $worktree1_refdir_prefix/branch-symbolic && 508 + git refs verify 2>err && 509 cat >expect <<-EOF && 510 + warning: worktrees/worktree-1/refs/worktree/branch-symbolic: symlinkRef: use deprecated symbolic link for symref 511 + warning: worktrees/worktree-1/refs/worktree/branch-symbolic: symrefTargetIsNotARef: points to non-ref target '\''logs/branch-escape'\'' 512 EOF 513 + rm $worktree1_refdir_prefix/branch-symbolic && 514 + test_cmp expect err && 515 + 516 + for bad_referent_name in ".tag" "branch " 517 + do 518 + ln -sf ./"$bad_referent_name" $worktree1_refdir_prefix/bad-symbolic && 519 + test_must_fail git refs verify 2>err && 520 + cat >expect <<-EOF && 521 + warning: worktrees/worktree-1/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref 522 + error: worktrees/worktree-1/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''worktrees/worktree-1/refs/worktree/$bad_referent_name'\'' 523 + EOF 524 + rm $worktree1_refdir_prefix/bad-symbolic && 525 + test_cmp expect err && 526 + 527 + ln -sf ../../../../refs/heads/"$bad_referent_name" $worktree1_refdir_prefix/bad-symbolic && 528 + test_must_fail git refs verify 2>err && 529 + cat >expect <<-EOF && 530 + warning: worktrees/worktree-1/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref 531 + error: worktrees/worktree-1/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''refs/heads/$bad_referent_name'\'' 532 + EOF 533 + rm $worktree1_refdir_prefix/bad-symbolic && 534 + test_cmp expect err && 535 + 536 + ln -sf ./"$bad_referent_name" $worktree2_refdir_prefix/bad-symbolic && 537 + test_must_fail git refs verify 2>err && 538 + cat >expect <<-EOF && 539 + warning: worktrees/worktree-2/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref 540 + error: worktrees/worktree-2/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''worktrees/worktree-2/refs/worktree/$bad_referent_name'\'' 541 + EOF 542 + rm $worktree2_refdir_prefix/bad-symbolic && 543 + test_cmp expect err && 544 + 545 + ln -sf ../../../../refs/heads/"$bad_referent_name" $worktree2_refdir_prefix/bad-symbolic && 546 + test_must_fail git refs verify 2>err && 547 + cat >expect <<-EOF && 548 + warning: worktrees/worktree-2/refs/worktree/bad-symbolic: symlinkRef: use deprecated symbolic link for symref 549 + error: worktrees/worktree-2/refs/worktree/bad-symbolic: badReferentName: points to invalid refname '\''refs/heads/$bad_referent_name'\'' 550 + EOF 551 + rm $worktree2_refdir_prefix/bad-symbolic && 552 + test_cmp expect err || return 1 553 + done 554 + ) 555 ' 556 557 test_expect_success 'ref content checks should work with worktrees' ' 558 test_when_finished "rm -rf repo" && 559 git init repo && 560 + ( 561 + cd repo && 562 + test_commit default && 563 + git branch branch-1 && 564 + git branch branch-2 && 565 + git branch branch-3 && 566 + git worktree add ./worktree-1 branch-2 && 567 + git worktree add ./worktree-2 branch-3 && 568 + worktree1_refdir_prefix=.git/worktrees/worktree-1/refs/worktree && 569 + worktree2_refdir_prefix=.git/worktrees/worktree-2/refs/worktree && 570 571 + ( 572 + cd worktree-1 && 573 + git update-ref refs/worktree/branch-4 refs/heads/branch-1 574 + ) && 575 + ( 576 + cd worktree-2 && 577 + git update-ref refs/worktree/branch-4 refs/heads/branch-1 578 + ) && 579 580 + for bad_content in "$(git rev-parse HEAD)x" "xfsazqfxcadas" "Xfsazqfxcadas" 581 + do 582 + printf "%s" $bad_content >$worktree1_refdir_prefix/bad-branch-1 && 583 + test_must_fail git refs verify 2>err && 584 + cat >expect <<-EOF && 585 + error: worktrees/worktree-1/refs/worktree/bad-branch-1: badRefContent: $bad_content 586 + EOF 587 + rm $worktree1_refdir_prefix/bad-branch-1 && 588 + test_cmp expect err || return 1 589 + done && 590 + 591 + for bad_content in "$(git rev-parse HEAD)x" "xfsazqfxcadas" "Xfsazqfxcadas" 592 + do 593 + printf "%s" $bad_content >$worktree2_refdir_prefix/bad-branch-2 && 594 + test_must_fail git refs verify 2>err && 595 + cat >expect <<-EOF && 596 + error: worktrees/worktree-2/refs/worktree/bad-branch-2: badRefContent: $bad_content 597 + EOF 598 + rm $worktree2_refdir_prefix/bad-branch-2 && 599 + test_cmp expect err || return 1 600 + done && 601 + 602 + printf "%s" "$(git rev-parse HEAD)" >$worktree1_refdir_prefix/branch-no-newline && 603 + git refs verify 2>err && 604 cat >expect <<-EOF && 605 + warning: worktrees/worktree-1/refs/worktree/branch-no-newline: refMissingNewline: misses LF at the end 606 EOF 607 + rm $worktree1_refdir_prefix/branch-no-newline && 608 + test_cmp expect err && 609 610 + printf "%s garbage" "$(git rev-parse HEAD)" >$worktree1_refdir_prefix/branch-garbage && 611 + git refs verify 2>err && 612 cat >expect <<-EOF && 613 + warning: worktrees/worktree-1/refs/worktree/branch-garbage: trailingRefContent: has trailing garbage: '\'' garbage'\'' 614 EOF 615 + rm $worktree1_refdir_prefix/branch-garbage && 616 + test_cmp expect err 617 + ) 618 ' 619 620 test_done