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