Merge branch 'ta/config-set-2'
[alt-git.git] / t / t1400-update-ref.sh
blob0218e96366ddd8659d5a78b42ffcfd415013114c
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 for ref '"$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 for ref '"$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 unbalanced quotes' '
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 invalid escape' '
360 echo "create $a \"ma\zter\"" >stdin &&
361 test_must_fail git update-ref --stdin <stdin 2>err &&
362 grep "fatal: badly quoted argument: \\\"ma\\\\zter\\\"" err
365 test_expect_success 'stdin fails on junk after quoted argument' '
366 echo "create \"$a\"master" >stdin &&
367 test_must_fail git update-ref --stdin <stdin 2>err &&
368 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"master" err
371 test_expect_success 'stdin fails create with no ref' '
372 echo "create " >stdin &&
373 test_must_fail git update-ref --stdin <stdin 2>err &&
374 grep "fatal: create: missing <ref>" err
377 test_expect_success 'stdin fails create with bad ref name' '
378 echo "create ~a $m" >stdin &&
379 test_must_fail git update-ref --stdin <stdin 2>err &&
380 grep "fatal: invalid ref format: ~a" err
383 test_expect_success 'stdin fails create with no new value' '
384 echo "create $a" >stdin &&
385 test_must_fail git update-ref --stdin <stdin 2>err &&
386 grep "fatal: create $a: missing <newvalue>" err
389 test_expect_success 'stdin fails create with too many arguments' '
390 echo "create $a $m $m" >stdin &&
391 test_must_fail git update-ref --stdin <stdin 2>err &&
392 grep "fatal: create $a: extra input: $m" err
395 test_expect_success 'stdin fails update with no ref' '
396 echo "update " >stdin &&
397 test_must_fail git update-ref --stdin <stdin 2>err &&
398 grep "fatal: update: missing <ref>" err
401 test_expect_success 'stdin fails update with bad ref name' '
402 echo "update ~a $m" >stdin &&
403 test_must_fail git update-ref --stdin <stdin 2>err &&
404 grep "fatal: invalid ref format: ~a" err
407 test_expect_success 'stdin fails update with no new value' '
408 echo "update $a" >stdin &&
409 test_must_fail git update-ref --stdin <stdin 2>err &&
410 grep "fatal: update $a: missing <newvalue>" err
413 test_expect_success 'stdin fails update with too many arguments' '
414 echo "update $a $m $m $m" >stdin &&
415 test_must_fail git update-ref --stdin <stdin 2>err &&
416 grep "fatal: update $a: extra input: $m" err
419 test_expect_success 'stdin fails delete with no ref' '
420 echo "delete " >stdin &&
421 test_must_fail git update-ref --stdin <stdin 2>err &&
422 grep "fatal: delete: missing <ref>" err
425 test_expect_success 'stdin fails delete with bad ref name' '
426 echo "delete ~a $m" >stdin &&
427 test_must_fail git update-ref --stdin <stdin 2>err &&
428 grep "fatal: invalid ref format: ~a" err
431 test_expect_success 'stdin fails delete with too many arguments' '
432 echo "delete $a $m $m" >stdin &&
433 test_must_fail git update-ref --stdin <stdin 2>err &&
434 grep "fatal: delete $a: extra input: $m" err
437 test_expect_success 'stdin fails verify with too many arguments' '
438 echo "verify $a $m $m" >stdin &&
439 test_must_fail git update-ref --stdin <stdin 2>err &&
440 grep "fatal: verify $a: extra input: $m" err
443 test_expect_success 'stdin fails option with unknown name' '
444 echo "option unknown" >stdin &&
445 test_must_fail git update-ref --stdin <stdin 2>err &&
446 grep "fatal: option unknown: unknown" err
449 test_expect_success 'stdin fails with duplicate refs' '
450 cat >stdin <<-EOF &&
451 create $a $m
452 create $b $m
453 create $a $m
455 test_must_fail git update-ref --stdin <stdin 2>err &&
456 grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
459 test_expect_success 'stdin create ref works' '
460 echo "create $a $m" >stdin &&
461 git update-ref --stdin <stdin &&
462 git rev-parse $m >expect &&
463 git rev-parse $a >actual &&
464 test_cmp expect actual
467 test_expect_success 'stdin succeeds with quoted argument' '
468 git update-ref -d $a &&
469 echo "create $a \"$m\"" >stdin &&
470 git update-ref --stdin <stdin &&
471 git rev-parse $m >expect &&
472 git rev-parse $a >actual &&
473 test_cmp expect actual
476 test_expect_success 'stdin succeeds with escaped character' '
477 git update-ref -d $a &&
478 echo "create $a \"ma\\163ter\"" >stdin &&
479 git update-ref --stdin <stdin &&
480 git rev-parse $m >expect &&
481 git rev-parse $a >actual &&
482 test_cmp expect actual
485 test_expect_success 'stdin update ref creates with zero old value' '
486 echo "update $b $m $Z" >stdin &&
487 git update-ref --stdin <stdin &&
488 git rev-parse $m >expect &&
489 git rev-parse $b >actual &&
490 test_cmp expect actual &&
491 git update-ref -d $b
494 test_expect_success 'stdin update ref creates with empty old value' '
495 echo "update $b $m $E" >stdin &&
496 git update-ref --stdin <stdin &&
497 git rev-parse $m >expect &&
498 git rev-parse $b >actual &&
499 test_cmp expect actual
502 test_expect_success 'stdin create ref works with path with space to blob' '
503 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
504 git update-ref --stdin <stdin &&
505 git rev-parse "$m:$pws" >expect &&
506 git rev-parse refs/blobs/pws >actual &&
507 test_cmp expect actual &&
508 git update-ref -d refs/blobs/pws
511 test_expect_success 'stdin update ref fails with wrong old value' '
512 echo "update $c $m $m~1" >stdin &&
513 test_must_fail git update-ref --stdin <stdin 2>err &&
514 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
515 test_must_fail git rev-parse --verify -q $c
518 test_expect_success 'stdin update ref fails with bad old value' '
519 echo "update $c $m does-not-exist" >stdin &&
520 test_must_fail git update-ref --stdin <stdin 2>err &&
521 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
522 test_must_fail git rev-parse --verify -q $c
525 test_expect_success 'stdin create ref fails with bad new value' '
526 echo "create $c does-not-exist" >stdin &&
527 test_must_fail git update-ref --stdin <stdin 2>err &&
528 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
529 test_must_fail git rev-parse --verify -q $c
532 test_expect_success 'stdin create ref fails with zero new value' '
533 echo "create $c " >stdin &&
534 test_must_fail git update-ref --stdin <stdin 2>err &&
535 grep "fatal: create $c: zero <newvalue>" err &&
536 test_must_fail git rev-parse --verify -q $c
539 test_expect_success 'stdin update ref works with right old value' '
540 echo "update $b $m~1 $m" >stdin &&
541 git update-ref --stdin <stdin &&
542 git rev-parse $m~1 >expect &&
543 git rev-parse $b >actual &&
544 test_cmp expect actual
547 test_expect_success 'stdin delete ref fails with wrong old value' '
548 echo "delete $a $m~1" >stdin &&
549 test_must_fail git update-ref --stdin <stdin 2>err &&
550 grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
551 git rev-parse $m >expect &&
552 git rev-parse $a >actual &&
553 test_cmp expect actual
556 test_expect_success 'stdin delete ref fails with zero old value' '
557 echo "delete $a " >stdin &&
558 test_must_fail git update-ref --stdin <stdin 2>err &&
559 grep "fatal: delete $a: zero <oldvalue>" err &&
560 git rev-parse $m >expect &&
561 git rev-parse $a >actual &&
562 test_cmp expect actual
565 test_expect_success 'stdin update symref works option no-deref' '
566 git symbolic-ref TESTSYMREF $b &&
567 cat >stdin <<-EOF &&
568 option no-deref
569 update TESTSYMREF $a $b
571 git update-ref --stdin <stdin &&
572 git rev-parse TESTSYMREF >expect &&
573 git rev-parse $a >actual &&
574 test_cmp expect actual &&
575 git rev-parse $m~1 >expect &&
576 git rev-parse $b >actual &&
577 test_cmp expect actual
580 test_expect_success 'stdin delete symref works option no-deref' '
581 git symbolic-ref TESTSYMREF $b &&
582 cat >stdin <<-EOF &&
583 option no-deref
584 delete TESTSYMREF $b
586 git update-ref --stdin <stdin &&
587 test_must_fail git rev-parse --verify -q TESTSYMREF &&
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 works with right old value' '
594 echo "delete $b $m~1" >stdin &&
595 git update-ref --stdin <stdin &&
596 test_must_fail git rev-parse --verify -q $b
599 test_expect_success 'stdin update/create/verify combination works' '
600 cat >stdin <<-EOF &&
601 update $a $m
602 create $b $m
603 verify $c
605 git update-ref --stdin <stdin &&
606 git rev-parse $m >expect &&
607 git rev-parse $a >actual &&
608 test_cmp expect actual &&
609 git rev-parse $b >actual &&
610 test_cmp expect actual &&
611 test_must_fail git rev-parse --verify -q $c
614 test_expect_success 'stdin update refs works with identity updates' '
615 cat >stdin <<-EOF &&
616 update $a $m $m
617 update $b $m $m
618 update $c $Z $E
620 git update-ref --stdin <stdin &&
621 git rev-parse $m >expect &&
622 git rev-parse $a >actual &&
623 test_cmp expect actual &&
624 git rev-parse $b >actual &&
625 test_cmp expect actual &&
626 test_must_fail git rev-parse --verify -q $c
629 test_expect_success 'stdin update refs fails with wrong old value' '
630 git update-ref $c $m &&
631 cat >stdin <<-EOF &&
632 update $a $m $m
633 update $b $m $m
634 update $c ''
636 test_must_fail git update-ref --stdin <stdin 2>err &&
637 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
638 git rev-parse $m >expect &&
639 git rev-parse $a >actual &&
640 test_cmp expect actual &&
641 git rev-parse $b >actual &&
642 test_cmp expect actual &&
643 git rev-parse $c >actual &&
644 test_cmp expect actual
647 test_expect_success 'stdin delete refs works with packed and loose refs' '
648 git pack-refs --all &&
649 git update-ref $c $m~1 &&
650 cat >stdin <<-EOF &&
651 delete $a $m
652 update $b $Z $m
653 update $c $E $m~1
655 git update-ref --stdin <stdin &&
656 test_must_fail git rev-parse --verify -q $a &&
657 test_must_fail git rev-parse --verify -q $b &&
658 test_must_fail git rev-parse --verify -q $c
661 test_expect_success 'stdin -z works on empty input' '
662 >stdin &&
663 git update-ref -z --stdin <stdin &&
664 git rev-parse --verify -q $m
667 test_expect_success 'stdin -z fails on empty line' '
668 echo "" >stdin &&
669 test_must_fail git update-ref -z --stdin <stdin 2>err &&
670 grep "fatal: whitespace before command: " err
673 test_expect_success 'stdin -z fails on empty command' '
674 printf $F "" >stdin &&
675 test_must_fail git update-ref -z --stdin <stdin 2>err &&
676 grep "fatal: empty command in input" err
679 test_expect_success 'stdin -z fails on only whitespace' '
680 printf $F " " >stdin &&
681 test_must_fail git update-ref -z --stdin <stdin 2>err &&
682 grep "fatal: whitespace before command: " err
685 test_expect_success 'stdin -z fails on leading whitespace' '
686 printf $F " create $a" "$m" >stdin &&
687 test_must_fail git update-ref -z --stdin <stdin 2>err &&
688 grep "fatal: whitespace before command: create $a" err
691 test_expect_success 'stdin -z fails on unknown command' '
692 printf $F "unknown $a" >stdin &&
693 test_must_fail git update-ref -z --stdin <stdin 2>err &&
694 grep "fatal: unknown command: unknown $a" err
697 test_expect_success 'stdin -z fails create with no ref' '
698 printf $F "create " >stdin &&
699 test_must_fail git update-ref -z --stdin <stdin 2>err &&
700 grep "fatal: create: missing <ref>" err
703 test_expect_success 'stdin -z fails create with bad ref name' '
704 printf $F "create ~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 create with no new value' '
710 printf $F "create $a" >stdin &&
711 test_must_fail git update-ref -z --stdin <stdin 2>err &&
712 grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
715 test_expect_success 'stdin -z fails create with too many arguments' '
716 printf $F "create $a" "$m" "$m" >stdin &&
717 test_must_fail git update-ref -z --stdin <stdin 2>err &&
718 grep "fatal: unknown command: $m" err
721 test_expect_success 'stdin -z fails update with no ref' '
722 printf $F "update " >stdin &&
723 test_must_fail git update-ref -z --stdin <stdin 2>err &&
724 grep "fatal: update: missing <ref>" err
727 test_expect_success 'stdin -z fails update with too few args' '
728 printf $F "update $a" "$m" >stdin &&
729 test_must_fail git update-ref -z --stdin <stdin 2>err &&
730 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
733 test_expect_success 'stdin -z fails update with bad ref name' '
734 printf $F "update ~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 emits warning with empty new value' '
740 git update-ref $a $m &&
741 printf $F "update $a" "" "" >stdin &&
742 git update-ref -z --stdin <stdin 2>err &&
743 grep "warning: update $a: missing <newvalue>, treating as zero" err &&
744 test_must_fail git rev-parse --verify -q $a
747 test_expect_success 'stdin -z fails update with no new value' '
748 printf $F "update $a" >stdin &&
749 test_must_fail git update-ref -z --stdin <stdin 2>err &&
750 grep "fatal: update $a: unexpected end of input when reading <newvalue>" err
753 test_expect_success 'stdin -z fails update with no old value' '
754 printf $F "update $a" "$m" >stdin &&
755 test_must_fail git update-ref -z --stdin <stdin 2>err &&
756 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
759 test_expect_success 'stdin -z fails update with too many arguments' '
760 printf $F "update $a" "$m" "$m" "$m" >stdin &&
761 test_must_fail git update-ref -z --stdin <stdin 2>err &&
762 grep "fatal: unknown command: $m" err
765 test_expect_success 'stdin -z fails delete with no ref' '
766 printf $F "delete " >stdin &&
767 test_must_fail git update-ref -z --stdin <stdin 2>err &&
768 grep "fatal: delete: missing <ref>" err
771 test_expect_success 'stdin -z fails delete with bad ref name' '
772 printf $F "delete ~a" "$m" >stdin &&
773 test_must_fail git update-ref -z --stdin <stdin 2>err &&
774 grep "fatal: invalid ref format: ~a" err
777 test_expect_success 'stdin -z fails delete with no old value' '
778 printf $F "delete $a" >stdin &&
779 test_must_fail git update-ref -z --stdin <stdin 2>err &&
780 grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
783 test_expect_success 'stdin -z fails delete with too many arguments' '
784 printf $F "delete $a" "$m" "$m" >stdin &&
785 test_must_fail git update-ref -z --stdin <stdin 2>err &&
786 grep "fatal: unknown command: $m" err
789 test_expect_success 'stdin -z fails verify with too many arguments' '
790 printf $F "verify $a" "$m" "$m" >stdin &&
791 test_must_fail git update-ref -z --stdin <stdin 2>err &&
792 grep "fatal: unknown command: $m" err
795 test_expect_success 'stdin -z fails verify with no old value' '
796 printf $F "verify $a" >stdin &&
797 test_must_fail git update-ref -z --stdin <stdin 2>err &&
798 grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err
801 test_expect_success 'stdin -z fails option with unknown name' '
802 printf $F "option unknown" >stdin &&
803 test_must_fail git update-ref -z --stdin <stdin 2>err &&
804 grep "fatal: option unknown: unknown" err
807 test_expect_success 'stdin -z fails with duplicate refs' '
808 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
809 test_must_fail git update-ref -z --stdin <stdin 2>err &&
810 grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
813 test_expect_success 'stdin -z create ref works' '
814 printf $F "create $a" "$m" >stdin &&
815 git update-ref -z --stdin <stdin &&
816 git rev-parse $m >expect &&
817 git rev-parse $a >actual &&
818 test_cmp expect actual
821 test_expect_success 'stdin -z update ref creates with zero old value' '
822 printf $F "update $b" "$m" "$Z" >stdin &&
823 git update-ref -z --stdin <stdin &&
824 git rev-parse $m >expect &&
825 git rev-parse $b >actual &&
826 test_cmp expect actual &&
827 git update-ref -d $b
830 test_expect_success 'stdin -z update ref creates with empty old value' '
831 printf $F "update $b" "$m" "" >stdin &&
832 git update-ref -z --stdin <stdin &&
833 git rev-parse $m >expect &&
834 git rev-parse $b >actual &&
835 test_cmp expect actual
838 test_expect_success 'stdin -z create ref works with path with space to blob' '
839 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
840 git update-ref -z --stdin <stdin &&
841 git rev-parse "$m:$pws" >expect &&
842 git rev-parse refs/blobs/pws >actual &&
843 test_cmp expect actual &&
844 git update-ref -d refs/blobs/pws
847 test_expect_success 'stdin -z update ref fails with wrong old value' '
848 printf $F "update $c" "$m" "$m~1" >stdin &&
849 test_must_fail git update-ref -z --stdin <stdin 2>err &&
850 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
851 test_must_fail git rev-parse --verify -q $c
854 test_expect_success 'stdin -z update ref fails with bad old value' '
855 printf $F "update $c" "$m" "does-not-exist" >stdin &&
856 test_must_fail git update-ref -z --stdin <stdin 2>err &&
857 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
858 test_must_fail git rev-parse --verify -q $c
861 test_expect_success 'stdin -z create ref fails when ref exists' '
862 git update-ref $c $m &&
863 git rev-parse "$c" >expect &&
864 printf $F "create $c" "$m~1" >stdin &&
865 test_must_fail git update-ref -z --stdin <stdin 2>err &&
866 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
867 git rev-parse "$c" >actual &&
868 test_cmp expect actual
871 test_expect_success 'stdin -z create ref fails with bad new value' '
872 git update-ref -d "$c" &&
873 printf $F "create $c" "does-not-exist" >stdin &&
874 test_must_fail git update-ref -z --stdin <stdin 2>err &&
875 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
876 test_must_fail git rev-parse --verify -q $c
879 test_expect_success 'stdin -z create ref fails with empty new value' '
880 printf $F "create $c" "" >stdin &&
881 test_must_fail git update-ref -z --stdin <stdin 2>err &&
882 grep "fatal: create $c: missing <newvalue>" err &&
883 test_must_fail git rev-parse --verify -q $c
886 test_expect_success 'stdin -z update ref works with right old value' '
887 printf $F "update $b" "$m~1" "$m" >stdin &&
888 git update-ref -z --stdin <stdin &&
889 git rev-parse $m~1 >expect &&
890 git rev-parse $b >actual &&
891 test_cmp expect actual
894 test_expect_success 'stdin -z delete ref fails with wrong old value' '
895 printf $F "delete $a" "$m~1" >stdin &&
896 test_must_fail git update-ref -z --stdin <stdin 2>err &&
897 grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
898 git rev-parse $m >expect &&
899 git rev-parse $a >actual &&
900 test_cmp expect actual
903 test_expect_success 'stdin -z delete ref fails with zero old value' '
904 printf $F "delete $a" "$Z" >stdin &&
905 test_must_fail git update-ref -z --stdin <stdin 2>err &&
906 grep "fatal: delete $a: zero <oldvalue>" err &&
907 git rev-parse $m >expect &&
908 git rev-parse $a >actual &&
909 test_cmp expect actual
912 test_expect_success 'stdin -z update symref works option no-deref' '
913 git symbolic-ref TESTSYMREF $b &&
914 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
915 git update-ref -z --stdin <stdin &&
916 git rev-parse TESTSYMREF >expect &&
917 git rev-parse $a >actual &&
918 test_cmp expect actual &&
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 symref works option no-deref' '
925 git symbolic-ref TESTSYMREF $b &&
926 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
927 git update-ref -z --stdin <stdin &&
928 test_must_fail git rev-parse --verify -q TESTSYMREF &&
929 git rev-parse $m~1 >expect &&
930 git rev-parse $b >actual &&
931 test_cmp expect actual
934 test_expect_success 'stdin -z delete ref works with right old value' '
935 printf $F "delete $b" "$m~1" >stdin &&
936 git update-ref -z --stdin <stdin &&
937 test_must_fail git rev-parse --verify -q $b
940 test_expect_success 'stdin -z update/create/verify combination works' '
941 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
942 git update-ref -z --stdin <stdin &&
943 git rev-parse $m >expect &&
944 git rev-parse $a >actual &&
945 test_cmp expect actual &&
946 git rev-parse $b >actual &&
947 test_cmp expect actual &&
948 test_must_fail git rev-parse --verify -q $c
951 test_expect_success 'stdin -z update refs works with identity updates' '
952 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
953 git update-ref -z --stdin <stdin &&
954 git rev-parse $m >expect &&
955 git rev-parse $a >actual &&
956 test_cmp expect actual &&
957 git rev-parse $b >actual &&
958 test_cmp expect actual &&
959 test_must_fail git rev-parse --verify -q $c
962 test_expect_success 'stdin -z update refs fails with wrong old value' '
963 git update-ref $c $m &&
964 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
965 test_must_fail git update-ref -z --stdin <stdin 2>err &&
966 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
967 git rev-parse $m >expect &&
968 git rev-parse $a >actual &&
969 test_cmp expect actual &&
970 git rev-parse $b >actual &&
971 test_cmp expect actual &&
972 git rev-parse $c >actual &&
973 test_cmp expect actual
976 test_expect_success 'stdin -z delete refs works with packed and loose refs' '
977 git pack-refs --all &&
978 git update-ref $c $m~1 &&
979 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
980 git update-ref -z --stdin <stdin &&
981 test_must_fail git rev-parse --verify -q $a &&
982 test_must_fail git rev-parse --verify -q $b &&
983 test_must_fail git rev-parse --verify -q $c
986 test_done