t3600: slightly modernize style
[git.git] / t / t1400-update-ref.sh
blob6ffd82fe321cd3154d6f193c21198218e762f1b2
1 #!/bin/sh
3 # Copyright (c) 2006 Shawn Pearce
6 test_description='Test git update-ref and basic ref logging'
7 . ./test-lib.sh
9 Z=$_z40
11 test_expect_success setup '
13 for name in A B C D E F
15 test_tick &&
16 T=$(git write-tree) &&
17 sha1=$(echo $name | git commit-tree $T) &&
18 eval $name=$sha1
19 done
23 m=refs/heads/master
24 n_dir=refs/heads/gu
25 n=$n_dir/fixes
27 test_expect_success \
28 "create $m" \
29 "git update-ref $m $A &&
30 test $A"' = $(cat .git/'"$m"')'
31 test_expect_success \
32 "create $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 &&
41 ! test -f .git/$m
43 rm -f .git/$m
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 &&
49 ! test -f .git/$m
51 rm -f .git/$m
53 test_expect_success \
54 "fail to create $n" \
55 "touch .git/$n_dir &&
56 test_must_fail git update-ref $n $A >out 2>err"
57 rm -f .git/$n_dir out err
59 test_expect_success \
60 "create $m (by HEAD)" \
61 "git update-ref HEAD $A &&
62 test $A"' = $(cat .git/'"$m"')'
63 test_expect_success \
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 &&
73 ! test -f .git/$m
75 rm -f .git/$m
77 test_expect_success \
78 "create $m (by HEAD)" \
79 "git update-ref HEAD $A &&
80 test $A"' = $(cat .git/'"$m"')'
81 test_expect_success \
82 "pack refs" \
83 "git pack-refs --all"
84 test_expect_success \
85 "move $m (by HEAD)" \
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 &&
91 ! test -f .git/$m
93 rm -f .git/$m
95 cp -f .git/HEAD .git/HEAD.orig
96 test_expect_success "delete symref without dereference" '
97 git update-ref --no-deref -d HEAD &&
98 ! test -f .git/HEAD
100 cp -f .git/HEAD.orig .git/HEAD
102 test_expect_success "delete symref without dereference when the referred ref is packed" '
103 echo foo >foo.c &&
104 git add foo.c &&
105 git commit -m foo &&
106 git pack-refs --all &&
107 git update-ref --no-deref -d HEAD &&
108 ! test -f .git/HEAD
110 cp -f .git/HEAD.orig .git/HEAD
111 git update-ref -d $m
113 test_expect_success '(not) create HEAD with old sha1' "
114 test_must_fail git update-ref HEAD $A $B
116 test_expect_success "(not) prior created .git/$m" "
117 ! test -f .git/$m
119 rm -f .git/$m
121 test_expect_success \
122 "create HEAD" \
123 "git update-ref HEAD $A"
124 test_expect_success '(not) change HEAD with wrong SHA1' "
125 test_must_fail git update-ref HEAD $B $Z
127 test_expect_success "(not) changed .git/$m" "
128 ! test $B"' = $(cat .git/'"$m"')
130 rm -f .git/$m
132 : a repository with working tree always has reflog these days...
133 : >.git/logs/refs/heads/master
134 test_expect_success \
135 "create $m (logged by touch)" \
136 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
137 git update-ref HEAD '"$A"' -m "Initial Creation" &&
138 test '"$A"' = $(cat .git/'"$m"')'
139 test_expect_success \
140 "update $m (logged by touch)" \
141 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
142 git update-ref HEAD'" $B $A "'-m "Switch" &&
143 test '"$B"' = $(cat .git/'"$m"')'
144 test_expect_success \
145 "set $m (logged by touch)" \
146 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
147 git update-ref HEAD'" $A &&
148 test $A"' = $(cat .git/'"$m"')'
150 cat >expect <<EOF
151 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
152 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
153 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
155 test_expect_success \
156 "verifying $m's log" \
157 "test_cmp expect .git/logs/$m"
158 rm -rf .git/$m .git/logs expect
160 test_expect_success \
161 'enable core.logAllRefUpdates' \
162 'git config core.logAllRefUpdates true &&
163 test true = $(git config --bool --get core.logAllRefUpdates)'
165 test_expect_success \
166 "create $m (logged by config)" \
167 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
168 git update-ref HEAD'" $A "'-m "Initial Creation" &&
169 test '"$A"' = $(cat .git/'"$m"')'
170 test_expect_success \
171 "update $m (logged by config)" \
172 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
173 git update-ref HEAD'" $B $A "'-m "Switch" &&
174 test '"$B"' = $(cat .git/'"$m"')'
175 test_expect_success \
176 "set $m (logged by config)" \
177 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
178 git update-ref HEAD '"$A &&
179 test $A"' = $(cat .git/'"$m"')'
181 cat >expect <<EOF
182 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
183 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
184 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
186 test_expect_success \
187 "verifying $m's log" \
188 'test_cmp expect .git/logs/$m'
189 rm -f .git/$m .git/logs/$m expect
191 git update-ref $m $D
192 cat >.git/logs/$m <<EOF
193 0000000000000000000000000000000000000000 $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
194 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
195 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
196 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
197 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
200 ed="Thu, 26 May 2005 18:32:00 -0500"
201 gd="Thu, 26 May 2005 18:33:00 -0500"
202 ld="Thu, 26 May 2005 18:43:00 -0500"
203 test_expect_success \
204 'Query "master@{May 25 2005}" (before history)' \
205 'rm -f o e &&
206 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
207 test '"$C"' = $(cat o) &&
208 test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
209 test_expect_success \
210 "Query master@{2005-05-25} (before history)" \
211 'rm -f o e &&
212 git rev-parse --verify master@{2005-05-25} >o 2>e &&
213 test '"$C"' = $(cat o) &&
214 echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
215 test_expect_success \
216 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
217 'rm -f o e &&
218 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
219 test '"$C"' = $(cat o) &&
220 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
221 test_expect_success \
222 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
223 'rm -f o e &&
224 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
225 test '"$C"' = $(cat o) &&
226 test "" = "$(cat e)"'
227 test_expect_success \
228 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \
229 'rm -f o e &&
230 git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e &&
231 test '"$A"' = $(cat o) &&
232 test "" = "$(cat e)"'
233 test_expect_success \
234 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
235 'rm -f o e &&
236 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
237 test '"$B"' = $(cat o) &&
238 test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"'
239 test_expect_success \
240 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
241 'rm -f o e &&
242 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
243 test '"$Z"' = $(cat o) &&
244 test "" = "$(cat e)"'
245 test_expect_success \
246 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
247 'rm -f o e &&
248 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
249 test '"$E"' = $(cat o) &&
250 test "" = "$(cat e)"'
251 test_expect_success \
252 'Query "master@{2005-05-28}" (past end of history)' \
253 'rm -f o e &&
254 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
255 test '"$D"' = $(cat o) &&
256 test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"'
259 rm -f .git/$m .git/logs/$m expect
261 test_expect_success \
262 'creating initial files' \
263 'echo TEST >F &&
264 git add F &&
265 GIT_AUTHOR_DATE="2005-05-26 23:30" \
266 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
267 h_TEST=$(git rev-parse --verify HEAD) &&
268 echo The other day this did not work. >M &&
269 echo And then Bob told me how to fix it. >>M &&
270 echo OTHER >F &&
271 GIT_AUTHOR_DATE="2005-05-26 23:41" \
272 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
273 h_OTHER=$(git rev-parse --verify HEAD) &&
274 GIT_AUTHOR_DATE="2005-05-26 23:44" \
275 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
276 h_FIXED=$(git rev-parse --verify HEAD) &&
277 echo Merged initial commit and a later commit. >M &&
278 echo $h_TEST >.git/MERGE_HEAD &&
279 GIT_AUTHOR_DATE="2005-05-26 23:45" \
280 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
281 h_MERGED=$(git rev-parse --verify HEAD) &&
282 rm -f M'
284 cat >expect <<EOF
285 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
286 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
287 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
288 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
290 test_expect_success \
291 'git commit logged updates' \
292 "test_cmp expect .git/logs/$m"
293 unset h_TEST h_OTHER h_FIXED h_MERGED
295 test_expect_success \
296 'git cat-file blob master:F (expect OTHER)' \
297 'test OTHER = $(git cat-file blob master:F)'
298 test_expect_success \
299 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
300 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")'
301 test_expect_success \
302 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
303 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'
305 a=refs/heads/a
306 b=refs/heads/b
307 c=refs/heads/c
308 E='""'
309 F='%s\0'
310 pws='path with space'
312 test_expect_success 'stdin test setup' '
313 echo "$pws" >"$pws" &&
314 git add -- "$pws" &&
315 git commit -m "$pws"
318 test_expect_success '-z fails without --stdin' '
319 test_must_fail git update-ref -z $m $m $m 2>err &&
320 grep "usage: git update-ref" err
323 test_expect_success 'stdin works with no input' '
324 >stdin &&
325 git update-ref --stdin <stdin &&
326 git rev-parse --verify -q $m
329 test_expect_success 'stdin fails on empty line' '
330 echo "" >stdin &&
331 test_must_fail git update-ref --stdin <stdin 2>err &&
332 grep "fatal: empty command in input" err
335 test_expect_success 'stdin fails on only whitespace' '
336 echo " " >stdin &&
337 test_must_fail git update-ref --stdin <stdin 2>err &&
338 grep "fatal: whitespace before command: " err
341 test_expect_success 'stdin fails on leading whitespace' '
342 echo " create $a $m" >stdin &&
343 test_must_fail git update-ref --stdin <stdin 2>err &&
344 grep "fatal: whitespace before command: create $a $m" err
347 test_expect_success 'stdin fails on unknown command' '
348 echo "unknown $a" >stdin &&
349 test_must_fail git update-ref --stdin <stdin 2>err &&
350 grep "fatal: unknown command: unknown $a" err
353 test_expect_success 'stdin fails on badly quoted input' '
354 echo "create $a \"master" >stdin &&
355 test_must_fail git update-ref --stdin <stdin 2>err &&
356 grep "fatal: badly quoted argument: \\\"master" err
359 test_expect_success 'stdin fails on arguments not separated by space' '
360 echo "create \"$a\"master" >stdin &&
361 test_must_fail git update-ref --stdin <stdin 2>err &&
362 grep "fatal: expected SP but got: master" err
365 test_expect_success 'stdin fails create with no ref' '
366 echo "create " >stdin &&
367 test_must_fail git update-ref --stdin <stdin 2>err &&
368 grep "fatal: create line missing <ref>" err
371 test_expect_success 'stdin fails create with bad ref name' '
372 echo "create ~a $m" >stdin &&
373 test_must_fail git update-ref --stdin <stdin 2>err &&
374 grep "fatal: invalid ref format: ~a" err
377 test_expect_success 'stdin fails create with no new value' '
378 echo "create $a" >stdin &&
379 test_must_fail git update-ref --stdin <stdin 2>err &&
380 grep "fatal: create $a missing <newvalue>" err
383 test_expect_success 'stdin fails create with too many arguments' '
384 echo "create $a $m $m" >stdin &&
385 test_must_fail git update-ref --stdin <stdin 2>err &&
386 grep "fatal: create $a has extra input: $m" err
389 test_expect_success 'stdin fails update with no ref' '
390 echo "update " >stdin &&
391 test_must_fail git update-ref --stdin <stdin 2>err &&
392 grep "fatal: update line missing <ref>" err
395 test_expect_success 'stdin fails update with bad ref name' '
396 echo "update ~a $m" >stdin &&
397 test_must_fail git update-ref --stdin <stdin 2>err &&
398 grep "fatal: invalid ref format: ~a" err
401 test_expect_success 'stdin fails update with no new value' '
402 echo "update $a" >stdin &&
403 test_must_fail git update-ref --stdin <stdin 2>err &&
404 grep "fatal: update $a missing <newvalue>" err
407 test_expect_success 'stdin fails update with too many arguments' '
408 echo "update $a $m $m $m" >stdin &&
409 test_must_fail git update-ref --stdin <stdin 2>err &&
410 grep "fatal: update $a has extra input: $m" err
413 test_expect_success 'stdin fails delete with no ref' '
414 echo "delete " >stdin &&
415 test_must_fail git update-ref --stdin <stdin 2>err &&
416 grep "fatal: delete line missing <ref>" err
419 test_expect_success 'stdin fails delete with bad ref name' '
420 echo "delete ~a $m" >stdin &&
421 test_must_fail git update-ref --stdin <stdin 2>err &&
422 grep "fatal: invalid ref format: ~a" err
425 test_expect_success 'stdin fails delete with too many arguments' '
426 echo "delete $a $m $m" >stdin &&
427 test_must_fail git update-ref --stdin <stdin 2>err &&
428 grep "fatal: delete $a has extra input: $m" err
431 test_expect_success 'stdin fails verify with too many arguments' '
432 echo "verify $a $m $m" >stdin &&
433 test_must_fail git update-ref --stdin <stdin 2>err &&
434 grep "fatal: verify $a has extra input: $m" err
437 test_expect_success 'stdin fails option with unknown name' '
438 echo "option unknown" >stdin &&
439 test_must_fail git update-ref --stdin <stdin 2>err &&
440 grep "fatal: option unknown: unknown" err
443 test_expect_success 'stdin fails with duplicate refs' '
444 cat >stdin <<-EOF &&
445 create $a $m
446 create $b $m
447 create $a $m
449 test_must_fail git update-ref --stdin <stdin 2>err &&
450 grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
453 test_expect_success 'stdin create ref works' '
454 echo "create $a $m" >stdin &&
455 git update-ref --stdin <stdin &&
456 git rev-parse $m >expect &&
457 git rev-parse $a >actual &&
458 test_cmp expect actual
461 test_expect_success 'stdin update ref creates with zero old value' '
462 echo "update $b $m $Z" >stdin &&
463 git update-ref --stdin <stdin &&
464 git rev-parse $m >expect &&
465 git rev-parse $b >actual &&
466 test_cmp expect actual &&
467 git update-ref -d $b
470 test_expect_success 'stdin update ref creates with empty old value' '
471 echo "update $b $m $E" >stdin &&
472 git update-ref --stdin <stdin &&
473 git rev-parse $m >expect &&
474 git rev-parse $b >actual &&
475 test_cmp expect actual
478 test_expect_success 'stdin create ref works with path with space to blob' '
479 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
480 git update-ref --stdin <stdin &&
481 git rev-parse "$m:$pws" >expect &&
482 git rev-parse refs/blobs/pws >actual &&
483 test_cmp expect actual &&
484 git update-ref -d refs/blobs/pws
487 test_expect_success 'stdin update ref fails with wrong old value' '
488 echo "update $c $m $m~1" >stdin &&
489 test_must_fail git update-ref --stdin <stdin 2>err &&
490 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
491 test_must_fail git rev-parse --verify -q $c
494 test_expect_success 'stdin update ref fails with bad old value' '
495 echo "update $c $m does-not-exist" >stdin &&
496 test_must_fail git update-ref --stdin <stdin 2>err &&
497 grep "fatal: invalid old value for ref $c: does-not-exist" err &&
498 test_must_fail git rev-parse --verify -q $c
501 test_expect_success 'stdin create ref fails with bad new value' '
502 echo "create $c does-not-exist" >stdin &&
503 test_must_fail git update-ref --stdin <stdin 2>err &&
504 grep "fatal: invalid new value for ref $c: does-not-exist" err &&
505 test_must_fail git rev-parse --verify -q $c
508 test_expect_success 'stdin create ref fails with zero new value' '
509 echo "create $c " >stdin &&
510 test_must_fail git update-ref --stdin <stdin 2>err &&
511 grep "fatal: create $c given zero new value" err &&
512 test_must_fail git rev-parse --verify -q $c
515 test_expect_success 'stdin update ref works with right old value' '
516 echo "update $b $m~1 $m" >stdin &&
517 git update-ref --stdin <stdin &&
518 git rev-parse $m~1 >expect &&
519 git rev-parse $b >actual &&
520 test_cmp expect actual
523 test_expect_success 'stdin delete ref fails with wrong old value' '
524 echo "delete $a $m~1" >stdin &&
525 test_must_fail git update-ref --stdin <stdin 2>err &&
526 grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
527 git rev-parse $m >expect &&
528 git rev-parse $a >actual &&
529 test_cmp expect actual
532 test_expect_success 'stdin delete ref fails with zero old value' '
533 echo "delete $a " >stdin &&
534 test_must_fail git update-ref --stdin <stdin 2>err &&
535 grep "fatal: delete $a given zero old value" err &&
536 git rev-parse $m >expect &&
537 git rev-parse $a >actual &&
538 test_cmp expect actual
541 test_expect_success 'stdin update symref works option no-deref' '
542 git symbolic-ref TESTSYMREF $b &&
543 cat >stdin <<-EOF &&
544 option no-deref
545 update TESTSYMREF $a $b
547 git update-ref --stdin <stdin &&
548 git rev-parse TESTSYMREF >expect &&
549 git rev-parse $a >actual &&
550 test_cmp expect actual &&
551 git rev-parse $m~1 >expect &&
552 git rev-parse $b >actual &&
553 test_cmp expect actual
556 test_expect_success 'stdin delete symref works option no-deref' '
557 git symbolic-ref TESTSYMREF $b &&
558 cat >stdin <<-EOF &&
559 option no-deref
560 delete TESTSYMREF $b
562 git update-ref --stdin <stdin &&
563 test_must_fail git rev-parse --verify -q TESTSYMREF &&
564 git rev-parse $m~1 >expect &&
565 git rev-parse $b >actual &&
566 test_cmp expect actual
569 test_expect_success 'stdin delete ref works with right old value' '
570 echo "delete $b $m~1" >stdin &&
571 git update-ref --stdin <stdin &&
572 test_must_fail git rev-parse --verify -q $b
575 test_expect_success 'stdin update/create/verify combination works' '
576 cat >stdin <<-EOF &&
577 update $a $m
578 create $b $m
579 verify $c
581 git update-ref --stdin <stdin &&
582 git rev-parse $m >expect &&
583 git rev-parse $a >actual &&
584 test_cmp expect actual &&
585 git rev-parse $b >actual &&
586 test_cmp expect actual &&
587 test_must_fail git rev-parse --verify -q $c
590 test_expect_success 'stdin update refs works with identity updates' '
591 cat >stdin <<-EOF &&
592 update $a $m $m
593 update $b $m $m
594 update $c $Z $E
596 git update-ref --stdin <stdin &&
597 git rev-parse $m >expect &&
598 git rev-parse $a >actual &&
599 test_cmp expect actual &&
600 git rev-parse $b >actual &&
601 test_cmp expect actual &&
602 test_must_fail git rev-parse --verify -q $c
605 test_expect_success 'stdin update refs fails with wrong old value' '
606 git update-ref $c $m &&
607 cat >stdin <<-EOF &&
608 update $a $m $m
609 update $b $m $m
610 update $c ''
612 test_must_fail git update-ref --stdin <stdin 2>err &&
613 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
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 git rev-parse $c >actual &&
620 test_cmp expect actual
623 test_expect_success 'stdin delete refs works with packed and loose refs' '
624 git pack-refs --all &&
625 git update-ref $c $m~1 &&
626 cat >stdin <<-EOF &&
627 delete $a $m
628 update $b $Z $m
629 update $c $E $m~1
631 git update-ref --stdin <stdin &&
632 test_must_fail git rev-parse --verify -q $a &&
633 test_must_fail git rev-parse --verify -q $b &&
634 test_must_fail git rev-parse --verify -q $c
637 test_expect_success 'stdin -z works on empty input' '
638 >stdin &&
639 git update-ref -z --stdin <stdin &&
640 git rev-parse --verify -q $m
643 test_expect_success 'stdin -z fails on empty line' '
644 echo "" >stdin &&
645 test_must_fail git update-ref -z --stdin <stdin 2>err &&
646 grep "fatal: whitespace before command: " err
649 test_expect_success 'stdin -z fails on empty command' '
650 printf $F "" >stdin &&
651 test_must_fail git update-ref -z --stdin <stdin 2>err &&
652 grep "fatal: empty command in input" err
655 test_expect_success 'stdin -z fails on only whitespace' '
656 printf $F " " >stdin &&
657 test_must_fail git update-ref -z --stdin <stdin 2>err &&
658 grep "fatal: whitespace before command: " err
661 test_expect_success 'stdin -z fails on leading whitespace' '
662 printf $F " create $a" "$m" >stdin &&
663 test_must_fail git update-ref -z --stdin <stdin 2>err &&
664 grep "fatal: whitespace before command: create $a" err
667 test_expect_success 'stdin -z fails on unknown command' '
668 printf $F "unknown $a" >stdin &&
669 test_must_fail git update-ref -z --stdin <stdin 2>err &&
670 grep "fatal: unknown command: unknown $a" err
673 test_expect_success 'stdin -z fails create with no ref' '
674 printf $F "create " >stdin &&
675 test_must_fail git update-ref -z --stdin <stdin 2>err &&
676 grep "fatal: create line missing <ref>" err
679 test_expect_success 'stdin -z fails create with bad ref name' '
680 printf $F "create ~a " "$m" >stdin &&
681 test_must_fail git update-ref -z --stdin <stdin 2>err &&
682 grep "fatal: invalid ref format: ~a " err
685 test_expect_success 'stdin -z fails create with no new value' '
686 printf $F "create $a" >stdin &&
687 test_must_fail git update-ref -z --stdin <stdin 2>err &&
688 grep "fatal: create $a missing <newvalue>" err
691 test_expect_success 'stdin -z fails create with too many arguments' '
692 printf $F "create $a" "$m" "$m" >stdin &&
693 test_must_fail git update-ref -z --stdin <stdin 2>err &&
694 grep "fatal: unknown command: $m" err
697 test_expect_success 'stdin -z fails update with no ref' '
698 printf $F "update " >stdin &&
699 test_must_fail git update-ref -z --stdin <stdin 2>err &&
700 grep "fatal: update line missing <ref>" err
703 test_expect_success 'stdin -z fails update with bad ref name' '
704 printf $F "update ~a" "$m" >stdin &&
705 test_must_fail git update-ref -z --stdin <stdin 2>err &&
706 grep "fatal: invalid ref format: ~a" err
709 test_expect_success 'stdin -z fails update with no new value' '
710 printf $F "update $a" >stdin &&
711 test_must_fail git update-ref -z --stdin <stdin 2>err &&
712 grep "fatal: update $a missing <newvalue>" err
715 test_expect_success 'stdin -z fails update with no old value' '
716 printf $F "update $a" "$m" >stdin &&
717 test_must_fail git update-ref -z --stdin <stdin 2>err &&
718 grep "fatal: update $a missing \\[<oldvalue>\\] NUL" err
721 test_expect_success 'stdin -z fails update with too many arguments' '
722 printf $F "update $a" "$m" "$m" "$m" >stdin &&
723 test_must_fail git update-ref -z --stdin <stdin 2>err &&
724 grep "fatal: unknown command: $m" err
727 test_expect_success 'stdin -z fails delete with no ref' '
728 printf $F "delete " >stdin &&
729 test_must_fail git update-ref -z --stdin <stdin 2>err &&
730 grep "fatal: delete line missing <ref>" err
733 test_expect_success 'stdin -z fails delete with bad ref name' '
734 printf $F "delete ~a" "$m" >stdin &&
735 test_must_fail git update-ref -z --stdin <stdin 2>err &&
736 grep "fatal: invalid ref format: ~a" err
739 test_expect_success 'stdin -z fails delete with no old value' '
740 printf $F "delete $a" >stdin &&
741 test_must_fail git update-ref -z --stdin <stdin 2>err &&
742 grep "fatal: delete $a missing \\[<oldvalue>\\] NUL" err
745 test_expect_success 'stdin -z fails delete with too many arguments' '
746 printf $F "delete $a" "$m" "$m" >stdin &&
747 test_must_fail git update-ref -z --stdin <stdin 2>err &&
748 grep "fatal: unknown command: $m" err
751 test_expect_success 'stdin -z fails verify with too many arguments' '
752 printf $F "verify $a" "$m" "$m" >stdin &&
753 test_must_fail git update-ref -z --stdin <stdin 2>err &&
754 grep "fatal: unknown command: $m" err
757 test_expect_success 'stdin -z fails verify with no old value' '
758 printf $F "verify $a" >stdin &&
759 test_must_fail git update-ref -z --stdin <stdin 2>err &&
760 grep "fatal: verify $a missing \\[<oldvalue>\\] NUL" err
763 test_expect_success 'stdin -z fails option with unknown name' '
764 printf $F "option unknown" >stdin &&
765 test_must_fail git update-ref -z --stdin <stdin 2>err &&
766 grep "fatal: option unknown: unknown" err
769 test_expect_success 'stdin -z fails with duplicate refs' '
770 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
771 test_must_fail git update-ref -z --stdin <stdin 2>err &&
772 grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
775 test_expect_success 'stdin -z create ref works' '
776 printf $F "create $a" "$m" >stdin &&
777 git update-ref -z --stdin <stdin &&
778 git rev-parse $m >expect &&
779 git rev-parse $a >actual &&
780 test_cmp expect actual
783 test_expect_success 'stdin -z update ref creates with zero old value' '
784 printf $F "update $b" "$m" "$Z" >stdin &&
785 git update-ref -z --stdin <stdin &&
786 git rev-parse $m >expect &&
787 git rev-parse $b >actual &&
788 test_cmp expect actual &&
789 git update-ref -d $b
792 test_expect_success 'stdin -z update ref creates with empty old value' '
793 printf $F "update $b" "$m" "" >stdin &&
794 git update-ref -z --stdin <stdin &&
795 git rev-parse $m >expect &&
796 git rev-parse $b >actual &&
797 test_cmp expect actual
800 test_expect_success 'stdin -z create ref works with path with space to blob' '
801 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
802 git update-ref -z --stdin <stdin &&
803 git rev-parse "$m:$pws" >expect &&
804 git rev-parse refs/blobs/pws >actual &&
805 test_cmp expect actual &&
806 git update-ref -d refs/blobs/pws
809 test_expect_success 'stdin -z update ref fails with wrong old value' '
810 printf $F "update $c" "$m" "$m~1" >stdin &&
811 test_must_fail git update-ref -z --stdin <stdin 2>err &&
812 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
813 test_must_fail git rev-parse --verify -q $c
816 test_expect_success 'stdin -z update ref fails with bad old value' '
817 printf $F "update $c" "$m" "does-not-exist" >stdin &&
818 test_must_fail git update-ref -z --stdin <stdin 2>err &&
819 grep "fatal: invalid old value for ref $c: does-not-exist" err &&
820 test_must_fail git rev-parse --verify -q $c
823 test_expect_success 'stdin -z create ref fails with bad new value' '
824 printf $F "create $c" "does-not-exist" >stdin &&
825 test_must_fail git update-ref -z --stdin <stdin 2>err &&
826 grep "fatal: invalid new value for ref $c: does-not-exist" err &&
827 test_must_fail git rev-parse --verify -q $c
830 test_expect_success 'stdin -z create ref fails with zero new value' '
831 printf $F "create $c" "" >stdin &&
832 test_must_fail git update-ref -z --stdin <stdin 2>err &&
833 grep "fatal: create $c given zero new value" err &&
834 test_must_fail git rev-parse --verify -q $c
837 test_expect_success 'stdin -z update ref works with right old value' '
838 printf $F "update $b" "$m~1" "$m" >stdin &&
839 git update-ref -z --stdin <stdin &&
840 git rev-parse $m~1 >expect &&
841 git rev-parse $b >actual &&
842 test_cmp expect actual
845 test_expect_success 'stdin -z delete ref fails with wrong old value' '
846 printf $F "delete $a" "$m~1" >stdin &&
847 test_must_fail git update-ref -z --stdin <stdin 2>err &&
848 grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
849 git rev-parse $m >expect &&
850 git rev-parse $a >actual &&
851 test_cmp expect actual
854 test_expect_success 'stdin -z delete ref fails with zero old value' '
855 printf $F "delete $a" "$Z" >stdin &&
856 test_must_fail git update-ref -z --stdin <stdin 2>err &&
857 grep "fatal: delete $a given zero old value" err &&
858 git rev-parse $m >expect &&
859 git rev-parse $a >actual &&
860 test_cmp expect actual
863 test_expect_success 'stdin -z update symref works option no-deref' '
864 git symbolic-ref TESTSYMREF $b &&
865 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
866 git update-ref -z --stdin <stdin &&
867 git rev-parse TESTSYMREF >expect &&
868 git rev-parse $a >actual &&
869 test_cmp expect actual &&
870 git rev-parse $m~1 >expect &&
871 git rev-parse $b >actual &&
872 test_cmp expect actual
875 test_expect_success 'stdin -z delete symref works option no-deref' '
876 git symbolic-ref TESTSYMREF $b &&
877 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
878 git update-ref -z --stdin <stdin &&
879 test_must_fail git rev-parse --verify -q TESTSYMREF &&
880 git rev-parse $m~1 >expect &&
881 git rev-parse $b >actual &&
882 test_cmp expect actual
885 test_expect_success 'stdin -z delete ref works with right old value' '
886 printf $F "delete $b" "$m~1" >stdin &&
887 git update-ref -z --stdin <stdin &&
888 test_must_fail git rev-parse --verify -q $b
891 test_expect_success 'stdin -z update/create/verify combination works' '
892 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
893 git update-ref -z --stdin <stdin &&
894 git rev-parse $m >expect &&
895 git rev-parse $a >actual &&
896 test_cmp expect actual &&
897 git rev-parse $b >actual &&
898 test_cmp expect actual &&
899 test_must_fail git rev-parse --verify -q $c
902 test_expect_success 'stdin -z update refs works with identity updates' '
903 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
904 git update-ref -z --stdin <stdin &&
905 git rev-parse $m >expect &&
906 git rev-parse $a >actual &&
907 test_cmp expect actual &&
908 git rev-parse $b >actual &&
909 test_cmp expect actual &&
910 test_must_fail git rev-parse --verify -q $c
913 test_expect_success 'stdin -z update refs fails with wrong old value' '
914 git update-ref $c $m &&
915 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "" "$Z" >stdin &&
916 test_must_fail git update-ref -z --stdin <stdin 2>err &&
917 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
918 git rev-parse $m >expect &&
919 git rev-parse $a >actual &&
920 test_cmp expect actual &&
921 git rev-parse $b >actual &&
922 test_cmp expect actual &&
923 git rev-parse $c >actual &&
924 test_cmp expect actual
927 test_expect_success 'stdin -z delete refs works with packed and loose refs' '
928 git pack-refs --all &&
929 git update-ref $c $m~1 &&
930 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
931 git update-ref -z --stdin <stdin &&
932 test_must_fail git rev-parse --verify -q $a &&
933 test_must_fail git rev-parse --verify -q $b &&
934 test_must_fail git rev-parse --verify -q $c
937 test_done