3 # Copyright (c) 2006 Shawn Pearce
6 test_description='Test git update-ref and basic ref logging'
11 test_expect_success setup '
13 for name in A B C D E F
16 T=$(git write-tree) &&
17 sha1=$(echo $name | git commit-tree $T) &&
30 "git update-ref $m $A &&
31 test $A"' = $(cat .git/'"$m"')'
34 "git update-ref $m $B $A &&
35 test $B"' = $(cat .git/'"$m"')'
36 test_expect_success "fail to delete $m with stale ref" '
37 test_must_fail git update-ref -d $m $A &&
38 test $B = "$(cat .git/$m)"
40 test_expect_success "delete $m" '
41 git update-ref -d $m $B &&
46 test_expect_success "delete $m without oldvalue verification" "
47 git update-ref $m $A &&
48 test $A = \$(cat .git/$m) &&
49 git update-ref -d $m &&
57 test_must_fail git update-ref $n $A >out 2>err"
58 rm -f .git/$n_dir out err
61 "create $m (by HEAD)" \
62 "git update-ref HEAD $A &&
63 test $A"' = $(cat .git/'"$m"')'
65 "create $m (by HEAD)" \
66 "git update-ref HEAD $B $A &&
67 test $B"' = $(cat .git/'"$m"')'
68 test_expect_success "fail to delete $m (by HEAD) with stale ref" '
69 test_must_fail git update-ref -d HEAD $A &&
70 test $B = $(cat .git/$m)
72 test_expect_success "delete $m (by HEAD)" '
73 git update-ref -d HEAD $B &&
78 test_expect_success 'update-ref does not create reflogs by default' '
79 test_when_finished "git update-ref -d $outside" &&
80 git update-ref $outside $A &&
81 git rev-parse $A >expect &&
82 git rev-parse $outside >actual &&
83 test_cmp expect actual &&
84 test_must_fail git reflog exists $outside
87 test_expect_success 'update-ref creates reflogs with --create-reflog' '
88 test_when_finished "git update-ref -d $outside" &&
89 git update-ref --create-reflog $outside $A &&
90 git rev-parse $A >expect &&
91 git rev-parse $outside >actual &&
92 test_cmp expect actual &&
93 git reflog exists $outside
97 "create $m (by HEAD)" \
98 "git update-ref HEAD $A &&
99 test $A"' = $(cat .git/'"$m"')'
100 test_expect_success \
102 "git pack-refs --all"
103 test_expect_success \
104 "move $m (by HEAD)" \
105 "git update-ref HEAD $B $A &&
106 test $B"' = $(cat .git/'"$m"')'
107 test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" '
108 git update-ref -d HEAD $B &&
109 ! grep "$m" .git/packed-refs &&
114 cp -f .git/HEAD .git/HEAD.orig
115 test_expect_success "delete symref without dereference" '
116 git update-ref --no-deref -d HEAD &&
119 cp -f .git/HEAD.orig .git/HEAD
121 test_expect_success "delete symref without dereference when the referred ref is packed" '
125 git pack-refs --all &&
126 git update-ref --no-deref -d HEAD &&
129 cp -f .git/HEAD.orig .git/HEAD
132 test_expect_success 'update-ref -d is not confused by self-reference' '
133 git symbolic-ref refs/heads/self refs/heads/self &&
134 test_when_finished "rm -f .git/refs/heads/self" &&
135 test_path_is_file .git/refs/heads/self &&
136 test_must_fail git update-ref -d refs/heads/self &&
137 test_path_is_file .git/refs/heads/self
140 test_expect_success 'update-ref --no-deref -d can delete self-reference' '
141 git symbolic-ref refs/heads/self refs/heads/self &&
142 test_when_finished "rm -f .git/refs/heads/self" &&
143 test_path_is_file .git/refs/heads/self &&
144 git update-ref --no-deref -d refs/heads/self &&
145 test_path_is_missing .git/refs/heads/self
148 test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
149 >.git/refs/heads/bad &&
150 test_when_finished "rm -f .git/refs/heads/bad" &&
151 git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
152 test_when_finished "rm -f .git/refs/heads/ref-to-bad" &&
153 test_path_is_file .git/refs/heads/ref-to-bad &&
154 git update-ref --no-deref -d refs/heads/ref-to-bad &&
155 test_path_is_missing .git/refs/heads/ref-to-bad
158 test_expect_success '(not) create HEAD with old sha1' "
159 test_must_fail git update-ref HEAD $A $B
161 test_expect_success "(not) prior created .git/$m" "
166 test_expect_success \
168 "git update-ref HEAD $A"
169 test_expect_success '(not) change HEAD with wrong SHA1' "
170 test_must_fail git update-ref HEAD $B $Z
172 test_expect_success "(not) changed .git/$m" "
173 ! test $B"' = $(cat .git/'"$m"')
177 : a repository with working tree always has reflog these days...
178 : >.git/logs/refs/heads/master
179 test_expect_success \
180 "create $m (logged by touch)" \
181 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
182 git update-ref HEAD '"$A"' -m "Initial Creation" &&
183 test '"$A"' = $(cat .git/'"$m"')'
184 test_expect_success \
185 "update $m (logged by touch)" \
186 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
187 git update-ref HEAD'" $B $A "'-m "Switch" &&
188 test '"$B"' = $(cat .git/'"$m"')'
189 test_expect_success \
190 "set $m (logged by touch)" \
191 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
192 git update-ref HEAD'" $A &&
193 test $A"' = $(cat .git/'"$m"')'
196 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
197 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
198 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
200 test_expect_success \
201 "verifying $m's log" \
202 "test_cmp expect .git/logs/$m"
203 rm -rf .git/$m .git/logs expect
205 test_expect_success \
206 'enable core.logAllRefUpdates' \
207 'git config core.logAllRefUpdates true &&
208 test true = $(git config --bool --get core.logAllRefUpdates)'
210 test_expect_success \
211 "create $m (logged by config)" \
212 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
213 git update-ref HEAD'" $A "'-m "Initial Creation" &&
214 test '"$A"' = $(cat .git/'"$m"')'
215 test_expect_success \
216 "update $m (logged by config)" \
217 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
218 git update-ref HEAD'" $B $A "'-m "Switch" &&
219 test '"$B"' = $(cat .git/'"$m"')'
220 test_expect_success \
221 "set $m (logged by config)" \
222 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
223 git update-ref HEAD '"$A &&
224 test $A"' = $(cat .git/'"$m"')'
227 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
228 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
229 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
231 test_expect_success \
232 "verifying $m's log" \
233 'test_cmp expect .git/logs/$m'
234 rm -f .git/$m .git/logs/$m expect
237 cat >.git/logs/$m <<EOF
238 0000000000000000000000000000000000000000 $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
239 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
240 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
241 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
242 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
245 ed="Thu, 26 May 2005 18:32:00 -0500"
246 gd="Thu, 26 May 2005 18:33:00 -0500"
247 ld="Thu, 26 May 2005 18:43:00 -0500"
248 test_expect_success \
249 'Query "master@{May 25 2005}" (before history)' \
251 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
252 test '"$C"' = $(cat o) &&
253 test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
254 test_expect_success \
255 "Query master@{2005-05-25} (before history)" \
257 git rev-parse --verify master@{2005-05-25} >o 2>e &&
258 test '"$C"' = $(cat o) &&
259 echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
260 test_expect_success \
261 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
263 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
264 test '"$C"' = $(cat o) &&
265 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
266 test_expect_success \
267 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
269 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
270 test '"$C"' = $(cat o) &&
271 test "" = "$(cat e)"'
272 test_expect_success \
273 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \
275 git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e &&
276 test '"$A"' = $(cat o) &&
277 test "" = "$(cat e)"'
278 test_expect_success \
279 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
281 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
282 test '"$B"' = $(cat o) &&
283 test "warning: Log for ref '"$m has gap after $gd"'." = "$(cat e)"'
284 test_expect_success \
285 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
287 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
288 test '"$Z"' = $(cat o) &&
289 test "" = "$(cat e)"'
290 test_expect_success \
291 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
293 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
294 test '"$E"' = $(cat o) &&
295 test "" = "$(cat e)"'
296 test_expect_success \
297 'Query "master@{2005-05-28}" (past end of history)' \
299 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
300 test '"$D"' = $(cat o) &&
301 test "warning: Log for ref '"$m unexpectedly ended on $ld"'." = "$(cat e)"'
304 rm -f .git/$m .git/logs/$m expect
306 test_expect_success \
307 'creating initial files' \
310 GIT_AUTHOR_DATE="2005-05-26 23:30" \
311 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
312 h_TEST=$(git rev-parse --verify HEAD) &&
313 echo The other day this did not work. >M &&
314 echo And then Bob told me how to fix it. >>M &&
316 GIT_AUTHOR_DATE="2005-05-26 23:41" \
317 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
318 h_OTHER=$(git rev-parse --verify HEAD) &&
319 GIT_AUTHOR_DATE="2005-05-26 23:44" \
320 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
321 h_FIXED=$(git rev-parse --verify HEAD) &&
322 echo Merged initial commit and a later commit. >M &&
323 echo $h_TEST >.git/MERGE_HEAD &&
324 GIT_AUTHOR_DATE="2005-05-26 23:45" \
325 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
326 h_MERGED=$(git rev-parse --verify HEAD) &&
330 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
331 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
332 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
333 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
335 test_expect_success \
336 'git commit logged updates' \
337 "test_cmp expect .git/logs/$m"
338 unset h_TEST h_OTHER h_FIXED h_MERGED
340 test_expect_success \
341 'git cat-file blob master:F (expect OTHER)' \
342 'test OTHER = $(git cat-file blob master:F)'
343 test_expect_success \
344 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
345 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")'
346 test_expect_success \
347 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
348 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'
355 pws='path with space'
357 test_expect_success 'stdin test setup' '
358 echo "$pws" >"$pws" &&
363 test_expect_success '-z fails without --stdin' '
364 test_must_fail git update-ref -z $m $m $m 2>err &&
365 grep "usage: git update-ref" err
368 test_expect_success 'stdin works with no input' '
370 git update-ref --stdin <stdin &&
371 git rev-parse --verify -q $m
374 test_expect_success 'stdin fails on empty line' '
376 test_must_fail git update-ref --stdin <stdin 2>err &&
377 grep "fatal: empty command in input" err
380 test_expect_success 'stdin fails on only whitespace' '
382 test_must_fail git update-ref --stdin <stdin 2>err &&
383 grep "fatal: whitespace before command: " err
386 test_expect_success 'stdin fails on leading whitespace' '
387 echo " create $a $m" >stdin &&
388 test_must_fail git update-ref --stdin <stdin 2>err &&
389 grep "fatal: whitespace before command: create $a $m" err
392 test_expect_success 'stdin fails on unknown command' '
393 echo "unknown $a" >stdin &&
394 test_must_fail git update-ref --stdin <stdin 2>err &&
395 grep "fatal: unknown command: unknown $a" err
398 test_expect_success 'stdin fails on unbalanced quotes' '
399 echo "create $a \"master" >stdin &&
400 test_must_fail git update-ref --stdin <stdin 2>err &&
401 grep "fatal: badly quoted argument: \\\"master" err
404 test_expect_success 'stdin fails on invalid escape' '
405 echo "create $a \"ma\zter\"" >stdin &&
406 test_must_fail git update-ref --stdin <stdin 2>err &&
407 grep "fatal: badly quoted argument: \\\"ma\\\\zter\\\"" err
410 test_expect_success 'stdin fails on junk after quoted argument' '
411 echo "create \"$a\"master" >stdin &&
412 test_must_fail git update-ref --stdin <stdin 2>err &&
413 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"master" err
416 test_expect_success 'stdin fails create with no ref' '
417 echo "create " >stdin &&
418 test_must_fail git update-ref --stdin <stdin 2>err &&
419 grep "fatal: create: missing <ref>" err
422 test_expect_success 'stdin fails create with no new value' '
423 echo "create $a" >stdin &&
424 test_must_fail git update-ref --stdin <stdin 2>err &&
425 grep "fatal: create $a: missing <newvalue>" err
428 test_expect_success 'stdin fails create with too many arguments' '
429 echo "create $a $m $m" >stdin &&
430 test_must_fail git update-ref --stdin <stdin 2>err &&
431 grep "fatal: create $a: extra input: $m" err
434 test_expect_success 'stdin fails update with no ref' '
435 echo "update " >stdin &&
436 test_must_fail git update-ref --stdin <stdin 2>err &&
437 grep "fatal: update: missing <ref>" err
440 test_expect_success 'stdin fails update with no new value' '
441 echo "update $a" >stdin &&
442 test_must_fail git update-ref --stdin <stdin 2>err &&
443 grep "fatal: update $a: missing <newvalue>" err
446 test_expect_success 'stdin fails update with too many arguments' '
447 echo "update $a $m $m $m" >stdin &&
448 test_must_fail git update-ref --stdin <stdin 2>err &&
449 grep "fatal: update $a: extra input: $m" err
452 test_expect_success 'stdin fails delete with no ref' '
453 echo "delete " >stdin &&
454 test_must_fail git update-ref --stdin <stdin 2>err &&
455 grep "fatal: delete: missing <ref>" err
458 test_expect_success 'stdin fails delete with too many arguments' '
459 echo "delete $a $m $m" >stdin &&
460 test_must_fail git update-ref --stdin <stdin 2>err &&
461 grep "fatal: delete $a: extra input: $m" err
464 test_expect_success 'stdin fails verify with too many arguments' '
465 echo "verify $a $m $m" >stdin &&
466 test_must_fail git update-ref --stdin <stdin 2>err &&
467 grep "fatal: verify $a: extra input: $m" err
470 test_expect_success 'stdin fails option with unknown name' '
471 echo "option unknown" >stdin &&
472 test_must_fail git update-ref --stdin <stdin 2>err &&
473 grep "fatal: option unknown: unknown" err
476 test_expect_success 'stdin fails with duplicate refs' '
482 test_must_fail git update-ref --stdin <stdin 2>err &&
483 grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
486 test_expect_success 'stdin create ref works' '
487 echo "create $a $m" >stdin &&
488 git update-ref --stdin <stdin &&
489 git rev-parse $m >expect &&
490 git rev-parse $a >actual &&
491 test_cmp expect actual
494 test_expect_success 'stdin does not create reflogs by default' '
495 test_when_finished "git update-ref -d $outside" &&
496 echo "create $outside $m" >stdin &&
497 git update-ref --stdin <stdin &&
498 git rev-parse $m >expect &&
499 git rev-parse $outside >actual &&
500 test_cmp expect actual &&
501 test_must_fail git reflog exists $outside
504 test_expect_success 'stdin creates reflogs with --create-reflog' '
505 echo "create $outside $m" >stdin &&
506 git update-ref --create-reflog --stdin <stdin &&
507 git rev-parse $m >expect &&
508 git rev-parse $outside >actual &&
509 test_cmp expect actual &&
510 git reflog exists $outside
513 test_expect_success 'stdin succeeds with quoted argument' '
514 git update-ref -d $a &&
515 echo "create $a \"$m\"" >stdin &&
516 git update-ref --stdin <stdin &&
517 git rev-parse $m >expect &&
518 git rev-parse $a >actual &&
519 test_cmp expect actual
522 test_expect_success 'stdin succeeds with escaped character' '
523 git update-ref -d $a &&
524 echo "create $a \"ma\\163ter\"" >stdin &&
525 git update-ref --stdin <stdin &&
526 git rev-parse $m >expect &&
527 git rev-parse $a >actual &&
528 test_cmp expect actual
531 test_expect_success 'stdin update ref creates with zero old value' '
532 echo "update $b $m $Z" >stdin &&
533 git update-ref --stdin <stdin &&
534 git rev-parse $m >expect &&
535 git rev-parse $b >actual &&
536 test_cmp expect actual &&
540 test_expect_success 'stdin update ref creates with empty old value' '
541 echo "update $b $m $E" >stdin &&
542 git update-ref --stdin <stdin &&
543 git rev-parse $m >expect &&
544 git rev-parse $b >actual &&
545 test_cmp expect actual
548 test_expect_success 'stdin create ref works with path with space to blob' '
549 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
550 git update-ref --stdin <stdin &&
551 git rev-parse "$m:$pws" >expect &&
552 git rev-parse refs/blobs/pws >actual &&
553 test_cmp expect actual &&
554 git update-ref -d refs/blobs/pws
557 test_expect_success 'stdin update ref fails with wrong old value' '
558 echo "update $c $m $m~1" >stdin &&
559 test_must_fail git update-ref --stdin <stdin 2>err &&
560 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
561 test_must_fail git rev-parse --verify -q $c
564 test_expect_success 'stdin update ref fails with bad old value' '
565 echo "update $c $m does-not-exist" >stdin &&
566 test_must_fail git update-ref --stdin <stdin 2>err &&
567 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
568 test_must_fail git rev-parse --verify -q $c
571 test_expect_success 'stdin create ref fails with bad new value' '
572 echo "create $c does-not-exist" >stdin &&
573 test_must_fail git update-ref --stdin <stdin 2>err &&
574 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
575 test_must_fail git rev-parse --verify -q $c
578 test_expect_success 'stdin create ref fails with zero new value' '
579 echo "create $c " >stdin &&
580 test_must_fail git update-ref --stdin <stdin 2>err &&
581 grep "fatal: create $c: zero <newvalue>" err &&
582 test_must_fail git rev-parse --verify -q $c
585 test_expect_success 'stdin update ref works with right old value' '
586 echo "update $b $m~1 $m" >stdin &&
587 git update-ref --stdin <stdin &&
588 git rev-parse $m~1 >expect &&
589 git rev-parse $b >actual &&
590 test_cmp expect actual
593 test_expect_success 'stdin delete ref fails with wrong old value' '
594 echo "delete $a $m~1" >stdin &&
595 test_must_fail git update-ref --stdin <stdin 2>err &&
596 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
597 git rev-parse $m >expect &&
598 git rev-parse $a >actual &&
599 test_cmp expect actual
602 test_expect_success 'stdin delete ref fails with zero old value' '
603 echo "delete $a " >stdin &&
604 test_must_fail git update-ref --stdin <stdin 2>err &&
605 grep "fatal: delete $a: zero <oldvalue>" err &&
606 git rev-parse $m >expect &&
607 git rev-parse $a >actual &&
608 test_cmp expect actual
611 test_expect_success 'stdin update symref works option no-deref' '
612 git symbolic-ref TESTSYMREF $b &&
615 update TESTSYMREF $a $b
617 git update-ref --stdin <stdin &&
618 git rev-parse TESTSYMREF >expect &&
619 git rev-parse $a >actual &&
620 test_cmp expect actual &&
621 git rev-parse $m~1 >expect &&
622 git rev-parse $b >actual &&
623 test_cmp expect actual
626 test_expect_success 'stdin delete symref works option no-deref' '
627 git symbolic-ref TESTSYMREF $b &&
632 git update-ref --stdin <stdin &&
633 test_must_fail git rev-parse --verify -q TESTSYMREF &&
634 git rev-parse $m~1 >expect &&
635 git rev-parse $b >actual &&
636 test_cmp expect actual
639 test_expect_success 'stdin delete ref works with right old value' '
640 echo "delete $b $m~1" >stdin &&
641 git update-ref --stdin <stdin &&
642 test_must_fail git rev-parse --verify -q $b
645 test_expect_success 'stdin update/create/verify combination works' '
651 git update-ref --stdin <stdin &&
652 git rev-parse $m >expect &&
653 git rev-parse $a >actual &&
654 test_cmp expect actual &&
655 git rev-parse $b >actual &&
656 test_cmp expect actual &&
657 test_must_fail git rev-parse --verify -q $c
660 test_expect_success 'stdin verify succeeds for correct value' '
661 git rev-parse $m >expect &&
662 echo "verify $m $m" >stdin &&
663 git update-ref --stdin <stdin &&
664 git rev-parse $m >actual &&
665 test_cmp expect actual
668 test_expect_success 'stdin verify succeeds for missing reference' '
669 echo "verify refs/heads/missing $Z" >stdin &&
670 git update-ref --stdin <stdin &&
671 test_must_fail git rev-parse --verify -q refs/heads/missing
674 test_expect_success 'stdin verify treats no value as missing' '
675 echo "verify refs/heads/missing" >stdin &&
676 git update-ref --stdin <stdin &&
677 test_must_fail git rev-parse --verify -q refs/heads/missing
680 test_expect_success 'stdin verify fails for wrong value' '
681 git rev-parse $m >expect &&
682 echo "verify $m $m~1" >stdin &&
683 test_must_fail git update-ref --stdin <stdin &&
684 git rev-parse $m >actual &&
685 test_cmp expect actual
688 test_expect_success 'stdin verify fails for mistaken null value' '
689 git rev-parse $m >expect &&
690 echo "verify $m $Z" >stdin &&
691 test_must_fail git update-ref --stdin <stdin &&
692 git rev-parse $m >actual &&
693 test_cmp expect actual
696 test_expect_success 'stdin verify fails for mistaken empty value' '
697 M=$(git rev-parse $m) &&
698 test_when_finished "git update-ref $m $M" &&
699 git rev-parse $m >expect &&
700 echo "verify $m" >stdin &&
701 test_must_fail git update-ref --stdin <stdin &&
702 git rev-parse $m >actual &&
703 test_cmp expect actual
706 test_expect_success 'stdin update refs works with identity updates' '
712 git update-ref --stdin <stdin &&
713 git rev-parse $m >expect &&
714 git rev-parse $a >actual &&
715 test_cmp expect actual &&
716 git rev-parse $b >actual &&
717 test_cmp expect actual &&
718 test_must_fail git rev-parse --verify -q $c
721 test_expect_success 'stdin update refs fails with wrong old value' '
722 git update-ref $c $m &&
728 test_must_fail git update-ref --stdin <stdin 2>err &&
729 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
730 git rev-parse $m >expect &&
731 git rev-parse $a >actual &&
732 test_cmp expect actual &&
733 git rev-parse $b >actual &&
734 test_cmp expect actual &&
735 git rev-parse $c >actual &&
736 test_cmp expect actual
739 test_expect_success 'stdin delete refs works with packed and loose refs' '
740 git pack-refs --all &&
741 git update-ref $c $m~1 &&
747 git update-ref --stdin <stdin &&
748 test_must_fail git rev-parse --verify -q $a &&
749 test_must_fail git rev-parse --verify -q $b &&
750 test_must_fail git rev-parse --verify -q $c
753 test_expect_success 'stdin -z works on empty input' '
755 git update-ref -z --stdin <stdin &&
756 git rev-parse --verify -q $m
759 test_expect_success 'stdin -z fails on empty line' '
761 test_must_fail git update-ref -z --stdin <stdin 2>err &&
762 grep "fatal: whitespace before command: " err
765 test_expect_success 'stdin -z fails on empty command' '
766 printf $F "" >stdin &&
767 test_must_fail git update-ref -z --stdin <stdin 2>err &&
768 grep "fatal: empty command in input" err
771 test_expect_success 'stdin -z fails on only whitespace' '
772 printf $F " " >stdin &&
773 test_must_fail git update-ref -z --stdin <stdin 2>err &&
774 grep "fatal: whitespace before command: " err
777 test_expect_success 'stdin -z fails on leading whitespace' '
778 printf $F " create $a" "$m" >stdin &&
779 test_must_fail git update-ref -z --stdin <stdin 2>err &&
780 grep "fatal: whitespace before command: create $a" err
783 test_expect_success 'stdin -z fails on unknown command' '
784 printf $F "unknown $a" >stdin &&
785 test_must_fail git update-ref -z --stdin <stdin 2>err &&
786 grep "fatal: unknown command: unknown $a" err
789 test_expect_success 'stdin -z fails create with no ref' '
790 printf $F "create " >stdin &&
791 test_must_fail git update-ref -z --stdin <stdin 2>err &&
792 grep "fatal: create: missing <ref>" err
795 test_expect_success 'stdin -z fails create with no new value' '
796 printf $F "create $a" >stdin &&
797 test_must_fail git update-ref -z --stdin <stdin 2>err &&
798 grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
801 test_expect_success 'stdin -z fails create with too many arguments' '
802 printf $F "create $a" "$m" "$m" >stdin &&
803 test_must_fail git update-ref -z --stdin <stdin 2>err &&
804 grep "fatal: unknown command: $m" err
807 test_expect_success 'stdin -z fails update with no ref' '
808 printf $F "update " >stdin &&
809 test_must_fail git update-ref -z --stdin <stdin 2>err &&
810 grep "fatal: update: missing <ref>" err
813 test_expect_success 'stdin -z fails update with too few args' '
814 printf $F "update $a" "$m" >stdin &&
815 test_must_fail git update-ref -z --stdin <stdin 2>err &&
816 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
819 test_expect_success 'stdin -z emits warning with empty new value' '
820 git update-ref $a $m &&
821 printf $F "update $a" "" "" >stdin &&
822 git update-ref -z --stdin <stdin 2>err &&
823 grep "warning: update $a: missing <newvalue>, treating as zero" err &&
824 test_must_fail git rev-parse --verify -q $a
827 test_expect_success 'stdin -z fails update with no new value' '
828 printf $F "update $a" >stdin &&
829 test_must_fail git update-ref -z --stdin <stdin 2>err &&
830 grep "fatal: update $a: unexpected end of input when reading <newvalue>" err
833 test_expect_success 'stdin -z fails update with no old value' '
834 printf $F "update $a" "$m" >stdin &&
835 test_must_fail git update-ref -z --stdin <stdin 2>err &&
836 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
839 test_expect_success 'stdin -z fails update with too many arguments' '
840 printf $F "update $a" "$m" "$m" "$m" >stdin &&
841 test_must_fail git update-ref -z --stdin <stdin 2>err &&
842 grep "fatal: unknown command: $m" err
845 test_expect_success 'stdin -z fails delete with no ref' '
846 printf $F "delete " >stdin &&
847 test_must_fail git update-ref -z --stdin <stdin 2>err &&
848 grep "fatal: delete: missing <ref>" err
851 test_expect_success 'stdin -z fails delete with no old value' '
852 printf $F "delete $a" >stdin &&
853 test_must_fail git update-ref -z --stdin <stdin 2>err &&
854 grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
857 test_expect_success 'stdin -z fails delete with too many arguments' '
858 printf $F "delete $a" "$m" "$m" >stdin &&
859 test_must_fail git update-ref -z --stdin <stdin 2>err &&
860 grep "fatal: unknown command: $m" err
863 test_expect_success 'stdin -z fails verify with too many arguments' '
864 printf $F "verify $a" "$m" "$m" >stdin &&
865 test_must_fail git update-ref -z --stdin <stdin 2>err &&
866 grep "fatal: unknown command: $m" err
869 test_expect_success 'stdin -z fails verify with no old value' '
870 printf $F "verify $a" >stdin &&
871 test_must_fail git update-ref -z --stdin <stdin 2>err &&
872 grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err
875 test_expect_success 'stdin -z fails option with unknown name' '
876 printf $F "option unknown" >stdin &&
877 test_must_fail git update-ref -z --stdin <stdin 2>err &&
878 grep "fatal: option unknown: unknown" err
881 test_expect_success 'stdin -z fails with duplicate refs' '
882 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
883 test_must_fail git update-ref -z --stdin <stdin 2>err &&
884 grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
887 test_expect_success 'stdin -z create ref works' '
888 printf $F "create $a" "$m" >stdin &&
889 git update-ref -z --stdin <stdin &&
890 git rev-parse $m >expect &&
891 git rev-parse $a >actual &&
892 test_cmp expect actual
895 test_expect_success 'stdin -z update ref creates with zero old value' '
896 printf $F "update $b" "$m" "$Z" >stdin &&
897 git update-ref -z --stdin <stdin &&
898 git rev-parse $m >expect &&
899 git rev-parse $b >actual &&
900 test_cmp expect actual &&
904 test_expect_success 'stdin -z update ref creates with empty old value' '
905 printf $F "update $b" "$m" "" >stdin &&
906 git update-ref -z --stdin <stdin &&
907 git rev-parse $m >expect &&
908 git rev-parse $b >actual &&
909 test_cmp expect actual
912 test_expect_success 'stdin -z create ref works with path with space to blob' '
913 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
914 git update-ref -z --stdin <stdin &&
915 git rev-parse "$m:$pws" >expect &&
916 git rev-parse refs/blobs/pws >actual &&
917 test_cmp expect actual &&
918 git update-ref -d refs/blobs/pws
921 test_expect_success 'stdin -z update ref fails with wrong old value' '
922 printf $F "update $c" "$m" "$m~1" >stdin &&
923 test_must_fail git update-ref -z --stdin <stdin 2>err &&
924 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
925 test_must_fail git rev-parse --verify -q $c
928 test_expect_success 'stdin -z update ref fails with bad old value' '
929 printf $F "update $c" "$m" "does-not-exist" >stdin &&
930 test_must_fail git update-ref -z --stdin <stdin 2>err &&
931 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
932 test_must_fail git rev-parse --verify -q $c
935 test_expect_success 'stdin -z create ref fails when ref exists' '
936 git update-ref $c $m &&
937 git rev-parse "$c" >expect &&
938 printf $F "create $c" "$m~1" >stdin &&
939 test_must_fail git update-ref -z --stdin <stdin 2>err &&
940 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
941 git rev-parse "$c" >actual &&
942 test_cmp expect actual
945 test_expect_success 'stdin -z create ref fails with bad new value' '
946 git update-ref -d "$c" &&
947 printf $F "create $c" "does-not-exist" >stdin &&
948 test_must_fail git update-ref -z --stdin <stdin 2>err &&
949 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
950 test_must_fail git rev-parse --verify -q $c
953 test_expect_success 'stdin -z create ref fails with empty new value' '
954 printf $F "create $c" "" >stdin &&
955 test_must_fail git update-ref -z --stdin <stdin 2>err &&
956 grep "fatal: create $c: missing <newvalue>" err &&
957 test_must_fail git rev-parse --verify -q $c
960 test_expect_success 'stdin -z update ref works with right old value' '
961 printf $F "update $b" "$m~1" "$m" >stdin &&
962 git update-ref -z --stdin <stdin &&
963 git rev-parse $m~1 >expect &&
964 git rev-parse $b >actual &&
965 test_cmp expect actual
968 test_expect_success 'stdin -z delete ref fails with wrong old value' '
969 printf $F "delete $a" "$m~1" >stdin &&
970 test_must_fail git update-ref -z --stdin <stdin 2>err &&
971 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
972 git rev-parse $m >expect &&
973 git rev-parse $a >actual &&
974 test_cmp expect actual
977 test_expect_success 'stdin -z delete ref fails with zero old value' '
978 printf $F "delete $a" "$Z" >stdin &&
979 test_must_fail git update-ref -z --stdin <stdin 2>err &&
980 grep "fatal: delete $a: zero <oldvalue>" err &&
981 git rev-parse $m >expect &&
982 git rev-parse $a >actual &&
983 test_cmp expect actual
986 test_expect_success 'stdin -z update symref works option no-deref' '
987 git symbolic-ref TESTSYMREF $b &&
988 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
989 git update-ref -z --stdin <stdin &&
990 git rev-parse TESTSYMREF >expect &&
991 git rev-parse $a >actual &&
992 test_cmp expect actual &&
993 git rev-parse $m~1 >expect &&
994 git rev-parse $b >actual &&
995 test_cmp expect actual
998 test_expect_success 'stdin -z delete symref works option no-deref' '
999 git symbolic-ref TESTSYMREF $b &&
1000 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
1001 git update-ref -z --stdin <stdin &&
1002 test_must_fail git rev-parse --verify -q TESTSYMREF &&
1003 git rev-parse $m~1 >expect &&
1004 git rev-parse $b >actual &&
1005 test_cmp expect actual
1008 test_expect_success 'stdin -z delete ref works with right old value' '
1009 printf $F "delete $b" "$m~1" >stdin &&
1010 git update-ref -z --stdin <stdin &&
1011 test_must_fail git rev-parse --verify -q $b
1014 test_expect_success 'stdin -z update/create/verify combination works' '
1015 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
1016 git update-ref -z --stdin <stdin &&
1017 git rev-parse $m >expect &&
1018 git rev-parse $a >actual &&
1019 test_cmp expect actual &&
1020 git rev-parse $b >actual &&
1021 test_cmp expect actual &&
1022 test_must_fail git rev-parse --verify -q $c
1025 test_expect_success 'stdin -z verify succeeds for correct value' '
1026 git rev-parse $m >expect &&
1027 printf $F "verify $m" "$m" >stdin &&
1028 git update-ref -z --stdin <stdin &&
1029 git rev-parse $m >actual &&
1030 test_cmp expect actual
1033 test_expect_success 'stdin -z verify succeeds for missing reference' '
1034 printf $F "verify refs/heads/missing" "$Z" >stdin &&
1035 git update-ref -z --stdin <stdin &&
1036 test_must_fail git rev-parse --verify -q refs/heads/missing
1039 test_expect_success 'stdin -z verify treats no value as missing' '
1040 printf $F "verify refs/heads/missing" "" >stdin &&
1041 git update-ref -z --stdin <stdin &&
1042 test_must_fail git rev-parse --verify -q refs/heads/missing
1045 test_expect_success 'stdin -z verify fails for wrong value' '
1046 git rev-parse $m >expect &&
1047 printf $F "verify $m" "$m~1" >stdin &&
1048 test_must_fail git update-ref -z --stdin <stdin &&
1049 git rev-parse $m >actual &&
1050 test_cmp expect actual
1053 test_expect_success 'stdin -z verify fails for mistaken null value' '
1054 git rev-parse $m >expect &&
1055 printf $F "verify $m" "$Z" >stdin &&
1056 test_must_fail git update-ref -z --stdin <stdin &&
1057 git rev-parse $m >actual &&
1058 test_cmp expect actual
1061 test_expect_success 'stdin -z verify fails for mistaken empty value' '
1062 M=$(git rev-parse $m) &&
1063 test_when_finished "git update-ref $m $M" &&
1064 git rev-parse $m >expect &&
1065 printf $F "verify $m" "" >stdin &&
1066 test_must_fail git update-ref -z --stdin <stdin &&
1067 git rev-parse $m >actual &&
1068 test_cmp expect actual
1071 test_expect_success 'stdin -z update refs works with identity updates' '
1072 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
1073 git update-ref -z --stdin <stdin &&
1074 git rev-parse $m >expect &&
1075 git rev-parse $a >actual &&
1076 test_cmp expect actual &&
1077 git rev-parse $b >actual &&
1078 test_cmp expect actual &&
1079 test_must_fail git rev-parse --verify -q $c
1082 test_expect_success 'stdin -z update refs fails with wrong old value' '
1083 git update-ref $c $m &&
1084 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
1085 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1086 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1087 git rev-parse $m >expect &&
1088 git rev-parse $a >actual &&
1089 test_cmp expect actual &&
1090 git rev-parse $b >actual &&
1091 test_cmp expect actual &&
1092 git rev-parse $c >actual &&
1093 test_cmp expect actual
1096 test_expect_success 'stdin -z delete refs works with packed and loose refs' '
1097 git pack-refs --all &&
1098 git update-ref $c $m~1 &&
1099 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
1100 git update-ref -z --stdin <stdin &&
1101 test_must_fail git rev-parse --verify -q $a &&
1102 test_must_fail git rev-parse --verify -q $b &&
1103 test_must_fail git rev-parse --verify -q $c
1106 run_with_limited_open_files () {
1107 (ulimit -n 32 && "$@")
1110 test_lazy_prereq ULIMIT_FILE_DESCRIPTORS 'run_with_limited_open_files true'
1112 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' '
1114 for i in $(test_seq 33)
1116 echo "create refs/heads/$i HEAD"
1117 done >large_input &&
1118 run_with_limited_open_files git update-ref --stdin <large_input &&
1119 git rev-parse --verify -q refs/heads/33
1123 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches does not burst open file limit' '
1125 for i in $(test_seq 33)
1127 echo "delete refs/heads/$i HEAD"
1128 done >large_input &&
1129 run_with_limited_open_files git update-ref --stdin <large_input &&
1130 test_must_fail git rev-parse --verify -q refs/heads/33