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) &&
29 "git update-ref $m $A &&
30 test $A"' = $(cat .git/'"$m"')'
33 "git update-ref $m $B $A &&
34 test $B"' = $(cat .git/'"$m"')'
35 test_expect_success
"fail to delete $m with stale ref" '
36 test_must_fail git update-ref -d $m $A &&
37 test $B = "$(cat .git/$m)"
39 test_expect_success
"delete $m" '
40 git update-ref -d $m $B &&
45 test_expect_success
"delete $m without oldvalue verification" "
46 git update-ref $m $A &&
47 test $A = \$(cat .git/$m) &&
48 git update-ref -d $m &&
56 test_must_fail git update-ref $n $A >out 2>err"
57 rm -f .git
/$n_dir out err
60 "create $m (by HEAD)" \
61 "git update-ref HEAD $A &&
62 test $A"' = $(cat .git/'"$m"')'
64 "create $m (by HEAD)" \
65 "git update-ref HEAD $B $A &&
66 test $B"' = $(cat .git/'"$m"')'
67 test_expect_success
"fail to delete $m (by HEAD) with stale ref" '
68 test_must_fail git update-ref -d HEAD $A &&
69 test $B = $(cat .git/$m)
71 test_expect_success
"delete $m (by HEAD)" '
72 git update-ref -d HEAD $B &&
78 "create $m (by HEAD)" \
79 "git update-ref HEAD $A &&
80 test $A"' = $(cat .git/'"$m"')'
86 "git update-ref HEAD $B $A &&
87 test $B"' = $(cat .git/'"$m"')'
88 test_expect_success
"delete $m (by HEAD) should remove both packed and loose $m" '
89 git update-ref -d HEAD $B &&
90 ! grep "$m" .git/packed-refs &&
95 cp -f .git
/HEAD .git
/HEAD.orig
96 test_expect_success
"delete symref without dereference" '
97 git update-ref --no-deref -d HEAD &&
100 cp -f .git
/HEAD.orig .git
/HEAD
102 test_expect_success
"delete symref without dereference when the referred ref is packed" '
106 git pack-refs --all &&
107 git update-ref --no-deref -d HEAD &&
110 cp -f .git
/HEAD.orig .git
/HEAD
113 test_expect_success
'update-ref -d is not confused by self-reference' '
114 git symbolic-ref refs/heads/self refs/heads/self &&
115 test_when_finished "rm -f .git/refs/heads/self" &&
116 test_path_is_file .git/refs/heads/self &&
117 test_must_fail git update-ref -d refs/heads/self &&
118 test_path_is_file .git/refs/heads/self
121 test_expect_success
'update-ref --no-deref -d can delete self-reference' '
122 git symbolic-ref refs/heads/self refs/heads/self &&
123 test_when_finished "rm -f .git/refs/heads/self" &&
124 test_path_is_file .git/refs/heads/self &&
125 git update-ref --no-deref -d refs/heads/self &&
126 test_path_is_missing .git/refs/heads/self
129 test_expect_success
'update-ref --no-deref -d can delete reference to bad ref' '
130 >.git/refs/heads/bad &&
131 test_when_finished "rm -f .git/refs/heads/bad" &&
132 git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
133 test_when_finished "rm -f .git/refs/heads/ref-to-bad" &&
134 test_path_is_file .git/refs/heads/ref-to-bad &&
135 git update-ref --no-deref -d refs/heads/ref-to-bad &&
136 test_path_is_missing .git/refs/heads/ref-to-bad
139 test_expect_success
'(not) create HEAD with old sha1' "
140 test_must_fail git update-ref HEAD $A $B
142 test_expect_success
"(not) prior created .git/$m" "
147 test_expect_success \
149 "git update-ref HEAD $A"
150 test_expect_success
'(not) change HEAD with wrong SHA1' "
151 test_must_fail git update-ref HEAD $B $Z
153 test_expect_success
"(not) changed .git/$m" "
154 ! test $B"' = $(cat .git/'"$m"')
158 : a repository with working tree always has reflog these days...
159 : >.git
/logs
/refs
/heads
/master
160 test_expect_success \
161 "create $m (logged by touch)" \
162 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
163 git update-ref HEAD '"$A"' -m "Initial Creation" &&
164 test '"$A"' = $(cat .git/'"$m"')'
165 test_expect_success \
166 "update $m (logged by touch)" \
167 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
168 git update-ref HEAD'" $B $A "'-m "Switch" &&
169 test '"$B"' = $(cat .git/'"$m"')'
170 test_expect_success \
171 "set $m (logged by touch)" \
172 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
173 git update-ref HEAD'" $A &&
174 test $A"' = $(cat .git/'"$m"')'
177 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
178 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
179 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
181 test_expect_success \
182 "verifying $m's log" \
183 "test_cmp expect .git/logs/$m"
184 rm -rf .git
/$m .git
/logs expect
186 test_expect_success \
187 'enable core.logAllRefUpdates' \
188 'git config core.logAllRefUpdates true &&
189 test true = $(git config --bool --get core.logAllRefUpdates)'
191 test_expect_success \
192 "create $m (logged by config)" \
193 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
194 git update-ref HEAD'" $A "'-m "Initial Creation" &&
195 test '"$A"' = $(cat .git/'"$m"')'
196 test_expect_success \
197 "update $m (logged by config)" \
198 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
199 git update-ref HEAD'" $B $A "'-m "Switch" &&
200 test '"$B"' = $(cat .git/'"$m"')'
201 test_expect_success \
202 "set $m (logged by config)" \
203 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
204 git update-ref HEAD '"$A &&
205 test $A"' = $(cat .git/'"$m"')'
208 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
209 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
210 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
212 test_expect_success \
213 "verifying $m's log" \
214 'test_cmp expect .git/logs/$m'
215 rm -f .git
/$m .git
/logs
/$m expect
218 cat >.git
/logs
/$m <<EOF
219 0000000000000000000000000000000000000000 $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
220 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
221 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
222 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
223 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
226 ed
="Thu, 26 May 2005 18:32:00 -0500"
227 gd
="Thu, 26 May 2005 18:33:00 -0500"
228 ld
="Thu, 26 May 2005 18:43:00 -0500"
229 test_expect_success \
230 'Query "master@{May 25 2005}" (before history)' \
232 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
233 test '"$C"' = $(cat o) &&
234 test "warning: Log for '\'master
\'' only goes back to $ed." = "$(cat e)"'
235 test_expect_success \
236 "Query master@{2005-05-25} (before history)" \
238 git rev-parse --verify master@{2005-05-25} >o 2>e &&
239 test '"$C"' = $(cat o) &&
240 echo test "warning: Log for '\'master
\'' only goes back to $ed." = "$(cat e)"'
241 test_expect_success \
242 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
244 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
245 test '"$C"' = $(cat o) &&
246 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
247 test_expect_success \
248 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
250 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
251 test '"$C"' = $(cat o) &&
252 test "" = "$(cat e)"'
253 test_expect_success \
254 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \
256 git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e &&
257 test '"$A"' = $(cat o) &&
258 test "" = "$(cat e)"'
259 test_expect_success \
260 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
262 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
263 test '"$B"' = $(cat o) &&
264 test "warning: Log for ref '"$m has gap after $gd"'." = "$(cat e)"'
265 test_expect_success \
266 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
268 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
269 test '"$Z"' = $(cat o) &&
270 test "" = "$(cat e)"'
271 test_expect_success \
272 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
274 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
275 test '"$E"' = $(cat o) &&
276 test "" = "$(cat e)"'
277 test_expect_success \
278 'Query "master@{2005-05-28}" (past end of history)' \
280 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
281 test '"$D"' = $(cat o) &&
282 test "warning: Log for ref '"$m unexpectedly ended on $ld"'." = "$(cat e)"'
285 rm -f .git
/$m .git
/logs
/$m expect
287 test_expect_success \
288 'creating initial files' \
291 GIT_AUTHOR_DATE="2005-05-26 23:30" \
292 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
293 h_TEST=$(git rev-parse --verify HEAD) &&
294 echo The other day this did not work. >M &&
295 echo And then Bob told me how to fix it. >>M &&
297 GIT_AUTHOR_DATE="2005-05-26 23:41" \
298 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
299 h_OTHER=$(git rev-parse --verify HEAD) &&
300 GIT_AUTHOR_DATE="2005-05-26 23:44" \
301 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
302 h_FIXED=$(git rev-parse --verify HEAD) &&
303 echo Merged initial commit and a later commit. >M &&
304 echo $h_TEST >.git/MERGE_HEAD &&
305 GIT_AUTHOR_DATE="2005-05-26 23:45" \
306 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
307 h_MERGED=$(git rev-parse --verify HEAD) &&
311 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
312 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
313 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
314 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
316 test_expect_success \
317 'git commit logged updates' \
318 "test_cmp expect .git/logs/$m"
319 unset h_TEST h_OTHER h_FIXED h_MERGED
321 test_expect_success \
322 'git cat-file blob master:F (expect OTHER)' \
323 'test OTHER = $(git cat-file blob master:F)'
324 test_expect_success \
325 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
326 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")'
327 test_expect_success \
328 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
329 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'
336 pws
='path with space'
338 test_expect_success
'stdin test setup' '
339 echo "$pws" >"$pws" &&
344 test_expect_success
'-z fails without --stdin' '
345 test_must_fail git update-ref -z $m $m $m 2>err &&
346 grep "usage: git update-ref" err
349 test_expect_success
'stdin works with no input' '
351 git update-ref --stdin <stdin &&
352 git rev-parse --verify -q $m
355 test_expect_success
'stdin fails on empty line' '
357 test_must_fail git update-ref --stdin <stdin 2>err &&
358 grep "fatal: empty command in input" err
361 test_expect_success
'stdin fails on only whitespace' '
363 test_must_fail git update-ref --stdin <stdin 2>err &&
364 grep "fatal: whitespace before command: " err
367 test_expect_success
'stdin fails on leading whitespace' '
368 echo " create $a $m" >stdin &&
369 test_must_fail git update-ref --stdin <stdin 2>err &&
370 grep "fatal: whitespace before command: create $a $m" err
373 test_expect_success
'stdin fails on unknown command' '
374 echo "unknown $a" >stdin &&
375 test_must_fail git update-ref --stdin <stdin 2>err &&
376 grep "fatal: unknown command: unknown $a" err
379 test_expect_success
'stdin fails on unbalanced quotes' '
380 echo "create $a \"master" >stdin &&
381 test_must_fail git update-ref --stdin <stdin 2>err &&
382 grep "fatal: badly quoted argument: \\\"master" err
385 test_expect_success
'stdin fails on invalid escape' '
386 echo "create $a \"ma\zter\"" >stdin &&
387 test_must_fail git update-ref --stdin <stdin 2>err &&
388 grep "fatal: badly quoted argument: \\\"ma\\\\zter\\\"" err
391 test_expect_success
'stdin fails on junk after quoted argument' '
392 echo "create \"$a\"master" >stdin &&
393 test_must_fail git update-ref --stdin <stdin 2>err &&
394 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"master" err
397 test_expect_success
'stdin fails create with no ref' '
398 echo "create " >stdin &&
399 test_must_fail git update-ref --stdin <stdin 2>err &&
400 grep "fatal: create: missing <ref>" err
403 test_expect_success
'stdin fails create with no new value' '
404 echo "create $a" >stdin &&
405 test_must_fail git update-ref --stdin <stdin 2>err &&
406 grep "fatal: create $a: missing <newvalue>" err
409 test_expect_success
'stdin fails create with too many arguments' '
410 echo "create $a $m $m" >stdin &&
411 test_must_fail git update-ref --stdin <stdin 2>err &&
412 grep "fatal: create $a: extra input: $m" err
415 test_expect_success
'stdin fails update with no ref' '
416 echo "update " >stdin &&
417 test_must_fail git update-ref --stdin <stdin 2>err &&
418 grep "fatal: update: missing <ref>" err
421 test_expect_success
'stdin fails update with no new value' '
422 echo "update $a" >stdin &&
423 test_must_fail git update-ref --stdin <stdin 2>err &&
424 grep "fatal: update $a: missing <newvalue>" err
427 test_expect_success
'stdin fails update with too many arguments' '
428 echo "update $a $m $m $m" >stdin &&
429 test_must_fail git update-ref --stdin <stdin 2>err &&
430 grep "fatal: update $a: extra input: $m" err
433 test_expect_success
'stdin fails delete with no ref' '
434 echo "delete " >stdin &&
435 test_must_fail git update-ref --stdin <stdin 2>err &&
436 grep "fatal: delete: missing <ref>" err
439 test_expect_success
'stdin fails delete with too many arguments' '
440 echo "delete $a $m $m" >stdin &&
441 test_must_fail git update-ref --stdin <stdin 2>err &&
442 grep "fatal: delete $a: extra input: $m" err
445 test_expect_success
'stdin fails verify with too many arguments' '
446 echo "verify $a $m $m" >stdin &&
447 test_must_fail git update-ref --stdin <stdin 2>err &&
448 grep "fatal: verify $a: extra input: $m" err
451 test_expect_success
'stdin fails option with unknown name' '
452 echo "option unknown" >stdin &&
453 test_must_fail git update-ref --stdin <stdin 2>err &&
454 grep "fatal: option unknown: unknown" err
457 test_expect_success
'stdin fails with duplicate refs' '
463 test_must_fail git update-ref --stdin <stdin 2>err &&
464 grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
467 test_expect_success
'stdin create ref works' '
468 echo "create $a $m" >stdin &&
469 git update-ref --stdin <stdin &&
470 git rev-parse $m >expect &&
471 git rev-parse $a >actual &&
472 test_cmp expect actual
475 test_expect_success
'stdin succeeds with quoted argument' '
476 git update-ref -d $a &&
477 echo "create $a \"$m\"" >stdin &&
478 git update-ref --stdin <stdin &&
479 git rev-parse $m >expect &&
480 git rev-parse $a >actual &&
481 test_cmp expect actual
484 test_expect_success
'stdin succeeds with escaped character' '
485 git update-ref -d $a &&
486 echo "create $a \"ma\\163ter\"" >stdin &&
487 git update-ref --stdin <stdin &&
488 git rev-parse $m >expect &&
489 git rev-parse $a >actual &&
490 test_cmp expect actual
493 test_expect_success
'stdin update ref creates with zero old value' '
494 echo "update $b $m $Z" >stdin &&
495 git update-ref --stdin <stdin &&
496 git rev-parse $m >expect &&
497 git rev-parse $b >actual &&
498 test_cmp expect actual &&
502 test_expect_success
'stdin update ref creates with empty old value' '
503 echo "update $b $m $E" >stdin &&
504 git update-ref --stdin <stdin &&
505 git rev-parse $m >expect &&
506 git rev-parse $b >actual &&
507 test_cmp expect actual
510 test_expect_success
'stdin create ref works with path with space to blob' '
511 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
512 git update-ref --stdin <stdin &&
513 git rev-parse "$m:$pws" >expect &&
514 git rev-parse refs/blobs/pws >actual &&
515 test_cmp expect actual &&
516 git update-ref -d refs/blobs/pws
519 test_expect_success
'stdin update ref fails with wrong old value' '
520 echo "update $c $m $m~1" >stdin &&
521 test_must_fail git update-ref --stdin <stdin 2>err &&
522 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
523 test_must_fail git rev-parse --verify -q $c
526 test_expect_success
'stdin update ref fails with bad old value' '
527 echo "update $c $m does-not-exist" >stdin &&
528 test_must_fail git update-ref --stdin <stdin 2>err &&
529 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
530 test_must_fail git rev-parse --verify -q $c
533 test_expect_success
'stdin create ref fails with bad new value' '
534 echo "create $c does-not-exist" >stdin &&
535 test_must_fail git update-ref --stdin <stdin 2>err &&
536 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
537 test_must_fail git rev-parse --verify -q $c
540 test_expect_success
'stdin create ref fails with zero new value' '
541 echo "create $c " >stdin &&
542 test_must_fail git update-ref --stdin <stdin 2>err &&
543 grep "fatal: create $c: zero <newvalue>" err &&
544 test_must_fail git rev-parse --verify -q $c
547 test_expect_success
'stdin update ref works with right old value' '
548 echo "update $b $m~1 $m" >stdin &&
549 git update-ref --stdin <stdin &&
550 git rev-parse $m~1 >expect &&
551 git rev-parse $b >actual &&
552 test_cmp expect actual
555 test_expect_success
'stdin delete ref fails with wrong old value' '
556 echo "delete $a $m~1" >stdin &&
557 test_must_fail git update-ref --stdin <stdin 2>err &&
558 grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
559 git rev-parse $m >expect &&
560 git rev-parse $a >actual &&
561 test_cmp expect actual
564 test_expect_success
'stdin delete ref fails with zero old value' '
565 echo "delete $a " >stdin &&
566 test_must_fail git update-ref --stdin <stdin 2>err &&
567 grep "fatal: delete $a: zero <oldvalue>" err &&
568 git rev-parse $m >expect &&
569 git rev-parse $a >actual &&
570 test_cmp expect actual
573 test_expect_success
'stdin update symref works option no-deref' '
574 git symbolic-ref TESTSYMREF $b &&
577 update TESTSYMREF $a $b
579 git update-ref --stdin <stdin &&
580 git rev-parse TESTSYMREF >expect &&
581 git rev-parse $a >actual &&
582 test_cmp expect actual &&
583 git rev-parse $m~1 >expect &&
584 git rev-parse $b >actual &&
585 test_cmp expect actual
588 test_expect_success
'stdin delete symref works option no-deref' '
589 git symbolic-ref TESTSYMREF $b &&
594 git update-ref --stdin <stdin &&
595 test_must_fail git rev-parse --verify -q TESTSYMREF &&
596 git rev-parse $m~1 >expect &&
597 git rev-parse $b >actual &&
598 test_cmp expect actual
601 test_expect_success
'stdin delete ref works with right old value' '
602 echo "delete $b $m~1" >stdin &&
603 git update-ref --stdin <stdin &&
604 test_must_fail git rev-parse --verify -q $b
607 test_expect_success
'stdin update/create/verify combination works' '
613 git update-ref --stdin <stdin &&
614 git rev-parse $m >expect &&
615 git rev-parse $a >actual &&
616 test_cmp expect actual &&
617 git rev-parse $b >actual &&
618 test_cmp expect actual &&
619 test_must_fail git rev-parse --verify -q $c
622 test_expect_success
'stdin update refs works with identity updates' '
628 git update-ref --stdin <stdin &&
629 git rev-parse $m >expect &&
630 git rev-parse $a >actual &&
631 test_cmp expect actual &&
632 git rev-parse $b >actual &&
633 test_cmp expect actual &&
634 test_must_fail git rev-parse --verify -q $c
637 test_expect_success
'stdin update refs fails with wrong old value' '
638 git update-ref $c $m &&
644 test_must_fail git update-ref --stdin <stdin 2>err &&
645 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
646 git rev-parse $m >expect &&
647 git rev-parse $a >actual &&
648 test_cmp expect actual &&
649 git rev-parse $b >actual &&
650 test_cmp expect actual &&
651 git rev-parse $c >actual &&
652 test_cmp expect actual
655 test_expect_success
'stdin delete refs works with packed and loose refs' '
656 git pack-refs --all &&
657 git update-ref $c $m~1 &&
663 git update-ref --stdin <stdin &&
664 test_must_fail git rev-parse --verify -q $a &&
665 test_must_fail git rev-parse --verify -q $b &&
666 test_must_fail git rev-parse --verify -q $c
669 test_expect_success
'stdin -z works on empty input' '
671 git update-ref -z --stdin <stdin &&
672 git rev-parse --verify -q $m
675 test_expect_success
'stdin -z fails on empty line' '
677 test_must_fail git update-ref -z --stdin <stdin 2>err &&
678 grep "fatal: whitespace before command: " err
681 test_expect_success
'stdin -z fails on empty command' '
682 printf $F "" >stdin &&
683 test_must_fail git update-ref -z --stdin <stdin 2>err &&
684 grep "fatal: empty command in input" err
687 test_expect_success
'stdin -z fails on only whitespace' '
688 printf $F " " >stdin &&
689 test_must_fail git update-ref -z --stdin <stdin 2>err &&
690 grep "fatal: whitespace before command: " err
693 test_expect_success
'stdin -z fails on leading whitespace' '
694 printf $F " create $a" "$m" >stdin &&
695 test_must_fail git update-ref -z --stdin <stdin 2>err &&
696 grep "fatal: whitespace before command: create $a" err
699 test_expect_success
'stdin -z fails on unknown command' '
700 printf $F "unknown $a" >stdin &&
701 test_must_fail git update-ref -z --stdin <stdin 2>err &&
702 grep "fatal: unknown command: unknown $a" err
705 test_expect_success
'stdin -z fails create with no ref' '
706 printf $F "create " >stdin &&
707 test_must_fail git update-ref -z --stdin <stdin 2>err &&
708 grep "fatal: create: missing <ref>" err
711 test_expect_success
'stdin -z fails create with no new value' '
712 printf $F "create $a" >stdin &&
713 test_must_fail git update-ref -z --stdin <stdin 2>err &&
714 grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
717 test_expect_success
'stdin -z fails create with too many arguments' '
718 printf $F "create $a" "$m" "$m" >stdin &&
719 test_must_fail git update-ref -z --stdin <stdin 2>err &&
720 grep "fatal: unknown command: $m" err
723 test_expect_success
'stdin -z fails update with no ref' '
724 printf $F "update " >stdin &&
725 test_must_fail git update-ref -z --stdin <stdin 2>err &&
726 grep "fatal: update: missing <ref>" err
729 test_expect_success
'stdin -z fails update with too few args' '
730 printf $F "update $a" "$m" >stdin &&
731 test_must_fail git update-ref -z --stdin <stdin 2>err &&
732 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
735 test_expect_success
'stdin -z emits warning with empty new value' '
736 git update-ref $a $m &&
737 printf $F "update $a" "" "" >stdin &&
738 git update-ref -z --stdin <stdin 2>err &&
739 grep "warning: update $a: missing <newvalue>, treating as zero" err &&
740 test_must_fail git rev-parse --verify -q $a
743 test_expect_success
'stdin -z fails update with no new value' '
744 printf $F "update $a" >stdin &&
745 test_must_fail git update-ref -z --stdin <stdin 2>err &&
746 grep "fatal: update $a: unexpected end of input when reading <newvalue>" err
749 test_expect_success
'stdin -z fails update with no old value' '
750 printf $F "update $a" "$m" >stdin &&
751 test_must_fail git update-ref -z --stdin <stdin 2>err &&
752 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
755 test_expect_success
'stdin -z fails update with too many arguments' '
756 printf $F "update $a" "$m" "$m" "$m" >stdin &&
757 test_must_fail git update-ref -z --stdin <stdin 2>err &&
758 grep "fatal: unknown command: $m" err
761 test_expect_success
'stdin -z fails delete with no ref' '
762 printf $F "delete " >stdin &&
763 test_must_fail git update-ref -z --stdin <stdin 2>err &&
764 grep "fatal: delete: missing <ref>" err
767 test_expect_success
'stdin -z fails delete with no old value' '
768 printf $F "delete $a" >stdin &&
769 test_must_fail git update-ref -z --stdin <stdin 2>err &&
770 grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
773 test_expect_success
'stdin -z fails delete with too many arguments' '
774 printf $F "delete $a" "$m" "$m" >stdin &&
775 test_must_fail git update-ref -z --stdin <stdin 2>err &&
776 grep "fatal: unknown command: $m" err
779 test_expect_success
'stdin -z fails verify with too many arguments' '
780 printf $F "verify $a" "$m" "$m" >stdin &&
781 test_must_fail git update-ref -z --stdin <stdin 2>err &&
782 grep "fatal: unknown command: $m" err
785 test_expect_success
'stdin -z fails verify with no old value' '
786 printf $F "verify $a" >stdin &&
787 test_must_fail git update-ref -z --stdin <stdin 2>err &&
788 grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err
791 test_expect_success
'stdin -z fails option with unknown name' '
792 printf $F "option unknown" >stdin &&
793 test_must_fail git update-ref -z --stdin <stdin 2>err &&
794 grep "fatal: option unknown: unknown" err
797 test_expect_success
'stdin -z fails with duplicate refs' '
798 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
799 test_must_fail git update-ref -z --stdin <stdin 2>err &&
800 grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
803 test_expect_success
'stdin -z create ref works' '
804 printf $F "create $a" "$m" >stdin &&
805 git update-ref -z --stdin <stdin &&
806 git rev-parse $m >expect &&
807 git rev-parse $a >actual &&
808 test_cmp expect actual
811 test_expect_success
'stdin -z update ref creates with zero old value' '
812 printf $F "update $b" "$m" "$Z" >stdin &&
813 git update-ref -z --stdin <stdin &&
814 git rev-parse $m >expect &&
815 git rev-parse $b >actual &&
816 test_cmp expect actual &&
820 test_expect_success
'stdin -z update ref creates with empty old value' '
821 printf $F "update $b" "$m" "" >stdin &&
822 git update-ref -z --stdin <stdin &&
823 git rev-parse $m >expect &&
824 git rev-parse $b >actual &&
825 test_cmp expect actual
828 test_expect_success
'stdin -z create ref works with path with space to blob' '
829 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
830 git update-ref -z --stdin <stdin &&
831 git rev-parse "$m:$pws" >expect &&
832 git rev-parse refs/blobs/pws >actual &&
833 test_cmp expect actual &&
834 git update-ref -d refs/blobs/pws
837 test_expect_success
'stdin -z update ref fails with wrong old value' '
838 printf $F "update $c" "$m" "$m~1" >stdin &&
839 test_must_fail git update-ref -z --stdin <stdin 2>err &&
840 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
841 test_must_fail git rev-parse --verify -q $c
844 test_expect_success
'stdin -z update ref fails with bad old value' '
845 printf $F "update $c" "$m" "does-not-exist" >stdin &&
846 test_must_fail git update-ref -z --stdin <stdin 2>err &&
847 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
848 test_must_fail git rev-parse --verify -q $c
851 test_expect_success
'stdin -z create ref fails when ref exists' '
852 git update-ref $c $m &&
853 git rev-parse "$c" >expect &&
854 printf $F "create $c" "$m~1" >stdin &&
855 test_must_fail git update-ref -z --stdin <stdin 2>err &&
856 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
857 git rev-parse "$c" >actual &&
858 test_cmp expect actual
861 test_expect_success
'stdin -z create ref fails with bad new value' '
862 git update-ref -d "$c" &&
863 printf $F "create $c" "does-not-exist" >stdin &&
864 test_must_fail git update-ref -z --stdin <stdin 2>err &&
865 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
866 test_must_fail git rev-parse --verify -q $c
869 test_expect_success
'stdin -z create ref fails with empty new value' '
870 printf $F "create $c" "" >stdin &&
871 test_must_fail git update-ref -z --stdin <stdin 2>err &&
872 grep "fatal: create $c: missing <newvalue>" err &&
873 test_must_fail git rev-parse --verify -q $c
876 test_expect_success
'stdin -z update ref works with right old value' '
877 printf $F "update $b" "$m~1" "$m" >stdin &&
878 git update-ref -z --stdin <stdin &&
879 git rev-parse $m~1 >expect &&
880 git rev-parse $b >actual &&
881 test_cmp expect actual
884 test_expect_success
'stdin -z delete ref fails with wrong old value' '
885 printf $F "delete $a" "$m~1" >stdin &&
886 test_must_fail git update-ref -z --stdin <stdin 2>err &&
887 grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
888 git rev-parse $m >expect &&
889 git rev-parse $a >actual &&
890 test_cmp expect actual
893 test_expect_success
'stdin -z delete ref fails with zero old value' '
894 printf $F "delete $a" "$Z" >stdin &&
895 test_must_fail git update-ref -z --stdin <stdin 2>err &&
896 grep "fatal: delete $a: zero <oldvalue>" err &&
897 git rev-parse $m >expect &&
898 git rev-parse $a >actual &&
899 test_cmp expect actual
902 test_expect_success
'stdin -z update symref works option no-deref' '
903 git symbolic-ref TESTSYMREF $b &&
904 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
905 git update-ref -z --stdin <stdin &&
906 git rev-parse TESTSYMREF >expect &&
907 git rev-parse $a >actual &&
908 test_cmp expect actual &&
909 git rev-parse $m~1 >expect &&
910 git rev-parse $b >actual &&
911 test_cmp expect actual
914 test_expect_success
'stdin -z delete symref works option no-deref' '
915 git symbolic-ref TESTSYMREF $b &&
916 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
917 git update-ref -z --stdin <stdin &&
918 test_must_fail git rev-parse --verify -q TESTSYMREF &&
919 git rev-parse $m~1 >expect &&
920 git rev-parse $b >actual &&
921 test_cmp expect actual
924 test_expect_success
'stdin -z delete ref works with right old value' '
925 printf $F "delete $b" "$m~1" >stdin &&
926 git update-ref -z --stdin <stdin &&
927 test_must_fail git rev-parse --verify -q $b
930 test_expect_success
'stdin -z update/create/verify combination works' '
931 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
932 git update-ref -z --stdin <stdin &&
933 git rev-parse $m >expect &&
934 git rev-parse $a >actual &&
935 test_cmp expect actual &&
936 git rev-parse $b >actual &&
937 test_cmp expect actual &&
938 test_must_fail git rev-parse --verify -q $c
941 test_expect_success
'stdin -z update refs works with identity updates' '
942 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
943 git update-ref -z --stdin <stdin &&
944 git rev-parse $m >expect &&
945 git rev-parse $a >actual &&
946 test_cmp expect actual &&
947 git rev-parse $b >actual &&
948 test_cmp expect actual &&
949 test_must_fail git rev-parse --verify -q $c
952 test_expect_success
'stdin -z update refs fails with wrong old value' '
953 git update-ref $c $m &&
954 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
955 test_must_fail git update-ref -z --stdin <stdin 2>err &&
956 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
957 git rev-parse $m >expect &&
958 git rev-parse $a >actual &&
959 test_cmp expect actual &&
960 git rev-parse $b >actual &&
961 test_cmp expect actual &&
962 git rev-parse $c >actual &&
963 test_cmp expect actual
966 test_expect_success
'stdin -z delete refs works with packed and loose refs' '
967 git pack-refs --all &&
968 git update-ref $c $m~1 &&
969 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
970 git update-ref -z --stdin <stdin &&
971 test_must_fail git rev-parse --verify -q $a &&
972 test_must_fail git rev-parse --verify -q $b &&
973 test_must_fail git rev-parse --verify -q $c