Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t1400-update-ref.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t1400-update-ref.sh` 2488 lines ยท 86886 bytes Raw Blame History 1 #!/bin/sh 2 # 3 # Copyright (c) 2006 Shawn Pearce 4 # 5 6 test_description='Test git update-ref and basic ref logging' 7 8 . ./test-lib.sh 9 10 Z=$ZERO_OID 11 12 m=refs/heads/main 13 outside=refs/foo 14 bare=bare-repo 15 16 create_test_commits () 17 { 18 prfx="$1" 19 for name in A B C D E F 20 do 21 test_tick && 22 T=$(git write-tree) && 23 sha1=$(echo $name | git commit-tree $T) && 24 eval $prfx$name=$sha1 25 done 26 } 27 28 test_expect_success setup ' 29 git checkout --orphan main && 30 create_test_commits "" && 31 mkdir $bare && 32 cd $bare && 33 git init --bare -b main && 34 create_test_commits "bare" && 35 cd - 36 ' 37 38 test_expect_success "create $m" ' 39 git update-ref $m $A && 40 test $A = $(git show-ref -s --verify $m) 41 ' 42 test_expect_success "create $m with oldvalue verification" ' 43 git update-ref $m $B $A && 44 test $B = $(git show-ref -s --verify $m) 45 ' 46 test_expect_success "fail to delete $m with stale ref" ' 47 test_must_fail git update-ref -d $m $A && 48 test $B = "$(git show-ref -s --verify $m)" 49 ' 50 test_expect_success "delete $m" ' 51 test_when_finished "git update-ref -d $m" && 52 git update-ref -d $m $B && 53 test_must_fail git show-ref --verify -q $m 54 ' 55 56 test_expect_success "delete $m without oldvalue verification" ' 57 test_when_finished "git update-ref -d $m" && 58 git update-ref $m $A && 59 test $A = $(git show-ref -s --verify $m) && 60 git update-ref -d $m && 61 test_must_fail git show-ref --verify -q $m 62 ' 63 64 test_expect_success "fail to create $n due to file/directory conflict" ' 65 test_when_finished "git update-ref -d refs/heads/gu" && 66 git update-ref refs/heads/gu $A && 67 test_must_fail git update-ref refs/heads/gu/fixes $A 68 ' 69 70 test_expect_success "create $m (by HEAD)" ' 71 git update-ref HEAD $A && 72 test $A = $(git show-ref -s --verify $m) 73 ' 74 test_expect_success "create $m (by HEAD) with oldvalue verification" ' 75 git update-ref HEAD $B $A && 76 test $B = $(git show-ref -s --verify $m) 77 ' 78 test_expect_success "fail to delete $m (by HEAD) with stale ref" ' 79 test_must_fail git update-ref -d HEAD $A && 80 test $B = $(git show-ref -s --verify $m) 81 ' 82 test_expect_success "delete $m (by HEAD)" ' 83 test_when_finished "git update-ref -d $m" && 84 git update-ref -d HEAD $B && 85 test_must_fail git show-ref --verify -q $m 86 ' 87 88 test_expect_success "deleting current branch adds message to HEAD's log" ' 89 test_when_finished "git update-ref -d $m" && 90 git update-ref $m $A && 91 git symbolic-ref HEAD $m && 92 git update-ref -m delete-$m -d $m && 93 test_must_fail git show-ref --verify -q $m && 94 test-tool ref-store main for-each-reflog-ent HEAD >actual && 95 test_grep "delete-$m$" actual 96 ' 97 98 test_expect_success "deleting by HEAD adds message to HEAD's log" ' 99 test_when_finished "git update-ref -d $m" && 100 git update-ref $m $A && 101 git symbolic-ref HEAD $m && 102 git update-ref -m delete-by-head -d HEAD && 103 test_must_fail git show-ref --verify -q $m && 104 test-tool ref-store main for-each-reflog-ent HEAD >actual && 105 test_grep "delete-by-head$" actual 106 ' 107 108 test_expect_success 'update-ref does not create reflogs by default' ' 109 test_when_finished "git update-ref -d $outside" && 110 git update-ref $outside $A && 111 git rev-parse $A >expect && 112 git rev-parse $outside >actual && 113 test_cmp expect actual && 114 test_must_fail git reflog exists $outside 115 ' 116 117 test_expect_success 'update-ref creates reflogs with --create-reflog' ' 118 test_when_finished "git update-ref -d $outside" && 119 git update-ref --create-reflog $outside $A && 120 git rev-parse $A >expect && 121 git rev-parse $outside >actual && 122 test_cmp expect actual && 123 git reflog exists $outside 124 ' 125 126 test_expect_success 'creates no reflog in bare repository' ' 127 git -C $bare update-ref $m $bareA && 128 git -C $bare rev-parse $bareA >expect && 129 git -C $bare rev-parse $m >actual && 130 test_cmp expect actual && 131 test_must_fail git -C $bare reflog exists $m 132 ' 133 134 test_expect_success 'core.logAllRefUpdates=true creates reflog in bare repository' ' 135 test_when_finished "git -C $bare config --unset core.logAllRefUpdates && \ 136 test-tool ref-store main delete-reflog $m" && 137 git -C $bare config core.logAllRefUpdates true && 138 git -C $bare update-ref $m $bareB && 139 git -C $bare rev-parse $bareB >expect && 140 git -C $bare rev-parse $m >actual && 141 test_cmp expect actual && 142 git -C $bare reflog exists $m 143 ' 144 145 test_expect_success 'core.logAllRefUpdates=true does not create reflog by default' ' 146 test_config core.logAllRefUpdates true && 147 test_when_finished "git update-ref -d $outside" && 148 git update-ref $outside $A && 149 git rev-parse $A >expect && 150 git rev-parse $outside >actual && 151 test_cmp expect actual && 152 test_must_fail git reflog exists $outside 153 ' 154 155 test_expect_success 'core.logAllRefUpdates=always creates reflog by default' ' 156 test_config core.logAllRefUpdates always && 157 test_when_finished "git update-ref -d $outside" && 158 git update-ref $outside $A && 159 git rev-parse $A >expect && 160 git rev-parse $outside >actual && 161 test_cmp expect actual && 162 git reflog exists $outside 163 ' 164 165 test_expect_success 'core.logAllRefUpdates=always creates reflog for ORIG_HEAD' ' 166 test_config core.logAllRefUpdates always && 167 git update-ref ORIG_HEAD $A && 168 git reflog exists ORIG_HEAD 169 ' 170 171 test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always' ' 172 test_config core.logAllRefUpdates true && 173 test_when_finished "git update-ref -d $outside" && 174 git update-ref --no-create-reflog $outside $A && 175 git rev-parse $A >expect && 176 git rev-parse $outside >actual && 177 test_cmp expect actual && 178 test_must_fail git reflog exists $outside 179 ' 180 181 test_expect_success 'core.logAllRefUpdates can be set up via onbranch condition' ' 182 test_when_finished "git update-ref -d $outside" && 183 test_when_finished "rm -f .git/include" && 184 cat >.git/include <<-\EOF && 185 [core] 186 logAllRefUpdates = always 187 EOF 188 test_config includeIf.onbranch:main.path "$(pwd)/.git/include" && 189 git update-ref $outside $A && 190 git reflog exists $outside 191 ' 192 193 test_expect_success "create $m (by HEAD)" ' 194 git update-ref HEAD $A && 195 test $A = $(git show-ref -s --verify $m) 196 ' 197 test_expect_success 'pack refs' ' 198 git pack-refs --all 199 ' 200 test_expect_success "move $m (by HEAD)" ' 201 git update-ref HEAD $B $A && 202 test $B = $(git show-ref -s --verify $m) 203 ' 204 test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" ' 205 test_when_finished "git update-ref -d $m" && 206 git update-ref -d HEAD $B && 207 if test_have_prereq REFFILES 208 then 209 test_grep ! "$m" .git/packed-refs 210 fi && 211 test_must_fail git show-ref --verify -q $m 212 ' 213 214 test_expect_success 'delete symref without dereference' ' 215 test_when_finished "git update-ref -d $m" && 216 echo foo >foo.c && 217 git add foo.c && 218 git commit -m foo && 219 git symbolic-ref SYMREF $m && 220 git update-ref --no-deref -d SYMREF && 221 git show-ref --verify -q $m && 222 test_must_fail git show-ref --verify -q SYMREF && 223 test_must_fail git symbolic-ref SYMREF 224 ' 225 226 test_expect_success 'delete symref without dereference when the referred ref is packed' ' 227 test_when_finished "git update-ref -d $m" && 228 echo foo >foo.c && 229 git add foo.c && 230 git commit -m foo && 231 git symbolic-ref SYMREF $m && 232 git pack-refs --all && 233 git update-ref --no-deref -d SYMREF && 234 git show-ref --verify -q $m && 235 test_must_fail git show-ref --verify -q SYMREF && 236 test_must_fail git symbolic-ref SYMREF 237 ' 238 239 test_expect_success 'update-ref -d is not confused by self-reference' ' 240 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" && 241 git symbolic-ref refs/heads/self refs/heads/self && 242 git symbolic-ref --no-recurse refs/heads/self && 243 test_must_fail git update-ref -d refs/heads/self && 244 git symbolic-ref --no-recurse refs/heads/self 245 ' 246 247 test_expect_success 'update-ref --no-deref -d can delete self-reference' ' 248 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" && 249 git symbolic-ref refs/heads/self refs/heads/self && 250 git symbolic-ref --no-recurse refs/heads/self && 251 git update-ref --no-deref -d refs/heads/self && 252 test_must_fail git show-ref --verify -q refs/heads/self 253 ' 254 255 test_expect_success REFFILES 'update-ref --no-deref -d can delete reference to bad ref' ' 256 >.git/refs/heads/bad && 257 test_when_finished "rm -f .git/refs/heads/bad" && 258 git symbolic-ref refs/heads/ref-to-bad refs/heads/bad && 259 test_when_finished "git update-ref -d refs/heads/ref-to-bad" && 260 git symbolic-ref --no-recurse refs/heads/ref-to-bad && 261 git update-ref --no-deref -d refs/heads/ref-to-bad && 262 test_must_fail git show-ref --verify -q refs/heads/ref-to-bad 263 ' 264 265 test_expect_success '(not) create HEAD with old sha1' ' 266 test_must_fail git update-ref HEAD $A $B 267 ' 268 test_expect_success "(not) prior created .git/$m" ' 269 test_when_finished "git update-ref -d $m" && 270 test_must_fail git show-ref --verify -q $m 271 ' 272 273 test_expect_success 'create HEAD' ' 274 git update-ref HEAD $A 275 ' 276 test_expect_success '(not) change HEAD with wrong SHA1' ' 277 test_must_fail git update-ref HEAD $B $Z 278 ' 279 test_expect_success "(not) changed .git/$m" ' 280 test_when_finished "git update-ref -d $m" && 281 ! test $B = $(git show-ref -s --verify $m) 282 ' 283 284 test_expect_success "clean up reflog" ' 285 test-tool ref-store main delete-reflog $m 286 ' 287 288 test_expect_success "create $m (logged by touch)" ' 289 test_config core.logAllRefUpdates false && 290 GIT_COMMITTER_DATE="2005-05-26 23:30" \ 291 git update-ref --create-reflog HEAD $A -m "Initial Creation" && 292 test $A = $(git show-ref -s --verify $m) 293 ' 294 test_expect_success "update $m (logged by touch)" ' 295 test_config core.logAllRefUpdates false && 296 GIT_COMMITTER_DATE="2005-05-26 23:31" \ 297 git update-ref HEAD $B $A -m "Switch" && 298 test $B = $(git show-ref -s --verify $m) 299 ' 300 test_expect_success "set $m (logged by touch)" ' 301 test_config core.logAllRefUpdates false && 302 GIT_COMMITTER_DATE="2005-05-26 23:41" \ 303 git update-ref HEAD $A && 304 test $A = $(git show-ref -s --verify $m) 305 ' 306 307 cat >expect < `1117150200` +0000 Initial Creation 309 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1117150260` +0000 Switch 310 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1117150860` +0000 311 EOF 312 test_expect_success "verifying $m's log (logged by touch)" ' 313 test_when_finished "git update-ref -d $m && git reflog expire --expire=all --all && rm -rf actual expect" && 314 test-tool ref-store main for-each-reflog-ent $m >actual && 315 test_cmp actual expect 316 ' 317 318 test_expect_success "create $m (logged by config)" ' 319 test_config core.logAllRefUpdates true && 320 GIT_COMMITTER_DATE="2005-05-26 23:32" \ 321 git update-ref HEAD $A -m "Initial Creation" && 322 test $A = $(git show-ref -s --verify $m) 323 ' 324 test_expect_success "update $m (logged by config)" ' 325 test_config core.logAllRefUpdates true && 326 GIT_COMMITTER_DATE="2005-05-26 23:33" \ 327 git update-ref HEAD $B $A -m "Switch" && 328 test $B = $(git show-ref -s --verify $m) 329 ' 330 test_expect_success "set $m (logged by config)" ' 331 test_config core.logAllRefUpdates true && 332 GIT_COMMITTER_DATE="2005-05-26 23:43" \ 333 git update-ref HEAD $A && 334 test $A = $(git show-ref -s --verify $m) 335 ' 336 337 cat >expect < `1117150320` +0000 Initial Creation 339 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1117150380` +0000 Switch 340 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1117150980` +0000 341 EOF 342 test_expect_success "verifying $m's log (logged by config)" ' 343 test_when_finished "git update-ref -d $m && git reflog expire --expire=all --all && rm -rf actual expect" && 344 test-tool ref-store main for-each-reflog-ent $m >actual && 345 test_cmp actual expect 346 ' 347 348 test_expect_success 'set up for querying the reflog' ' 349 git update-ref -d $m && 350 test-tool ref-store main delete-reflog $m && 351 352 GIT_COMMITTER_DATE="`1117150320` -0500" git update-ref $m $C && 353 GIT_COMMITTER_DATE="`1117150350` -0500" git update-ref $m $A && 354 GIT_COMMITTER_DATE="`1117150380` -0500" git update-ref $m $B && 355 GIT_COMMITTER_DATE="`1117150680` -0500" git update-ref $m $F && 356 GIT_COMMITTER_DATE="`1117150980` -0500" git update-ref $m $E && 357 git update-ref $m $D && 358 # Delete the last reflog entry so that the tip of m and the reflog for 359 # it disagree. 360 git reflog delete $m@{0} && 361 362 cat >expect <<-EOF && 363 $Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1117150320` -0500 364 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1117150350` -0500 365 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1117150380` -0500 366 $B $F $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1117150680` -0500 367 $F $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1117150980` -0500 368 EOF 369 test-tool ref-store main for-each-reflog-ent $m >actual && 370 test_cmp expect actual 371 ' 372 373 ed="Thu, 26 May 2005 18:32:00 -0500" 374 gd="Thu, 26 May 2005 18:33:00 -0500" 375 ld="Thu, 26 May 2005 18:43:00 -0500" 376 test_expect_success 'Query "main@{May 25 2005}" (before history)' ' 377 test_when_finished "rm -f o e" && 378 git rev-parse --verify "main@{May 25 2005}" >o 2>e && 379 echo "$C" >expect && 380 test_cmp expect o && 381 echo "warning: log for '\''main'\'' only goes back to $ed" >expect && 382 test_cmp expect e 383 ' 384 test_expect_success 'Query main@{2005-05-25} (before history)' ' 385 test_when_finished "rm -f o e" && 386 git rev-parse --verify main@{2005-05-25} >o 2>e && 387 echo "$C" >expect && 388 test_cmp expect o && 389 echo "warning: log for '\''main'\'' only goes back to $ed" >expect && 390 test_cmp expect e 391 ' 392 test_expect_success 'Query "main@{May 26 2005 23:31:59}" (1 second before history)' ' 393 test_when_finished "rm -f o e" && 394 git rev-parse --verify "main@{May 26 2005 23:31:59}" >o 2>e && 395 echo "$C" >expect && 396 test_cmp expect o && 397 echo "warning: log for '\''main'\'' only goes back to $ed" >expect && 398 test_cmp expect e 399 ' 400 test_expect_success 'Query "main@{May 26 2005 23:32:00}" (exactly history start)' ' 401 test_when_finished "rm -f o e" && 402 git rev-parse --verify "main@{May 26 2005 23:32:00}" >o 2>e && 403 echo "$C" >expect && 404 test_cmp expect o && 405 test_must_be_empty e 406 ' 407 test_expect_success 'Query "main@{May 26 2005 23:32:30}" (first non-creation change)' ' 408 test_when_finished "rm -f o e" && 409 git rev-parse --verify "main@{May 26 2005 23:32:30}" >o 2>e && 410 echo "$A" >expect && 411 test_cmp expect o && 412 test_must_be_empty e 413 ' 414 test_expect_success 'Query "main@{2005-05-26 23:33:01}" (middle of history with gap)' ' 415 test_when_finished "rm -f o e" && 416 git rev-parse --verify "main@{2005-05-26 23:33:01}" >o 2>e && 417 echo "$B" >expect && 418 test_cmp expect o 419 ' 420 test_expect_success 'Query "main@{2005-05-26 23:38:00}" (middle of history)' ' 421 test_when_finished "rm -f o e" && 422 git rev-parse --verify "main@{2005-05-26 23:38:00}" >o 2>e && 423 echo "$F" >expect && 424 test_cmp expect o && 425 test_must_be_empty e 426 ' 427 test_expect_success 'Query "main@{2005-05-26 23:43:00}" (exact end of history)' ' 428 test_when_finished "rm -f o e" && 429 git rev-parse --verify "main@{2005-05-26 23:43:00}" >o 2>e && 430 echo "$E" >expect && 431 test_cmp expect o && 432 test_must_be_empty e 433 ' 434 test_expect_success 'Query "main@{2005-05-28}" (past end of history)' ' 435 test_when_finished "rm -f o e" && 436 git rev-parse --verify "main@{2005-05-28}" >o 2>e && 437 echo "$D" >expect && 438 test_cmp expect o && 439 test_grep -F "warning: log for ref $m unexpectedly ended on $ld" e 440 ' 441 442 rm -f expect 443 git update-ref -d $m 444 445 test_expect_success 'query reflog with gap' ' 446 test_when_finished "git update-ref -d $m" && 447 448 GIT_COMMITTER_DATE="`1117150320` -0500" git update-ref $m $A && 449 GIT_COMMITTER_DATE="`1117150380` -0500" git update-ref $m $B && 450 GIT_COMMITTER_DATE="`1117150480` -0500" git update-ref $m $C && 451 GIT_COMMITTER_DATE="`1117150580` -0500" git update-ref $m $D && 452 GIT_COMMITTER_DATE="`1117150680` -0500" git update-ref $m $F && 453 git reflog delete $m@{2} && 454 455 git rev-parse --verify "main@{2005-05-26 23:33:01}" >actual 2>stderr && 456 echo "$B" >expect && 457 test_cmp expect actual && 458 test_grep -F "warning: log for ref $m has gap after $gd" stderr 459 ' 460 461 test_expect_success 'creating initial files' ' 462 test_when_finished rm -f M && 463 echo TEST >F && 464 git add F && 465 GIT_AUTHOR_DATE="2005-05-26 23:30" \ 466 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a && 467 h_TEST=$(git rev-parse --verify HEAD) && 468 echo The other day this did not work. >M && 469 echo And then Bob told me how to fix it. >>M && 470 echo OTHER >F && 471 GIT_AUTHOR_DATE="2005-05-26 23:41" \ 472 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a && 473 h_OTHER=$(git rev-parse --verify HEAD) && 474 GIT_AUTHOR_DATE="2005-05-26 23:44" \ 475 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend && 476 h_FIXED=$(git rev-parse --verify HEAD) && 477 echo Merged initial commit and a later commit. >M && 478 echo $h_TEST >.git/MERGE_HEAD && 479 GIT_AUTHOR_DATE="2005-05-26 23:45" \ 480 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M && 481 h_MERGED=$(git rev-parse --verify HEAD) 482 ' 483 484 cat >expect < `1117150200` +0000 commit (initial): add 486 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1117150860` +0000 commit: The other day this did not work. 487 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1117151040` +0000 commit (amend): The other day this did not work. 488 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> `1117151100` +0000 commit (merge): Merged initial commit and a later commit. 489 EOF 490 test_expect_success 'git commit logged updates' ' 491 test-tool ref-store main for-each-reflog-ent $m >actual && 492 test_cmp expect actual 493 ' 494 unset h_TEST h_OTHER h_FIXED h_MERGED 495 496 test_expect_success 'git cat-file blob main:F (expect OTHER)' ' 497 test OTHER = $(git cat-file blob main:F) 498 ' 499 test_expect_success 'git cat-file blob main@{2005-05-26 23:30}:F (expect TEST)' ' 500 test TEST = $(git cat-file blob "main@{2005-05-26 23:30}:F") 501 ' 502 test_expect_success 'git cat-file blob main@{2005-05-26 23:42}:F (expect OTHER)' ' 503 test OTHER = $(git cat-file blob "main@{2005-05-26 23:42}:F") 504 ' 505 506 # Test adding and deleting pseudorefs 507 508 test_expect_success 'given old value for missing pseudoref, do not create' ' 509 test_must_fail git update-ref PSEUDOREF $A $B 2>err && 510 test_must_fail git rev-parse PSEUDOREF && 511 test_grep "unable to resolve reference" err 512 ' 513 514 test_expect_success 'create pseudoref' ' 515 git update-ref PSEUDOREF $A && 516 test $A = $(git show-ref -s --verify PSEUDOREF) 517 ' 518 519 test_expect_success 'overwrite pseudoref with no old value given' ' 520 git update-ref PSEUDOREF $B && 521 test $B = $(git show-ref -s --verify PSEUDOREF) 522 ' 523 524 test_expect_success 'overwrite pseudoref with correct old value' ' 525 git update-ref PSEUDOREF $C $B && 526 test $C = $(git show-ref -s --verify PSEUDOREF) 527 ' 528 529 test_expect_success 'do not overwrite pseudoref with wrong old value' ' 530 test_must_fail git update-ref PSEUDOREF $D $E 2>err && 531 test $C = $(git show-ref -s --verify PSEUDOREF) && 532 test_grep "cannot lock ref.*expected" err 533 ' 534 535 test_expect_success 'delete pseudoref' ' 536 git update-ref -d PSEUDOREF && 537 test_must_fail git show-ref -s --verify PSEUDOREF 538 ' 539 540 test_expect_success 'do not delete pseudoref with wrong old value' ' 541 git update-ref PSEUDOREF $A && 542 test_must_fail git update-ref -d PSEUDOREF $B 2>err && 543 test $A = $(git show-ref -s --verify PSEUDOREF) && 544 test_grep "cannot lock ref.*expected" err 545 ' 546 547 test_expect_success 'delete pseudoref with correct old value' ' 548 git update-ref -d PSEUDOREF $A && 549 test_must_fail git show-ref -s --verify PSEUDOREF 550 ' 551 552 test_expect_success 'create pseudoref with old OID zero' ' 553 git update-ref PSEUDOREF $A $Z && 554 test $A = $(git show-ref -s --verify PSEUDOREF) 555 ' 556 557 test_expect_success 'do not overwrite pseudoref with old OID zero' ' 558 test_when_finished git update-ref -d PSEUDOREF && 559 test_must_fail git update-ref PSEUDOREF $B $Z 2>err && 560 test $A = $(git show-ref -s --verify PSEUDOREF) && 561 test_grep "already exists" err 562 ' 563 564 # Test --stdin 565 566 a=refs/heads/a 567 b=refs/heads/b 568 c=refs/heads/c 569 E='""' 570 F='%s\0' 571 pws='path with space' 572 573 test_expect_success 'stdin test setup' ' 574 echo "$pws" >"$pws" && 575 git add -- "$pws" && 576 git commit -m "$pws" 577 ' 578 579 test_expect_success '-z fails without --stdin' ' 580 test_must_fail git update-ref -z $m $m $m 2>err && 581 test_grep "usage: git update-ref" err 582 ' 583 584 test_expect_success 'stdin works with no input' ' 585 >stdin && 586 git update-ref --stdin stdin && 592 test_must_fail git update-ref --stdin err && 593 test_grep "fatal: empty command in input" err 594 ' 595 596 test_expect_success 'stdin fails on only whitespace' ' 597 echo " " >stdin && 598 test_must_fail git update-ref --stdin err && 599 test_grep "fatal: whitespace before command: " err 600 ' 601 602 test_expect_success 'stdin fails on leading whitespace' ' 603 echo " create $a $m" >stdin && 604 test_must_fail git update-ref --stdin err && 605 test_grep "fatal: whitespace before command: create $a $m" err 606 ' 607 608 test_expect_success 'stdin fails on unknown command' ' 609 echo "unknown $a" >stdin && 610 test_must_fail git update-ref --stdin err && 611 test_grep "fatal: unknown command: unknown $a" err 612 ' 613 614 test_expect_success 'stdin fails on unbalanced quotes' ' 615 echo "create $a \"main" >stdin && 616 test_must_fail git update-ref --stdin err && 617 test_grep "fatal: badly quoted argument: \\\"main" err 618 ' 619 620 test_expect_success 'stdin fails on invalid escape' ' 621 echo "create $a \"ma\zn\"" >stdin && 622 test_must_fail git update-ref --stdin err && 623 test_grep "fatal: badly quoted argument: \\\"ma\\\\zn\\\"" err 624 ' 625 626 test_expect_success 'stdin fails on junk after quoted argument' ' 627 echo "create \"$a\"main" >stdin && 628 test_must_fail git update-ref --stdin err && 629 test_grep "fatal: unexpected character after quoted argument: \\\"$a\\\"main" err 630 ' 631 632 test_expect_success 'stdin fails create with no ref' ' 633 echo "create " >stdin && 634 test_must_fail git update-ref --stdin err && 635 test_grep "fatal: create: missing " err 636 ' 637 638 test_expect_success 'stdin fails create with no new value' ' 639 echo "create $a" >stdin && 640 test_must_fail git update-ref --stdin err && 641 test_grep "fatal: create $a: missing " err 642 ' 643 644 test_expect_success 'stdin fails create with too many arguments' ' 645 echo "create $a $m $m" >stdin && 646 test_must_fail git update-ref --stdin err && 647 test_grep "fatal: create $a: extra input: $m" err 648 ' 649 650 test_expect_success 'stdin fails update with no ref' ' 651 echo "update " >stdin && 652 test_must_fail git update-ref --stdin err && 653 test_grep "fatal: update: missing " err 654 ' 655 656 test_expect_success 'stdin fails update with no new value' ' 657 echo "update $a" >stdin && 658 test_must_fail git update-ref --stdin err && 659 test_grep "fatal: update $a: missing " err 660 ' 661 662 test_expect_success 'stdin fails update with too many arguments' ' 663 echo "update $a $m $m $m" >stdin && 664 test_must_fail git update-ref --stdin err && 665 test_grep "fatal: update $a: extra input: $m" err 666 ' 667 668 test_expect_success 'stdin fails delete with no ref' ' 669 echo "delete " >stdin && 670 test_must_fail git update-ref --stdin err && 671 test_grep "fatal: delete: missing " err 672 ' 673 674 test_expect_success 'stdin fails delete with too many arguments' ' 675 echo "delete $a $m $m" >stdin && 676 test_must_fail git update-ref --stdin err && 677 test_grep "fatal: delete $a: extra input: $m" err 678 ' 679 680 test_expect_success 'stdin fails verify with too many arguments' ' 681 echo "verify $a $m $m" >stdin && 682 test_must_fail git update-ref --stdin err && 683 test_grep "fatal: verify $a: extra input: $m" err 684 ' 685 686 test_expect_success 'stdin fails option with unknown name' ' 687 echo "option unknown" >stdin && 688 test_must_fail git update-ref --stdin err && 689 test_grep "fatal: option unknown: unknown" err 690 ' 691 692 test_expect_success 'stdin fails with duplicate refs' ' 693 cat >stdin <<-EOF && 694 create $a $m 695 create $b $m 696 create $a $m 697 EOF 698 test_must_fail git update-ref --stdin err && 699 test_grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err 700 ' 701 702 test_expect_success 'stdin create ref works' ' 703 echo "create $a $m" >stdin && 704 git update-ref --stdin expect && 706 git rev-parse $a >actual && 707 test_cmp expect actual 708 ' 709 710 test_expect_success 'stdin does not create reflogs by default' ' 711 test_when_finished "git update-ref -d $outside" && 712 echo "create $outside $m" >stdin && 713 git update-ref --stdin expect && 715 git rev-parse $outside >actual && 716 test_cmp expect actual && 717 test_must_fail git reflog exists $outside 718 ' 719 720 test_expect_success 'stdin creates reflogs with --create-reflog' ' 721 test_when_finished "git update-ref -d $outside" && 722 echo "create $outside $m" >stdin && 723 git update-ref --create-reflog --stdin expect && 725 git rev-parse $outside >actual && 726 test_cmp expect actual && 727 git reflog exists $outside 728 ' 729 730 test_expect_success 'stdin succeeds with quoted argument' ' 731 git update-ref -d $a && 732 echo "create $a \"$m\"" >stdin && 733 git update-ref --stdin expect && 735 git rev-parse $a >actual && 736 test_cmp expect actual 737 ' 738 739 test_expect_success 'stdin succeeds with escaped character' ' 740 git update-ref -d $a && 741 echo "create $a \"ma\\151n\"" >stdin && 742 git update-ref --stdin expect && 744 git rev-parse $a >actual && 745 test_cmp expect actual 746 ' 747 748 test_expect_success 'stdin update ref creates with zero old value' ' 749 echo "update $b $m $Z" >stdin && 750 git update-ref --stdin expect && 752 git rev-parse $b >actual && 753 test_cmp expect actual && 754 git update-ref -d $b 755 ' 756 757 test_expect_success 'stdin update ref creates with empty old value' ' 758 echo "update $b $m $E" >stdin && 759 git update-ref --stdin expect && 761 git rev-parse $b >actual && 762 test_cmp expect actual 763 ' 764 765 test_expect_success 'stdin create ref works with path with space to blob' ' 766 echo "create refs/blobs/pws \"$m:$pws\"" >stdin && 767 git update-ref --stdin expect && 769 git rev-parse refs/blobs/pws >actual && 770 test_cmp expect actual && 771 git update-ref -d refs/blobs/pws 772 ' 773 774 test_expect_success 'stdin update ref fails with wrong old value' ' 775 echo "update $c $m $m~1" >stdin && 776 test_must_fail git update-ref --stdin err && 777 test_grep "fatal: cannot lock ref '"'"'$c'"'"'" err && 778 test_must_fail git rev-parse --verify -q $c 779 ' 780 781 test_expect_success 'stdin update ref fails with bad old value' ' 782 echo "update $c $m does-not-exist" >stdin && 783 test_must_fail git update-ref --stdin err && 784 test_grep "fatal: update $c: invalid : does-not-exist" err && 785 test_must_fail git rev-parse --verify -q $c 786 ' 787 788 test_expect_success 'stdin create ref fails with bad new value' ' 789 echo "create $c does-not-exist" >stdin && 790 test_must_fail git update-ref --stdin err && 791 test_grep "fatal: create $c: invalid : does-not-exist" err && 792 test_must_fail git rev-parse --verify -q $c 793 ' 794 795 test_expect_success 'stdin create ref fails with zero new value' ' 796 echo "create $c " >stdin && 797 test_must_fail git update-ref --stdin err && 798 test_grep "fatal: create $c: zero " err && 799 test_must_fail git rev-parse --verify -q $c 800 ' 801 802 test_expect_success 'stdin update ref works with right old value' ' 803 echo "update $b $m~1 $m" >stdin && 804 git update-ref --stdin expect && 806 git rev-parse $b >actual && 807 test_cmp expect actual 808 ' 809 810 test_expect_success 'stdin delete ref fails with wrong old value' ' 811 echo "delete $a $m~1" >stdin && 812 test_must_fail git update-ref --stdin err && 813 test_grep "fatal: cannot lock ref '"'"'$a'"'"'" err && 814 git rev-parse $m >expect && 815 git rev-parse $a >actual && 816 test_cmp expect actual 817 ' 818 819 test_expect_success 'stdin delete ref fails with zero old value' ' 820 echo "delete $a " >stdin && 821 test_must_fail git update-ref --stdin err && 822 test_grep "fatal: delete $a: zero " err && 823 git rev-parse $m >expect && 824 git rev-parse $a >actual && 825 test_cmp expect actual 826 ' 827 828 test_expect_success 'stdin update symref works option no-deref' ' 829 git symbolic-ref TESTSYMREF $b && 830 cat >stdin <<-EOF && 831 option no-deref 832 update TESTSYMREF $a $b 833 EOF 834 git update-ref --stdin expect && 836 git rev-parse $a >actual && 837 test_cmp expect actual && 838 git rev-parse $m~1 >expect && 839 git rev-parse $b >actual && 840 test_cmp expect actual 841 ' 842 843 test_expect_success 'stdin delete symref works option no-deref' ' 844 git symbolic-ref TESTSYMREF $b && 845 cat >stdin <<-EOF && 846 option no-deref 847 delete TESTSYMREF $b 848 EOF 849 git update-ref --stdin expect && 852 git rev-parse $b >actual && 853 test_cmp expect actual 854 ' 855 856 test_expect_success 'stdin update symref works flag --no-deref' ' 857 git symbolic-ref TESTSYMREFONE $b && 858 git symbolic-ref TESTSYMREFTWO $b && 859 cat >stdin <<-EOF && 860 update TESTSYMREFONE $a $b 861 update TESTSYMREFTWO $a $b 862 EOF 863 git update-ref --no-deref --stdin expect && 865 git rev-parse $a $a >actual && 866 test_cmp expect actual && 867 git rev-parse $m~1 >expect && 868 git rev-parse $b >actual && 869 test_cmp expect actual 870 ' 871 872 test_expect_success 'stdin delete symref works flag --no-deref' ' 873 git symbolic-ref TESTSYMREFONE $b && 874 git symbolic-ref TESTSYMREFTWO $b && 875 cat >stdin <<-EOF && 876 delete TESTSYMREFONE $b 877 delete TESTSYMREFTWO $b 878 EOF 879 git update-ref --no-deref --stdin expect && 883 git rev-parse $b >actual && 884 test_cmp expect actual 885 ' 886 887 test_expect_success 'stdin delete ref works with right old value' ' 888 echo "delete $b $m~1" >stdin && 889 git update-ref --stdin stdin <<-EOF && 895 update $a $m 896 create $b $m 897 verify $c 898 EOF 899 git update-ref --stdin expect && 901 git rev-parse $a >actual && 902 test_cmp expect actual && 903 git rev-parse $b >actual && 904 test_cmp expect actual && 905 test_must_fail git rev-parse --verify -q $c 906 ' 907 908 test_expect_success 'stdin verify succeeds for correct value' ' 909 test-tool ref-store main for-each-reflog-ent $m >before && 910 git rev-parse $m >expect && 911 echo "verify $m $m" >stdin && 912 git update-ref --stdin actual && 914 test_cmp expect actual && 915 test-tool ref-store main for-each-reflog-ent $m >after && 916 test_cmp before after 917 ' 918 919 test_expect_success 'stdin verify succeeds for missing reference' ' 920 test-tool ref-store main for-each-reflog-ent $m >before && 921 echo "verify refs/heads/missing $Z" >stdin && 922 git update-ref --stdin after && 925 test_cmp before after 926 ' 927 928 test_expect_success 'stdin verify treats no value as missing' ' 929 echo "verify refs/heads/missing" >stdin && 930 git update-ref --stdin expect && 936 echo "verify $m $m~1" >stdin && 937 test_must_fail git update-ref --stdin actual && 939 test_cmp expect actual 940 ' 941 942 test_expect_success 'stdin verify fails for mistaken null value' ' 943 git rev-parse $m >expect && 944 echo "verify $m $Z" >stdin && 945 test_must_fail git update-ref --stdin actual && 947 test_cmp expect actual 948 ' 949 950 test_expect_success 'stdin verify fails for mistaken empty value' ' 951 M=$(git rev-parse $m) && 952 test_when_finished "git update-ref $m $M" && 953 git rev-parse $m >expect && 954 echo "verify $m" >stdin && 955 test_must_fail git update-ref --stdin actual && 957 test_cmp expect actual 958 ' 959 960 test_expect_success 'stdin update refs works with identity updates' ' 961 cat >stdin <<-EOF && 962 update $a $m $m 963 update $b $m $m 964 update $c $Z $E 965 EOF 966 git update-ref --stdin expect && 968 git rev-parse $a >actual && 969 test_cmp expect actual && 970 git rev-parse $b >actual && 971 test_cmp expect actual && 972 test_must_fail git rev-parse --verify -q $c 973 ' 974 975 test_expect_success 'stdin update refs fails with wrong old value' ' 976 git update-ref $c $m && 977 cat >stdin <<-EOF && 978 update $a $m $m 979 update $b $m $m 980 update $c '' 981 EOF 982 test_must_fail git update-ref --stdin err && 983 test_grep "fatal: cannot lock ref '"'"'$c'"'"'" err && 984 git rev-parse $m >expect && 985 git rev-parse $a >actual && 986 test_cmp expect actual && 987 git rev-parse $b >actual && 988 test_cmp expect actual && 989 git rev-parse $c >actual && 990 test_cmp expect actual 991 ' 992 993 test_expect_success 'stdin delete refs works with packed and loose refs' ' 994 git pack-refs --all && 995 git update-ref $c $m~1 && 996 cat >stdin <<-EOF && 997 delete $a $m 998 update $b $Z $m 999 update $c $E $m~1 1000 EOF 1001 git update-ref --stdin stdin && 1009 git update-ref -z --stdin stdin && 1015 test_must_fail git update-ref -z --stdin err && 1016 test_grep "fatal: whitespace before command: " err 1017 ' 1018 1019 test_expect_success 'stdin -z fails on empty command' ' 1020 printf $F "" >stdin && 1021 test_must_fail git update-ref -z --stdin err && 1022 test_grep "fatal: empty command in input" err 1023 ' 1024 1025 test_expect_success 'stdin -z fails on only whitespace' ' 1026 printf $F " " >stdin && 1027 test_must_fail git update-ref -z --stdin err && 1028 test_grep "fatal: whitespace before command: " err 1029 ' 1030 1031 test_expect_success 'stdin -z fails on leading whitespace' ' 1032 printf $F " create $a" "$m" >stdin && 1033 test_must_fail git update-ref -z --stdin err && 1034 test_grep "fatal: whitespace before command: create $a" err 1035 ' 1036 1037 test_expect_success 'stdin -z fails on unknown command' ' 1038 printf $F "unknown $a" >stdin && 1039 test_must_fail git update-ref -z --stdin err && 1040 test_grep "fatal: unknown command: unknown $a" err 1041 ' 1042 1043 test_expect_success 'stdin -z fails create with no ref' ' 1044 printf $F "create " >stdin && 1045 test_must_fail git update-ref -z --stdin err && 1046 test_grep "fatal: create: missing " err 1047 ' 1048 1049 test_expect_success 'stdin -z fails create with no new value' ' 1050 printf $F "create $a" >stdin && 1051 test_must_fail git update-ref -z --stdin err && 1052 test_grep "fatal: create $a: unexpected end of input when reading " err 1053 ' 1054 1055 test_expect_success 'stdin -z fails create with too many arguments' ' 1056 printf $F "create $a" "$m" "$m" >stdin && 1057 test_must_fail git update-ref -z --stdin err && 1058 test_grep "fatal: unknown command: $m" err 1059 ' 1060 1061 test_expect_success 'stdin -z fails update with no ref' ' 1062 printf $F "update " >stdin && 1063 test_must_fail git update-ref -z --stdin err && 1064 test_grep "fatal: update: missing " err 1065 ' 1066 1067 test_expect_success 'stdin -z fails update with too few args' ' 1068 printf $F "update $a" "$m" >stdin && 1069 test_must_fail git update-ref -z --stdin err && 1070 test_grep "fatal: update $a: unexpected end of input when reading " err 1071 ' 1072 1073 test_expect_success 'stdin -z emits warning with empty new value' ' 1074 git update-ref $a $m && 1075 printf $F "update $a" "" "" >stdin && 1076 git update-ref -z --stdin err && 1077 test_grep "warning: update $a: missing , treating as zero" err && 1078 test_must_fail git rev-parse --verify -q $a 1079 ' 1080 1081 test_expect_success 'stdin -z fails update with no new value' ' 1082 printf $F "update $a" >stdin && 1083 test_must_fail git update-ref -z --stdin err && 1084 test_grep "fatal: update $a: unexpected end of input when reading " err 1085 ' 1086 1087 test_expect_success 'stdin -z fails update with no old value' ' 1088 printf $F "update $a" "$m" >stdin && 1089 test_must_fail git update-ref -z --stdin err && 1090 test_grep "fatal: update $a: unexpected end of input when reading " err 1091 ' 1092 1093 test_expect_success 'stdin -z fails update with too many arguments' ' 1094 printf $F "update $a" "$m" "$m" "$m" >stdin && 1095 test_must_fail git update-ref -z --stdin err && 1096 test_grep "fatal: unknown command: $m" err 1097 ' 1098 1099 test_expect_success 'stdin -z fails delete with no ref' ' 1100 printf $F "delete " >stdin && 1101 test_must_fail git update-ref -z --stdin err && 1102 test_grep "fatal: delete: missing " err 1103 ' 1104 1105 test_expect_success 'stdin -z fails delete with no old value' ' 1106 printf $F "delete $a" >stdin && 1107 test_must_fail git update-ref -z --stdin err && 1108 test_grep "fatal: delete $a: unexpected end of input when reading " err 1109 ' 1110 1111 test_expect_success 'stdin -z fails delete with too many arguments' ' 1112 printf $F "delete $a" "$m" "$m" >stdin && 1113 test_must_fail git update-ref -z --stdin err && 1114 test_grep "fatal: unknown command: $m" err 1115 ' 1116 1117 test_expect_success 'stdin -z fails verify with too many arguments' ' 1118 printf $F "verify $a" "$m" "$m" >stdin && 1119 test_must_fail git update-ref -z --stdin err && 1120 test_grep "fatal: unknown command: $m" err 1121 ' 1122 1123 test_expect_success 'stdin -z fails verify with no old value' ' 1124 printf $F "verify $a" >stdin && 1125 test_must_fail git update-ref -z --stdin err && 1126 test_grep "fatal: verify $a: unexpected end of input when reading " err 1127 ' 1128 1129 test_expect_success 'stdin -z fails option with unknown name' ' 1130 printf $F "option unknown" >stdin && 1131 test_must_fail git update-ref -z --stdin err && 1132 test_grep "fatal: option unknown: unknown" err 1133 ' 1134 1135 test_expect_success 'stdin -z fails with duplicate refs' ' 1136 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin && 1137 test_must_fail git update-ref -z --stdin err && 1138 test_grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err 1139 ' 1140 1141 test_expect_success 'stdin -z create ref works' ' 1142 printf $F "create $a" "$m" >stdin && 1143 git update-ref -z --stdin expect && 1145 git rev-parse $a >actual && 1146 test_cmp expect actual 1147 ' 1148 1149 test_expect_success 'stdin -z update ref creates with zero old value' ' 1150 printf $F "update $b" "$m" "$Z" >stdin && 1151 git update-ref -z --stdin expect && 1153 git rev-parse $b >actual && 1154 test_cmp expect actual && 1155 git update-ref -d $b 1156 ' 1157 1158 test_expect_success 'stdin -z update ref creates with empty old value' ' 1159 printf $F "update $b" "$m" "" >stdin && 1160 git update-ref -z --stdin expect && 1162 git rev-parse $b >actual && 1163 test_cmp expect actual 1164 ' 1165 1166 test_expect_success 'stdin -z create ref works with path with space to blob' ' 1167 printf $F "create refs/blobs/pws" "$m:$pws" >stdin && 1168 git update-ref -z --stdin expect && 1170 git rev-parse refs/blobs/pws >actual && 1171 test_cmp expect actual && 1172 git update-ref -d refs/blobs/pws 1173 ' 1174 1175 test_expect_success 'stdin -z update ref fails with wrong old value' ' 1176 printf $F "update $c" "$m" "$m~1" >stdin && 1177 test_must_fail git update-ref -z --stdin err && 1178 test_grep "fatal: cannot lock ref '"'"'$c'"'"'" err && 1179 test_must_fail git rev-parse --verify -q $c 1180 ' 1181 1182 test_expect_success 'stdin -z update ref fails with bad old value' ' 1183 printf $F "update $c" "$m" "does-not-exist" >stdin && 1184 test_must_fail git update-ref -z --stdin err && 1185 test_grep "fatal: update $c: invalid : does-not-exist" err && 1186 test_must_fail git rev-parse --verify -q $c 1187 ' 1188 1189 test_expect_success 'stdin -z create ref fails when ref exists' ' 1190 git update-ref $c $m && 1191 git rev-parse "$c" >expect && 1192 printf $F "create $c" "$m~1" >stdin && 1193 test_must_fail git update-ref -z --stdin err && 1194 test_grep "fatal: cannot lock ref '"'"'$c'"'"'" err && 1195 git rev-parse "$c" >actual && 1196 test_cmp expect actual 1197 ' 1198 1199 test_expect_success 'stdin -z create ref fails with bad new value' ' 1200 git update-ref -d "$c" && 1201 printf $F "create $c" "does-not-exist" >stdin && 1202 test_must_fail git update-ref -z --stdin err && 1203 test_grep "fatal: create $c: invalid : does-not-exist" err && 1204 test_must_fail git rev-parse --verify -q $c 1205 ' 1206 1207 test_expect_success 'stdin -z create ref fails with empty new value' ' 1208 printf $F "create $c" "" >stdin && 1209 test_must_fail git update-ref -z --stdin err && 1210 test_grep "fatal: create $c: missing " err && 1211 test_must_fail git rev-parse --verify -q $c 1212 ' 1213 1214 test_expect_success 'stdin -z create ref fails with non commit object' ' 1215 printf $F "create $c" "$(test_oid 001)" >stdin && 1216 test_must_fail git update-ref -z --stdin err && 1217 test_grep "fatal: trying to write ref ${SQ}$c${SQ} with nonexistent object" err && 1218 test_must_fail git rev-parse --verify -q $c 1219 ' 1220 1221 test_expect_success 'stdin -z update ref fails with non commit object' ' 1222 printf $F "update $b" "$(test_oid 001)" "" >stdin && 1223 test_must_fail git update-ref -z --stdin err && 1224 test_grep "fatal: trying to write ref ${SQ}$b${SQ} with nonexistent object" err && 1225 test_must_fail git rev-parse --verify -q $c 1226 ' 1227 1228 test_expect_success 'stdin -z update ref works with right old value' ' 1229 printf $F "update $b" "$m~1" "$m" >stdin && 1230 git update-ref -z --stdin expect && 1232 git rev-parse $b >actual && 1233 test_cmp expect actual 1234 ' 1235 1236 test_expect_success 'stdin -z delete ref fails with wrong old value' ' 1237 printf $F "delete $a" "$m~1" >stdin && 1238 test_must_fail git update-ref -z --stdin err && 1239 test_grep "fatal: cannot lock ref '"'"'$a'"'"'" err && 1240 git rev-parse $m >expect && 1241 git rev-parse $a >actual && 1242 test_cmp expect actual 1243 ' 1244 1245 test_expect_success 'stdin -z delete ref fails with zero old value' ' 1246 printf $F "delete $a" "$Z" >stdin && 1247 test_must_fail git update-ref -z --stdin err && 1248 test_grep "fatal: delete $a: zero " err && 1249 git rev-parse $m >expect && 1250 git rev-parse $a >actual && 1251 test_cmp expect actual 1252 ' 1253 1254 test_expect_success 'stdin -z update symref works option no-deref' ' 1255 git symbolic-ref TESTSYMREF $b && 1256 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin && 1257 git update-ref -z --stdin expect && 1259 git rev-parse $a >actual && 1260 test_cmp expect actual && 1261 git rev-parse $m~1 >expect && 1262 git rev-parse $b >actual && 1263 test_cmp expect actual 1264 ' 1265 1266 test_expect_success 'stdin -z delete symref works option no-deref' ' 1267 git symbolic-ref TESTSYMREF $b && 1268 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin && 1269 git update-ref -z --stdin expect && 1272 git rev-parse $b >actual && 1273 test_cmp expect actual 1274 ' 1275 1276 test_expect_success 'stdin -z delete ref works with right old value' ' 1277 printf $F "delete $b" "$m~1" >stdin && 1278 git update-ref -z --stdin stdin && 1284 git update-ref -z --stdin expect && 1286 git rev-parse $a >actual && 1287 test_cmp expect actual && 1288 git rev-parse $b >actual && 1289 test_cmp expect actual && 1290 test_must_fail git rev-parse --verify -q $c 1291 ' 1292 1293 test_expect_success 'stdin -z verify succeeds for correct value' ' 1294 git rev-parse $m >expect && 1295 printf $F "verify $m" "$m" >stdin && 1296 git update-ref -z --stdin actual && 1298 test_cmp expect actual 1299 ' 1300 1301 test_expect_success 'stdin -z verify succeeds for missing reference' ' 1302 printf $F "verify refs/heads/missing" "$Z" >stdin && 1303 git update-ref -z --stdin stdin && 1309 git update-ref -z --stdin expect && 1315 printf $F "verify $m" "$m~1" >stdin && 1316 test_must_fail git update-ref -z --stdin actual && 1318 test_cmp expect actual 1319 ' 1320 1321 test_expect_success 'stdin -z verify fails for mistaken null value' ' 1322 git rev-parse $m >expect && 1323 printf $F "verify $m" "$Z" >stdin && 1324 test_must_fail git update-ref -z --stdin actual && 1326 test_cmp expect actual 1327 ' 1328 1329 test_expect_success 'stdin -z verify fails for mistaken empty value' ' 1330 M=$(git rev-parse $m) && 1331 test_when_finished "git update-ref $m $M" && 1332 git rev-parse $m >expect && 1333 printf $F "verify $m" "" >stdin && 1334 test_must_fail git update-ref -z --stdin actual && 1336 test_cmp expect actual 1337 ' 1338 1339 test_expect_success 'stdin -z update refs works with identity updates' ' 1340 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin && 1341 git update-ref -z --stdin expect && 1343 git rev-parse $a >actual && 1344 test_cmp expect actual && 1345 git rev-parse $b >actual && 1346 test_cmp expect actual && 1347 test_must_fail git rev-parse --verify -q $c 1348 ' 1349 1350 test_expect_success 'stdin -z update refs fails with wrong old value' ' 1351 git update-ref $c $m && 1352 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin && 1353 test_must_fail git update-ref -z --stdin err && 1354 test_grep "fatal: cannot lock ref '"'"'$c'"'"'" err && 1355 git rev-parse $m >expect && 1356 git rev-parse $a >actual && 1357 test_cmp expect actual && 1358 git rev-parse $b >actual && 1359 test_cmp expect actual && 1360 git rev-parse $c >actual && 1361 test_cmp expect actual 1362 ' 1363 1364 test_expect_success 'stdin -z delete refs works with packed and loose refs' ' 1365 git pack-refs --all && 1366 git update-ref $c $m~1 && 1367 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin && 1368 git update-ref -z --stdin stdin <<-EOF && 1378 update refs/heads/target1 $C 1379 option no-deref 1380 update HEAD $B 1381 EOF 1382 test_must_fail git update-ref --stdin err && 1383 test_grep "fatal: multiple updates for '\''HEAD'\'' (including one via its referent .refs/heads/target1.) are not allowed" err && 1384 echo "refs/heads/target1" >expect && 1385 git symbolic-ref HEAD >actual && 1386 test_cmp expect actual && 1387 echo "$A" >expect && 1388 git rev-parse refs/heads/target1 >actual && 1389 test_cmp expect actual 1390 ' 1391 1392 test_expect_success 'fails with duplicate ref update via symref' ' 1393 test_when_finished "git symbolic-ref -d refs/heads/symref2" && 1394 git branch target2 $A && 1395 git symbolic-ref refs/heads/symref2 refs/heads/target2 && 1396 cat >stdin <<-EOF && 1397 update refs/heads/target2 $C 1398 update refs/heads/symref2 $B 1399 EOF 1400 test_must_fail git update-ref --stdin err && 1401 test_grep "fatal: multiple updates for '\''refs/heads/target2'\'' (including one via symref .refs/heads/symref2.) are not allowed" err && 1402 echo "refs/heads/target2" >expect && 1403 git symbolic-ref refs/heads/symref2 >actual && 1404 test_cmp expect actual && 1405 echo "$A" >expect && 1406 git rev-parse refs/heads/target2 >actual && 1407 test_cmp expect actual 1408 ' 1409 1410 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' ' 1411 ( 1412 test_seq -f "create refs/heads/%d HEAD" 33 | 1413 run_with_limited_open_files git update-ref --stdin && 1414 git rev-parse --verify -q refs/heads/33 1415 ) 1416 ' 1417 1418 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches does not burst open file limit' ' 1419 ( 1420 test_seq -f "delete refs/heads/%d HEAD" 33 | 1421 run_with_limited_open_files git update-ref --stdin && 1422 test_must_fail git rev-parse --verify -q refs/heads/33 1423 ) 1424 ' 1425 1426 test_expect_success 'handle per-worktree refs in refs/bisect' ' 1427 git commit --allow-empty -m "initial commit" && 1428 git worktree add -b branch worktree && 1429 ( 1430 cd worktree && 1431 git commit --allow-empty -m "test commit" && 1432 git for-each-ref >for-each-ref.out && 1433 test_grep ! refs/bisect for-each-ref.out && 1434 git update-ref refs/bisect/something HEAD && 1435 git rev-parse refs/bisect/something >../worktree-head && 1436 git for-each-ref | grep refs/bisect/something 1437 ) && 1438 git show-ref >actual && 1439 test_grep ! 'refs/bisect' actual && 1440 test_must_fail git rev-parse refs/bisect/something && 1441 git update-ref refs/bisect/something HEAD && 1442 git rev-parse refs/bisect/something >main-head && 1443 ! test_cmp main-head worktree-head 1444 ' 1445 1446 test_expect_success 'transaction handles empty commit' ' 1447 cat >stdin <<-EOF && 1448 start 1449 prepare 1450 commit 1451 EOF 1452 git update-ref --stdin actual && 1453 printf "%s: ok\n" start prepare commit >expect && 1454 test_cmp expect actual 1455 ' 1456 1457 test_expect_success 'transaction handles empty commit with missing prepare' ' 1458 cat >stdin <<-EOF && 1459 start 1460 commit 1461 EOF 1462 git update-ref --stdin actual && 1463 printf "%s: ok\n" start commit >expect && 1464 test_cmp expect actual 1465 ' 1466 1467 test_expect_success 'transaction handles sole commit' ' 1468 cat >stdin <<-EOF && 1469 commit 1470 EOF 1471 git update-ref --stdin actual && 1472 printf "%s: ok\n" commit >expect && 1473 test_cmp expect actual 1474 ' 1475 1476 test_expect_success 'transaction handles empty abort' ' 1477 cat >stdin <<-EOF && 1478 start 1479 prepare 1480 abort 1481 EOF 1482 git update-ref --stdin actual && 1483 printf "%s: ok\n" start prepare abort >expect && 1484 test_cmp expect actual 1485 ' 1486 1487 test_expect_success 'transaction exits on multiple aborts' ' 1488 cat >stdin <<-EOF && 1489 abort 1490 abort 1491 EOF 1492 test_must_fail git update-ref --stdin actual 2>err && 1493 printf "%s: ok\n" abort >expect && 1494 test_cmp expect actual && 1495 test_grep "fatal: transaction is closed" err 1496 ' 1497 1498 test_expect_success 'transaction exits on start after prepare' ' 1499 cat >stdin <<-EOF && 1500 prepare 1501 start 1502 EOF 1503 test_must_fail git update-ref --stdin err >actual && 1504 printf "%s: ok\n" prepare >expect && 1505 test_cmp expect actual && 1506 test_grep "fatal: prepared transactions can only be closed" err 1507 ' 1508 1509 test_expect_success 'transaction handles empty abort with missing prepare' ' 1510 cat >stdin <<-EOF && 1511 start 1512 abort 1513 EOF 1514 git update-ref --stdin actual && 1515 printf "%s: ok\n" start abort >expect && 1516 test_cmp expect actual 1517 ' 1518 1519 test_expect_success 'transaction handles sole abort' ' 1520 cat >stdin <<-EOF && 1521 abort 1522 EOF 1523 git update-ref --stdin actual && 1524 printf "%s: ok\n" abort >expect && 1525 test_cmp expect actual 1526 ' 1527 1528 test_expect_success 'transaction can handle commit' ' 1529 cat >stdin <<-EOF && 1530 start 1531 create $a HEAD 1532 commit 1533 EOF 1534 git update-ref --stdin actual && 1535 printf "%s: ok\n" start commit >expect && 1536 test_cmp expect actual && 1537 git rev-parse HEAD >expect && 1538 git rev-parse $a >actual && 1539 test_cmp expect actual 1540 ' 1541 1542 test_expect_success 'transaction can handle abort' ' 1543 cat >stdin <<-EOF && 1544 start 1545 create $b HEAD 1546 abort 1547 EOF 1548 git update-ref --stdin actual && 1549 printf "%s: ok\n" start abort >expect && 1550 test_cmp expect actual && 1551 test_must_fail git show-ref --verify -q $b 1552 ' 1553 1554 test_expect_success 'transaction aborts by default' ' 1555 cat >stdin <<-EOF && 1556 start 1557 create $b HEAD 1558 EOF 1559 git update-ref --stdin actual && 1560 printf "%s: ok\n" start >expect && 1561 test_cmp expect actual && 1562 test_must_fail git show-ref --verify -q $b 1563 ' 1564 1565 test_expect_success 'transaction with prepare aborts by default' ' 1566 cat >stdin <<-EOF && 1567 start 1568 create $b HEAD 1569 prepare 1570 EOF 1571 git update-ref --stdin actual && 1572 printf "%s: ok\n" start prepare >expect && 1573 test_cmp expect actual && 1574 test_must_fail git show-ref --verify -q $b 1575 ' 1576 1577 test_expect_success 'transaction can commit multiple times' ' 1578 cat >stdin <<-EOF && 1579 start 1580 create refs/heads/branch-1 $A 1581 commit 1582 start 1583 create refs/heads/branch-2 $B 1584 commit 1585 EOF 1586 git update-ref --stdin actual && 1587 printf "%s: ok\n" start commit start commit >expect && 1588 test_cmp expect actual && 1589 echo "$A" >expect && 1590 git rev-parse refs/heads/branch-1 >actual && 1591 test_cmp expect actual && 1592 echo "$B" >expect && 1593 git rev-parse refs/heads/branch-2 >actual && 1594 test_cmp expect actual 1595 ' 1596 1597 test_expect_success 'transaction can create and delete' ' 1598 cat >stdin <<-EOF && 1599 start 1600 create refs/heads/create-and-delete $A 1601 commit 1602 start 1603 delete refs/heads/create-and-delete $A 1604 commit 1605 EOF 1606 git update-ref --stdin actual && 1607 printf "%s: ok\n" start commit start commit >expect && 1608 test_cmp expect actual && 1609 test_must_fail git show-ref --verify refs/heads/create-and-delete 1610 ' 1611 1612 test_expect_success 'transaction can commit after abort' ' 1613 cat >stdin <<-EOF && 1614 start 1615 create refs/heads/abort $A 1616 abort 1617 start 1618 create refs/heads/abort $A 1619 commit 1620 EOF 1621 git update-ref --stdin actual && 1622 printf "%s: ok\n" start abort start commit >expect && 1623 echo "$A" >expect && 1624 git rev-parse refs/heads/abort >actual && 1625 test_cmp expect actual 1626 ' 1627 1628 test_expect_success 'transaction cannot restart ongoing transaction' ' 1629 cat >stdin <<-EOF && 1630 start 1631 create refs/heads/restart $A 1632 start 1633 commit 1634 EOF 1635 test_must_fail git update-ref --stdin actual && 1636 printf "%s: ok\n" start >expect && 1637 test_cmp expect actual && 1638 test_must_fail git show-ref --verify refs/heads/restart 1639 ' 1640 1641 test_expect_success PIPE 'transaction flushes status updates' ' 1642 test_when_finished "rm -f in out" && 1643 mkfifo in out && 1644 (git update-ref --stdin out &) && 1645 1646 exec 9>in && 1647 exec 8&-" && 1649 test_when_finished "exec 8<&-" && 1650 1651 echo "start" >&9 && 1652 echo "start: ok" >expected && 1653 read line <&8 && 1654 echo "$line" >actual && 1655 test_cmp expected actual && 1656 1657 echo "create refs/heads/flush $A" >&9 && 1658 1659 echo prepare >&9 && 1660 echo "prepare: ok" >expected && 1661 read line <&8 && 1662 echo "$line" >actual && 1663 test_cmp expected actual && 1664 1665 # This must now fail given that we have locked the ref. 1666 test_must_fail git update-ref refs/heads/flush $B 2>stderr && 1667 test_grep "fatal: update_ref failed for ref ${SQ}refs/heads/flush${SQ}: cannot lock ref" stderr && 1668 1669 echo commit >&9 && 1670 echo "commit: ok" >expected && 1671 read line <&8 && 1672 echo "$line" >actual && 1673 test_cmp expected actual 1674 ' 1675 1676 format_command () { 1677 if test "$1" = "-z" 1678 then 1679 shift 1680 printf "$F" "$@" 1681 else 1682 echo "$@" 1683 fi 1684 } 1685 1686 for type in "" "-z" 1687 do 1688 1689 test_expect_success "stdin $type symref-verify fails without --no-deref" ' 1690 git symbolic-ref refs/heads/symref $a && 1691 format_command $type "symref-verify refs/heads/symref" "$a" >stdin && 1692 test_must_fail git update-ref --stdin $type err && 1693 test_grep "fatal: symref-verify: cannot operate with deref mode" err 1694 ' 1695 1696 test_expect_success "stdin $type symref-verify fails with too many arguments" ' 1697 format_command $type "symref-verify refs/heads/symref" "$a" "$a" >stdin && 1698 test_must_fail git update-ref --stdin $type --no-deref err && 1699 if test "$type" = "-z" 1700 then 1701 test_grep "fatal: unknown command: $a" err 1702 else 1703 test_grep "fatal: symref-verify refs/heads/symref: extra input: $a" err 1704 fi 1705 ' 1706 1707 test_expect_success "stdin $type symref-verify succeeds for correct value" ' 1708 git symbolic-ref refs/heads/symref >expect && 1709 test-tool ref-store main for-each-reflog-ent refs/heads/symref >before && 1710 format_command $type "symref-verify refs/heads/symref" "$a" >stdin && 1711 git update-ref --stdin $type --no-deref actual && 1713 test_cmp expect actual && 1714 test-tool ref-store main for-each-reflog-ent refs/heads/symref >after && 1715 test_cmp before after 1716 ' 1717 1718 test_expect_success "stdin $type symref-verify fails with no value" ' 1719 git symbolic-ref refs/heads/symref >expect && 1720 format_command $type "symref-verify refs/heads/symref" "" >stdin && 1721 test_must_fail git update-ref --stdin $type --no-deref stdin && 1729 git update-ref --stdin $type --no-deref before && 1734 format_command $type "symref-verify refs/heads/missing" "refs/heads/unknown" >stdin && 1735 test_must_fail git update-ref --stdin $type --no-deref err && 1736 test_grep "fatal: cannot lock ref ${SQ}refs/heads/missing${SQ}: unable to resolve reference ${SQ}refs/heads/missing${SQ}" err && 1737 test_must_fail git rev-parse --verify -q refs/heads/missing && 1738 test-tool ref-store main for-each-reflog-ent refs/heads/symref >after && 1739 test_cmp before after 1740 ' 1741 1742 test_expect_success "stdin $type symref-verify fails for wrong value" ' 1743 git symbolic-ref refs/heads/symref >expect && 1744 format_command $type "symref-verify refs/heads/symref" "$b" >stdin && 1745 test_must_fail git update-ref --stdin $type --no-deref actual && 1747 test_cmp expect actual 1748 ' 1749 1750 test_expect_success "stdin $type symref-verify fails for mistaken null value" ' 1751 git symbolic-ref refs/heads/symref >expect && 1752 format_command $type "symref-verify refs/heads/symref" "$Z" >stdin && 1753 test_must_fail git update-ref --stdin $type --no-deref actual && 1755 test_cmp expect actual 1756 ' 1757 1758 test_expect_success "stdin $type symref-delete fails without --no-deref" ' 1759 git symbolic-ref refs/heads/symref $a && 1760 format_command $type "symref-delete refs/heads/symref" "$a" >stdin && 1761 test_must_fail git update-ref --stdin $type err && 1762 test_grep "fatal: symref-delete: cannot operate with deref mode" err 1763 ' 1764 1765 test_expect_success "stdin $type symref-delete fails with no ref" ' 1766 format_command $type "symref-delete " >stdin && 1767 test_must_fail git update-ref --stdin $type --no-deref err && 1768 test_grep "fatal: symref-delete: missing " err 1769 ' 1770 1771 test_expect_success "stdin $type symref-delete fails deleting regular ref" ' 1772 test_when_finished "git update-ref -d refs/heads/regularref" && 1773 git update-ref refs/heads/regularref $a && 1774 format_command $type "symref-delete refs/heads/regularref" "$a" >stdin && 1775 test_must_fail git update-ref --stdin $type --no-deref err && 1776 test_grep "fatal: cannot lock ref ${SQ}refs/heads/regularref${SQ}: expected symref with target ${SQ}$a${SQ}: but is a regular ref" err 1777 ' 1778 1779 test_expect_success "stdin $type symref-delete fails with too many arguments" ' 1780 format_command $type "symref-delete refs/heads/symref" "$a" "$a" >stdin && 1781 test_must_fail git update-ref --stdin $type --no-deref err && 1782 if test "$type" = "-z" 1783 then 1784 test_grep "fatal: unknown command: $a" err 1785 else 1786 test_grep "fatal: symref-delete refs/heads/symref: extra input: $a" err 1787 fi 1788 ' 1789 1790 test_expect_success "stdin $type symref-delete fails with wrong old value" ' 1791 format_command $type "symref-delete refs/heads/symref" "$m" >stdin && 1792 test_must_fail git update-ref --stdin $type --no-deref err && 1793 test_grep "fatal: verifying symref target: ${SQ}refs/heads/symref${SQ}: is at $a but expected refs/heads/main" err && 1794 git symbolic-ref refs/heads/symref >expect && 1795 echo $a >actual && 1796 test_cmp expect actual 1797 ' 1798 1799 test_expect_success "stdin $type symref-delete works with right old value" ' 1800 format_command $type "symref-delete refs/heads/symref" "$a" >stdin && 1801 git update-ref --stdin $type --no-deref stdin && 1807 format_command $type "symref-delete refs/heads/symref" "" >stdin && 1808 git update-ref --stdin $type --no-deref stdin && 1816 git update-ref --stdin $type --no-deref stdin && 1823 git update-ref --stdin $type --no-deref stdin && 1828 test_must_fail git update-ref --stdin $type --no-deref err && 1829 if test "$type" = "-z" 1830 then 1831 test_grep "fatal: unknown command: $a" err 1832 else 1833 test_grep "fatal: symref-create refs/heads/symref: extra input: $a" err 1834 fi 1835 ' 1836 1837 test_expect_success "stdin $type symref-create fails with no target" ' 1838 format_command $type "symref-create refs/heads/symref" >stdin && 1839 test_must_fail git update-ref --stdin $type --no-deref stdin && 1844 test_must_fail git update-ref --stdin $type --no-deref stdin && 1850 git update-ref --stdin $type --no-deref expect && 1852 echo $a >actual && 1853 test_cmp expect actual 1854 ' 1855 1856 test_expect_success "stdin $type symref-create works with --no-deref" ' 1857 test_when_finished "git symbolic-ref -d refs/heads/symref" && 1858 format_command $type "symref-create refs/heads/symref" "$a" && 1859 git update-ref --stdin $type err 1860 ' 1861 1862 test_expect_success "stdin $type create dangling symref ref works" ' 1863 test_when_finished "git symbolic-ref -d refs/heads/symref" && 1864 format_command $type "symref-create refs/heads/symref" "refs/heads/unknown" >stdin && 1865 git update-ref --stdin $type --no-deref expect && 1867 echo refs/heads/unknown >actual && 1868 test_cmp expect actual 1869 ' 1870 1871 test_expect_success "stdin $type symref-create does not create reflogs by default" ' 1872 test_when_finished "git symbolic-ref -d refs/symref" && 1873 format_command $type "symref-create refs/symref" "$a" >stdin && 1874 git update-ref --stdin $type --no-deref expect && 1876 echo $a >actual && 1877 test_cmp expect actual && 1878 test_must_fail git reflog exists refs/symref 1879 ' 1880 1881 test_expect_success "stdin $type symref-create reflogs with --create-reflog" ' 1882 test_when_finished "git symbolic-ref -d refs/heads/symref" && 1883 format_command $type "symref-create refs/heads/symref" "$a" >stdin && 1884 git update-ref --create-reflog --stdin $type --no-deref expect && 1886 echo $a >actual && 1887 test_cmp expect actual && 1888 git reflog exists refs/heads/symref 1889 ' 1890 1891 test_expect_success "stdin $type symref-update fails with too many arguments" ' 1892 format_command $type "symref-update refs/heads/symref" "$a" "ref" "$a" "$a" >stdin && 1893 test_must_fail git update-ref --stdin $type --no-deref err && 1894 if test "$type" = "-z" 1895 then 1896 test_grep "fatal: unknown command: $a" err 1897 else 1898 test_grep "fatal: symref-update refs/heads/symref: extra input: $a" err 1899 fi 1900 ' 1901 1902 test_expect_success "stdin $type symref-update fails with wrong old value argument" ' 1903 format_command $type "symref-update refs/heads/symref" "$a" "foo" "$a" "$a" >stdin && 1904 test_must_fail git update-ref --stdin $type --no-deref err && 1905 test_grep "fatal: symref-update refs/heads/symref: invalid arg ${SQ}foo${SQ} for old value" err 1906 ' 1907 1908 test_expect_success "stdin $type symref-update creates with zero old value" ' 1909 test_when_finished "git symbolic-ref -d refs/heads/symref" && 1910 format_command $type "symref-update refs/heads/symref" "$a" "oid" "$Z" >stdin && 1911 git update-ref --stdin $type --no-deref expect && 1913 git symbolic-ref refs/heads/symref >actual && 1914 test_cmp expect actual 1915 ' 1916 1917 test_expect_success "stdin $type symref-update creates with no old value" ' 1918 test_when_finished "git symbolic-ref -d refs/heads/symref" && 1919 format_command $type "symref-update refs/heads/symref" "$a" >stdin && 1920 git update-ref --stdin $type --no-deref expect && 1922 git symbolic-ref refs/heads/symref >actual && 1923 test_cmp expect actual 1924 ' 1925 1926 test_expect_success "stdin $type symref-update creates dangling" ' 1927 test_when_finished "git symbolic-ref -d refs/heads/symref" && 1928 test_must_fail git rev-parse refs/heads/nonexistent && 1929 format_command $type "symref-update refs/heads/symref" "refs/heads/nonexistent" >stdin && 1930 git update-ref --stdin $type --no-deref expect && 1932 git symbolic-ref refs/heads/symref >actual && 1933 test_cmp expect actual 1934 ' 1935 1936 test_expect_success "stdin $type symref-update fails with wrong old value" ' 1937 test_when_finished "git symbolic-ref -d refs/heads/symref" && 1938 git symbolic-ref refs/heads/symref $a && 1939 format_command $type "symref-update refs/heads/symref" "$m" "ref" "$b" >stdin && 1940 test_must_fail git update-ref --stdin $type --no-deref err && 1941 test_grep "fatal: verifying symref target: ${SQ}refs/heads/symref${SQ}: is at $a but expected $b" err && 1942 test_must_fail git rev-parse --verify -q $c 1943 ' 1944 1945 test_expect_success "stdin $type symref-update updates dangling ref" ' 1946 test_when_finished "git symbolic-ref -d refs/heads/symref" && 1947 test_must_fail git rev-parse refs/heads/nonexistent && 1948 git symbolic-ref refs/heads/symref refs/heads/nonexistent && 1949 format_command $type "symref-update refs/heads/symref" "$a" >stdin && 1950 git update-ref --stdin $type --no-deref expect && 1952 git symbolic-ref refs/heads/symref >actual && 1953 test_cmp expect actual 1954 ' 1955 1956 test_expect_success "stdin $type symref-update updates dangling ref with old value" ' 1957 test_when_finished "git symbolic-ref -d refs/heads/symref" && 1958 test_must_fail git rev-parse refs/heads/nonexistent && 1959 git symbolic-ref refs/heads/symref refs/heads/nonexistent && 1960 format_command $type "symref-update refs/heads/symref" "$a" "ref" "refs/heads/nonexistent" >stdin && 1961 git update-ref --stdin $type --no-deref expect && 1963 git symbolic-ref refs/heads/symref >actual && 1964 test_cmp expect actual 1965 ' 1966 1967 test_expect_success "stdin $type symref-update fails update dangling ref with wrong old value" ' 1968 test_when_finished "git symbolic-ref -d refs/heads/symref" && 1969 test_must_fail git rev-parse refs/heads/nonexistent && 1970 git symbolic-ref refs/heads/symref refs/heads/nonexistent && 1971 format_command $type "symref-update refs/heads/symref" "$a" "ref" "refs/heads/wrongref" >stdin && 1972 test_must_fail git update-ref --stdin $type --no-deref expect && 1974 git symbolic-ref refs/heads/symref >actual && 1975 test_cmp expect actual 1976 ' 1977 1978 test_expect_success "stdin $type symref-update works with right old value" ' 1979 test_when_finished "git symbolic-ref -d refs/heads/symref" && 1980 git symbolic-ref refs/heads/symref $a && 1981 format_command $type "symref-update refs/heads/symref" "$m" "ref" "$a" >stdin && 1982 git update-ref --stdin $type --no-deref expect && 1984 git symbolic-ref refs/heads/symref >actual && 1985 test_cmp expect actual 1986 ' 1987 1988 test_expect_success "stdin $type symref-update works with no old value" ' 1989 test_when_finished "git symbolic-ref -d refs/heads/symref" && 1990 git symbolic-ref refs/heads/symref $a && 1991 format_command $type "symref-update refs/heads/symref" "$m" >stdin && 1992 git update-ref --stdin $type --no-deref expect && 1994 git symbolic-ref refs/heads/symref >actual && 1995 test_cmp expect actual 1996 ' 1997 1998 test_expect_success "stdin $type symref-update fails with empty old ref-target" ' 1999 test_when_finished "git symbolic-ref -d refs/heads/symref" && 2000 git symbolic-ref refs/heads/symref $a && 2001 format_command $type "symref-update refs/heads/symref" "$m" "ref" "" >stdin && 2002 test_must_fail git update-ref --stdin $type --no-deref expect && 2004 git symbolic-ref refs/heads/symref >actual && 2005 test_cmp expect actual 2006 ' 2007 2008 test_expect_success "stdin $type symref-update creates (with deref)" ' 2009 test_when_finished "git symbolic-ref -d refs/heads/symref" && 2010 format_command $type "symref-update refs/heads/symref" "$a" >stdin && 2011 git update-ref --stdin $type expect && 2013 git symbolic-ref --no-recurse refs/heads/symref >actual && 2014 test_cmp expect actual && 2015 test-tool ref-store main for-each-reflog-ent refs/heads/symref >actual && 2016 test_grep "$Z $(git rev-parse $a)" actual 2017 ' 2018 2019 test_expect_success "stdin $type symref-update regular ref to symref with correct old-oid" ' 2020 test_when_finished "git symbolic-ref -d --no-recurse refs/heads/regularref" && 2021 git update-ref --no-deref refs/heads/regularref $a && 2022 format_command $type "symref-update refs/heads/regularref" "$a" "oid" "$(git rev-parse $a)" >stdin && 2023 git update-ref --stdin $type expect && 2025 git symbolic-ref --no-recurse refs/heads/regularref >actual && 2026 test_cmp expect actual && 2027 test-tool ref-store main for-each-reflog-ent refs/heads/regularref >actual && 2028 test_grep "$(git rev-parse $a) $(git rev-parse $a)" actual 2029 ' 2030 2031 test_expect_success "stdin $type symref-update regular ref to symref fails with wrong old-oid" ' 2032 test_when_finished "git update-ref -d refs/heads/regularref" && 2033 git update-ref --no-deref refs/heads/regularref $a && 2034 format_command $type "symref-update refs/heads/regularref" "$a" "oid" "$(git rev-parse refs/heads/target2)" >stdin && 2035 test_must_fail git update-ref --stdin $type err && 2036 test_grep "fatal: cannot lock ref ${SQ}refs/heads/regularref${SQ}: is at $(git rev-parse $a) but expected $(git rev-parse refs/heads/target2)" err && 2037 echo $(git rev-parse $a) >expect && 2038 git rev-parse refs/heads/regularref >actual && 2039 test_cmp expect actual 2040 ' 2041 2042 test_expect_success "stdin $type symref-update regular ref to symref fails with invalid old-oid" ' 2043 test_when_finished "git update-ref -d refs/heads/regularref" && 2044 git update-ref --no-deref refs/heads/regularref $a && 2045 format_command $type "symref-update refs/heads/regularref" "$a" "oid" "not-a-ref-oid" >stdin && 2046 test_must_fail git update-ref --stdin $type err && 2047 test_grep "fatal: symref-update refs/heads/regularref: invalid oid: not-a-ref-oid" err && 2048 echo $(git rev-parse $a) >expect && 2049 git rev-parse refs/heads/regularref >actual && 2050 test_cmp expect actual 2051 ' 2052 2053 test_expect_success "stdin $type symref-update existing symref with zero old-oid" ' 2054 test_when_finished "git symbolic-ref -d --no-recurse refs/heads/symref" && 2055 git symbolic-ref refs/heads/symref refs/heads/target2 && 2056 format_command $type "symref-update refs/heads/symref" "$a" "oid" "$Z" >stdin && 2057 test_must_fail git update-ref --stdin $type err && 2058 test_grep "fatal: cannot lock ref ${SQ}refs/heads/symref${SQ}: reference already exists" err && 2059 echo refs/heads/target2 >expect && 2060 git symbolic-ref refs/heads/symref >actual && 2061 test_cmp expect actual 2062 ' 2063 2064 test_expect_success "stdin $type symref-update regular ref to symref (with deref)" ' 2065 test_when_finished "git symbolic-ref -d refs/heads/symref" && 2066 test_when_finished "git update-ref -d --no-deref refs/heads/symref2" && 2067 git update-ref refs/heads/symref2 $a && 2068 git symbolic-ref --no-recurse refs/heads/symref refs/heads/symref2 && 2069 format_command $type "symref-update refs/heads/symref" "$a" >stdin && 2070 git update-ref $type --stdin expect && 2072 git symbolic-ref --no-recurse refs/heads/symref2 >actual && 2073 test_cmp expect actual && 2074 echo refs/heads/symref2 >expect && 2075 git symbolic-ref --no-recurse refs/heads/symref >actual && 2076 test_cmp expect actual && 2077 test-tool ref-store main for-each-reflog-ent refs/heads/symref >actual && 2078 test_grep "$(git rev-parse $a) $(git rev-parse $a)" actual 2079 ' 2080 2081 test_expect_success "stdin $type symref-update regular ref to symref" ' 2082 test_when_finished "git symbolic-ref -d --no-recurse refs/heads/regularref" && 2083 git update-ref --no-deref refs/heads/regularref $a && 2084 format_command $type "symref-update refs/heads/regularref" "$a" >stdin && 2085 git update-ref $type --stdin expect && 2087 git symbolic-ref --no-recurse refs/heads/regularref >actual && 2088 test_cmp expect actual && 2089 test-tool ref-store main for-each-reflog-ent refs/heads/regularref >actual && 2090 test_grep "$(git rev-parse $a) $(git rev-parse $a)" actual 2091 ' 2092 2093 test_expect_success "stdin $type batch-updates" ' 2094 git init repo && 2095 test_when_finished "rm -fr repo" && 2096 ( 2097 cd repo && 2098 test_commit commit && 2099 head=$(git rev-parse HEAD) && 2100 2101 format_command $type "update refs/heads/ref1" "$head" "$Z" >stdin && 2102 format_command $type "update refs/heads/ref2" "$head" "$Z" >>stdin && 2103 git update-ref $type --stdin --batch-updates expect && 2105 git rev-parse refs/heads/ref1 >actual && 2106 test_cmp expect actual && 2107 git rev-parse refs/heads/ref2 >actual && 2108 test_cmp expect actual 2109 ) 2110 ' 2111 2112 test_expect_success "stdin $type batch-updates with invalid new_oid" ' 2113 git init repo && 2114 test_when_finished "rm -fr repo" && 2115 ( 2116 cd repo && 2117 test_commit one && 2118 old_head=$(git rev-parse HEAD) && 2119 test_commit two && 2120 head=$(git rev-parse HEAD) && 2121 git update-ref refs/heads/ref1 $head && 2122 git update-ref refs/heads/ref2 $head && 2123 2124 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin && 2125 format_command $type "update refs/heads/ref2" "$(test_oid 001)" "$head" >>stdin && 2126 git update-ref $type --stdin --batch-updates stdout 2>err && 2127 echo $old_head >expect && 2128 git rev-parse refs/heads/ref1 >actual && 2129 test_cmp expect actual && 2130 echo $head >expect && 2131 git rev-parse refs/heads/ref2 >actual && 2132 test_cmp expect actual && 2133 test_grep "rejected refs/heads/ref2 $(test_oid 001) $head invalid new value provided" stdout && 2134 test_grep "trying to write ref ${SQ}refs/heads/ref2${SQ} with nonexistent object" err 2135 ) 2136 ' 2137 2138 test_expect_success "stdin $type batch-updates with non-commit new_oid" ' 2139 git init repo && 2140 test_when_finished "rm -fr repo" && 2141 ( 2142 cd repo && 2143 test_commit one && 2144 old_head=$(git rev-parse HEAD) && 2145 test_commit two && 2146 head=$(git rev-parse HEAD) && 2147 head_tree=$(git rev-parse HEAD^{tree}) && 2148 git update-ref refs/heads/ref1 $head && 2149 git update-ref refs/heads/ref2 $head && 2150 2151 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin && 2152 format_command $type "update refs/heads/ref2" "$head_tree" "$head" >>stdin && 2153 git update-ref $type --stdin --batch-updates stdout 2>err && 2154 echo $old_head >expect && 2155 git rev-parse refs/heads/ref1 >actual && 2156 test_cmp expect actual && 2157 echo $head >expect && 2158 git rev-parse refs/heads/ref2 >actual && 2159 test_cmp expect actual && 2160 test_grep "rejected refs/heads/ref2 $head_tree $head invalid new value provided" stdout && 2161 test_grep "trying to write non-commit object $head_tree to branch ${SQ}refs/heads/ref2${SQ}" err 2162 ) 2163 ' 2164 2165 test_expect_success "stdin $type batch-updates with non-existent ref" ' 2166 git init repo && 2167 test_when_finished "rm -fr repo" && 2168 ( 2169 cd repo && 2170 test_commit one && 2171 old_head=$(git rev-parse HEAD) && 2172 test_commit two && 2173 head=$(git rev-parse HEAD) && 2174 git update-ref refs/heads/ref1 $head && 2175 2176 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin && 2177 format_command $type "update refs/heads/ref2" "$old_head" "$head" >>stdin && 2178 git update-ref $type --stdin --batch-updates stdout 2>err && 2179 echo $old_head >expect && 2180 git rev-parse refs/heads/ref1 >actual && 2181 test_cmp expect actual && 2182 test_must_fail git rev-parse refs/heads/ref2 && 2183 test_grep "rejected refs/heads/ref2 $old_head $head reference does not exist" stdout && 2184 test_grep "cannot lock ref ${SQ}refs/heads/ref2${SQ}: unable to resolve reference ${SQ}refs/heads/ref2${SQ}" err 2185 ) 2186 ' 2187 2188 test_expect_success "stdin $type batch-updates with dangling symref" ' 2189 git init repo && 2190 test_when_finished "rm -fr repo" && 2191 ( 2192 cd repo && 2193 test_commit one && 2194 old_head=$(git rev-parse HEAD) && 2195 test_commit two && 2196 head=$(git rev-parse HEAD) && 2197 git update-ref refs/heads/ref1 $head && 2198 git symbolic-ref refs/heads/ref2 refs/heads/nonexistent && 2199 2200 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin && 2201 format_command $type "update refs/heads/ref2" "$old_head" "$head" >>stdin && 2202 git update-ref $type --no-deref --stdin --batch-updates stdout 2>err && 2203 echo $old_head >expect && 2204 git rev-parse refs/heads/ref1 >actual && 2205 test_cmp expect actual && 2206 echo $head >expect && 2207 test_must_fail git rev-parse refs/heads/ref2 && 2208 test_grep "rejected refs/heads/ref2 $old_head $head reference does not exist" stdout && 2209 test_grep "cannot lock ref ${SQ}refs/heads/ref2${SQ}: reference is missing but expected $head" err 2210 ) 2211 ' 2212 2213 test_expect_success "stdin $type batch-updates with regular ref as symref" ' 2214 git init repo && 2215 test_when_finished "rm -fr repo" && 2216 ( 2217 cd repo && 2218 test_commit one && 2219 old_head=$(git rev-parse HEAD) && 2220 test_commit two && 2221 head=$(git rev-parse HEAD) && 2222 git update-ref refs/heads/ref1 $head && 2223 git update-ref refs/heads/ref2 $head && 2224 2225 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin && 2226 format_command $type "symref-update refs/heads/ref2" "$old_head" "ref" "refs/heads/nonexistent" >>stdin && 2227 git update-ref $type --no-deref --stdin --batch-updates stdout 2>err && 2228 echo $old_head >expect && 2229 git rev-parse refs/heads/ref1 >actual && 2230 test_cmp expect actual && 2231 echo $head >expect && 2232 echo $head >expect && 2233 git rev-parse refs/heads/ref2 >actual && 2234 test_cmp expect actual && 2235 test_grep "rejected refs/heads/ref2 $ZERO_OID $ZERO_OID expected symref but found regular ref" stdout && 2236 test_grep "cannot lock ref ${SQ}refs/heads/ref2${SQ}: expected symref with target ${SQ}refs/heads/nonexistent${SQ}: but is a regular ref" err 2237 ) 2238 ' 2239 2240 test_expect_success "stdin $type batch-updates with invalid old_oid" ' 2241 git init repo && 2242 test_when_finished "rm -fr repo" && 2243 ( 2244 cd repo && 2245 test_commit one && 2246 old_head=$(git rev-parse HEAD) && 2247 test_commit two && 2248 head=$(git rev-parse HEAD) && 2249 git update-ref refs/heads/ref1 $head && 2250 git update-ref refs/heads/ref2 $head && 2251 2252 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin && 2253 format_command $type "update refs/heads/ref2" "$old_head" "$Z" >>stdin && 2254 git update-ref $type --stdin --batch-updates stdout 2>err && 2255 echo $old_head >expect && 2256 git rev-parse refs/heads/ref1 >actual && 2257 test_cmp expect actual && 2258 echo $head >expect && 2259 git rev-parse refs/heads/ref2 >actual && 2260 test_cmp expect actual && 2261 test_grep "rejected refs/heads/ref2 $old_head $ZERO_OID reference already exists" stdout && 2262 test_grep "cannot lock ref ${SQ}refs/heads/ref2${SQ}: reference already exists" err 2263 ) 2264 ' 2265 2266 test_expect_success "stdin $type batch-updates with incorrect old oid" ' 2267 git init repo && 2268 test_when_finished "rm -fr repo" && 2269 ( 2270 cd repo && 2271 test_commit one && 2272 old_head=$(git rev-parse HEAD) && 2273 test_commit two && 2274 head=$(git rev-parse HEAD) && 2275 git update-ref refs/heads/ref1 $head && 2276 git update-ref refs/heads/ref2 $head && 2277 2278 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin && 2279 format_command $type "update refs/heads/ref2" "$head" "$old_head" >>stdin && 2280 git update-ref $type --stdin --batch-updates stdout 2>err && 2281 echo $old_head >expect && 2282 git rev-parse refs/heads/ref1 >actual && 2283 test_cmp expect actual && 2284 echo $head >expect && 2285 git rev-parse refs/heads/ref2 >actual && 2286 test_cmp expect actual && 2287 test_grep "rejected refs/heads/ref2 $head $old_head incorrect old value provided" stdout && 2288 test_grep "cannot lock ref ${SQ}refs/heads/ref2${SQ}: is at $head but expected $old_head" err 2289 ) 2290 ' 2291 2292 test_expect_success "stdin $type batch-updates refname conflict" ' 2293 git init repo && 2294 test_when_finished "rm -fr repo" && 2295 ( 2296 cd repo && 2297 test_commit one && 2298 old_head=$(git rev-parse HEAD) && 2299 test_commit two && 2300 head=$(git rev-parse HEAD) && 2301 git update-ref refs/heads/ref/foo $head && 2302 2303 format_command $type "update refs/heads/ref/foo" "$old_head" "$head" >stdin && 2304 format_command $type "update refs/heads/ref" "$old_head" "$ZERO_OID" >>stdin && 2305 git update-ref $type --stdin --batch-updates stdout 2>err && 2306 echo $old_head >expect && 2307 git rev-parse refs/heads/ref/foo >actual && 2308 test_cmp expect actual && 2309 test_grep "rejected refs/heads/ref $old_head $ZERO_OID refname conflict" stdout && 2310 test_grep "${SQ}refs/heads/ref/foo${SQ} exists; cannot create ${SQ}refs/heads/ref${SQ}" err 2311 ) 2312 ' 2313 2314 test_expect_success "stdin $type batch-updates refname conflict new ref" ' 2315 git init repo && 2316 test_when_finished "rm -fr repo" && 2317 ( 2318 cd repo && 2319 test_commit one && 2320 old_head=$(git rev-parse HEAD) && 2321 test_commit two && 2322 head=$(git rev-parse HEAD) && 2323 git update-ref refs/heads/ref/foo $head && 2324 2325 format_command $type "update refs/heads/foo" "$old_head" "$ZERO_OID" >stdin && 2326 format_command $type "update refs/heads/ref" "$old_head" "$ZERO_OID" >>stdin && 2327 git update-ref $type --stdin --batch-updates stdout 2>err && 2328 echo $old_head >expect && 2329 git rev-parse refs/heads/foo >actual && 2330 test_cmp expect actual && 2331 test_grep "rejected refs/heads/ref $old_head $ZERO_OID refname conflict" stdout && 2332 test_grep "${SQ}refs/heads/ref/foo${SQ} exists; cannot create ${SQ}refs/heads/ref${SQ}" err 2333 ) 2334 ' 2335 2336 test_expect_success CASE_INSENSITIVE_FS,REFFILES "stdin $type batch-updates existing reference" ' 2337 git init repo && 2338 test_when_finished "rm -fr repo" && 2339 ( 2340 cd repo && 2341 test_commit one && 2342 old_head=$(git rev-parse HEAD) && 2343 test_commit two && 2344 head=$(git rev-parse HEAD) && 2345 2346 { 2347 format_command $type "create refs/heads/foo" "$head" && 2348 format_command $type "create refs/heads/ref" "$old_head" && 2349 format_command $type "create refs/heads/Foo" "$old_head" 2350 } >stdin && 2351 git update-ref $type --stdin --batch-updates stdout 2>err && 2352 2353 echo $head >expect && 2354 git rev-parse refs/heads/foo >actual && 2355 echo $old_head >expect && 2356 git rev-parse refs/heads/ref >actual && 2357 test_cmp expect actual && 2358 test_grep "rejected refs/heads/Foo $old_head $ZERO_OID reference conflict due to case-insensitive filesystem" stdout && 2359 test_grep -e "cannot lock ref ${SQ}refs/heads/Foo${SQ}: Unable to create" -e "Foo.lock" err 2360 ) 2361 ' 2362 2363 test_expect_success CASE_INSENSITIVE_FS "stdin $type batch-updates existing reference" ' 2364 git init --ref-storage-format=reftable repo && 2365 test_when_finished "rm -fr repo" && 2366 ( 2367 cd repo && 2368 test_commit one && 2369 old_head=$(git rev-parse HEAD) && 2370 test_commit two && 2371 head=$(git rev-parse HEAD) && 2372 2373 { 2374 format_command $type "create refs/heads/foo" "$head" && 2375 format_command $type "create refs/heads/ref" "$old_head" && 2376 format_command $type "create refs/heads/Foo" "$old_head" 2377 } >stdin && 2378 git update-ref $type --stdin --batch-updates stdout && 2379 2380 echo $head >expect && 2381 git rev-parse refs/heads/foo >actual && 2382 echo $old_head >expect && 2383 git rev-parse refs/heads/ref >actual && 2384 test_cmp expect actual && 2385 git rev-parse refs/heads/Foo >actual && 2386 test_cmp expect actual 2387 ) 2388 ' 2389 2390 test_expect_success "stdin $type batch-updates delete incorrect symbolic ref" ' 2391 git init repo && 2392 test_when_finished "rm -fr repo" && 2393 ( 2394 cd repo && 2395 test_commit c1 && 2396 head=$(git rev-parse HEAD) && 2397 git symbolic-ref refs/heads/symbolic refs/heads/non-existent && 2398 2399 format_command $type "delete refs/heads/symbolic" "$head" >stdin && 2400 git update-ref $type --stdin --batch-updates stdout 2>err && 2401 test_grep "rejected refs/heads/non-existent $ZERO_OID $head reference does not exist" stdout && 2402 test_grep "cannot lock ref ${SQ}refs/heads/symbolic${SQ}: unable to resolve reference ${SQ}refs/heads/non-existent${SQ}" err 2403 ) 2404 ' 2405 2406 test_expect_success "stdin $type batch-updates delete with incorrect old_oid" ' 2407 git init repo && 2408 test_when_finished "rm -fr repo" && 2409 ( 2410 cd repo && 2411 test_commit c1 && 2412 git branch new-branch && 2413 test_commit c2 && 2414 head=$(git rev-parse HEAD) && 2415 2416 format_command $type "delete refs/heads/new-branch" "$head" >stdin && 2417 git update-ref $type --stdin --batch-updates stdout 2>err && 2418 test_grep "rejected refs/heads/new-branch $ZERO_OID $head incorrect old value provided" stdout && 2419 test_grep "cannot lock ref ${SQ}refs/heads/new-branch${SQ}: is at $(git rev-parse new-branch) but expected $head" err 2420 ) 2421 ' 2422 2423 test_expect_success "stdin $type batch-updates delete non-existent ref" ' 2424 git init repo && 2425 test_when_finished "rm -fr repo" && 2426 ( 2427 cd repo && 2428 test_commit commit && 2429 head=$(git rev-parse HEAD) && 2430 2431 format_command $type "delete refs/heads/non-existent" "$head" >stdin && 2432 git update-ref $type --stdin --batch-updates stdout 2>err && 2433 test_grep "rejected refs/heads/non-existent $ZERO_OID $head reference does not exist" stdout && 2434 test_grep "cannot lock ref ${SQ}refs/heads/non-existent${SQ}: unable to resolve reference ${SQ}refs/heads/non-existent${SQ}" err 2435 ) 2436 ' 2437 done 2438 2439 test_expect_success 'update-ref should also create reflog for HEAD' ' 2440 test_commit to-rewind && 2441 git rev-parse HEAD >expect && 2442 head=$(git symbolic-ref HEAD) && 2443 git update-ref --create-reflog "$head" HEAD~ && 2444 git rev-parse HEAD@{1} >actual && 2445 test_cmp expect actual 2446 ' 2447 2448 test_expect_success REFFILES 'empty directories are pruned when aborting a transaction' ' 2449 test_path_is_missing .git/refs/heads/nested && 2450 git update-ref --stdin <<-EOF && 2451 create refs/heads/nested/something HEAD 2452 prepare 2453 abort 2454 EOF 2455 test_path_is_missing .git/refs/heads/nested 2456 ' 2457 2458 test_expect_success REFFILES 'empty directories are pruned when not committing' ' 2459 test_path_is_missing .git/refs/heads/nested && 2460 git update-ref --stdin <<-EOF && 2461 create refs/heads/nested/something HEAD 2462 prepare 2463 EOF 2464 test_path_is_missing .git/refs/heads/nested 2465 ' 2466 2467 test_expect_success 'dangling symref not overwritten by creation' ' 2468 test_when_finished "git update-ref -d refs/heads/dangling" && 2469 git symbolic-ref refs/heads/dangling refs/heads/does-not-exist && 2470 test_must_fail git update-ref --no-deref --stdin 2>err <<-\EOF && 2471 create refs/heads/dangling HEAD 2472 EOF 2473 test_grep "cannot lock.*dangling symref already exists" err && 2474 test_must_fail git rev-parse --verify refs/heads/dangling && 2475 test_must_fail git rev-parse --verify refs/heads/does-not-exist 2476 ' 2477 2478 test_expect_success 'dangling symref overwritten without old oid' ' 2479 test_when_finished "git update-ref -d refs/heads/dangling" && 2480 git symbolic-ref refs/heads/dangling refs/heads/does-not-exist && 2481 git update-ref --no-deref --stdin <<-\EOF && 2482 update refs/heads/dangling HEAD 2483 EOF 2484 git rev-parse --verify refs/heads/dangling && 2485 test_must_fail git rev-parse --verify refs/heads/does-not-exist 2486 ' 2487 2488 test_done