branch -d: simplify by using RESOLVE_REF_READING
[alt-git.git] / t / t1400-update-ref.sh
blob7c8c41a1a0f063a068ce793a95cadf22b131e80b
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 '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 'update-ref --no-deref -d can delete reference to broken name' '
140 git symbolic-ref refs/heads/badname refs/heads/broken...ref &&
141 test_when_finished "rm -f .git/refs/heads/badname" &&
142 test_path_is_file .git/refs/heads/badname &&
143 git update-ref --no-deref -d refs/heads/badname &&
144 test_path_is_missing .git/refs/heads/badname
147 test_expect_success '(not) create HEAD with old sha1' "
148 test_must_fail git update-ref HEAD $A $B
150 test_expect_success "(not) prior created .git/$m" "
151 ! test -f .git/$m
153 rm -f .git/$m
155 test_expect_success \
156 "create HEAD" \
157 "git update-ref HEAD $A"
158 test_expect_success '(not) change HEAD with wrong SHA1' "
159 test_must_fail git update-ref HEAD $B $Z
161 test_expect_success "(not) changed .git/$m" "
162 ! test $B"' = $(cat .git/'"$m"')
164 rm -f .git/$m
166 : a repository with working tree always has reflog these days...
167 : >.git/logs/refs/heads/master
168 test_expect_success \
169 "create $m (logged by touch)" \
170 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
171 git update-ref HEAD '"$A"' -m "Initial Creation" &&
172 test '"$A"' = $(cat .git/'"$m"')'
173 test_expect_success \
174 "update $m (logged by touch)" \
175 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
176 git update-ref HEAD'" $B $A "'-m "Switch" &&
177 test '"$B"' = $(cat .git/'"$m"')'
178 test_expect_success \
179 "set $m (logged by touch)" \
180 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
181 git update-ref HEAD'" $A &&
182 test $A"' = $(cat .git/'"$m"')'
184 cat >expect <<EOF
185 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
186 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
187 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
189 test_expect_success \
190 "verifying $m's log" \
191 "test_cmp expect .git/logs/$m"
192 rm -rf .git/$m .git/logs expect
194 test_expect_success \
195 'enable core.logAllRefUpdates' \
196 'git config core.logAllRefUpdates true &&
197 test true = $(git config --bool --get core.logAllRefUpdates)'
199 test_expect_success \
200 "create $m (logged by config)" \
201 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
202 git update-ref HEAD'" $A "'-m "Initial Creation" &&
203 test '"$A"' = $(cat .git/'"$m"')'
204 test_expect_success \
205 "update $m (logged by config)" \
206 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
207 git update-ref HEAD'" $B $A "'-m "Switch" &&
208 test '"$B"' = $(cat .git/'"$m"')'
209 test_expect_success \
210 "set $m (logged by config)" \
211 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
212 git update-ref HEAD '"$A &&
213 test $A"' = $(cat .git/'"$m"')'
215 cat >expect <<EOF
216 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
217 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
218 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
220 test_expect_success \
221 "verifying $m's log" \
222 'test_cmp expect .git/logs/$m'
223 rm -f .git/$m .git/logs/$m expect
225 git update-ref $m $D
226 cat >.git/logs/$m <<EOF
227 0000000000000000000000000000000000000000 $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
228 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
229 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
230 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
231 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
234 ed="Thu, 26 May 2005 18:32:00 -0500"
235 gd="Thu, 26 May 2005 18:33:00 -0500"
236 ld="Thu, 26 May 2005 18:43:00 -0500"
237 test_expect_success \
238 'Query "master@{May 25 2005}" (before history)' \
239 'rm -f o e &&
240 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
241 test '"$C"' = $(cat o) &&
242 test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
243 test_expect_success \
244 "Query master@{2005-05-25} (before history)" \
245 'rm -f o e &&
246 git rev-parse --verify master@{2005-05-25} >o 2>e &&
247 test '"$C"' = $(cat o) &&
248 echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
249 test_expect_success \
250 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
251 'rm -f o e &&
252 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
253 test '"$C"' = $(cat o) &&
254 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
255 test_expect_success \
256 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
257 'rm -f o e &&
258 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
259 test '"$C"' = $(cat o) &&
260 test "" = "$(cat e)"'
261 test_expect_success \
262 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \
263 'rm -f o e &&
264 git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e &&
265 test '"$A"' = $(cat o) &&
266 test "" = "$(cat e)"'
267 test_expect_success \
268 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
269 'rm -f o e &&
270 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
271 test '"$B"' = $(cat o) &&
272 test "warning: Log for ref '"$m has gap after $gd"'." = "$(cat e)"'
273 test_expect_success \
274 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
275 'rm -f o e &&
276 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
277 test '"$Z"' = $(cat o) &&
278 test "" = "$(cat e)"'
279 test_expect_success \
280 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
281 'rm -f o e &&
282 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
283 test '"$E"' = $(cat o) &&
284 test "" = "$(cat e)"'
285 test_expect_success \
286 'Query "master@{2005-05-28}" (past end of history)' \
287 'rm -f o e &&
288 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
289 test '"$D"' = $(cat o) &&
290 test "warning: Log for ref '"$m unexpectedly ended on $ld"'." = "$(cat e)"'
293 rm -f .git/$m .git/logs/$m expect
295 test_expect_success \
296 'creating initial files' \
297 'echo TEST >F &&
298 git add F &&
299 GIT_AUTHOR_DATE="2005-05-26 23:30" \
300 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
301 h_TEST=$(git rev-parse --verify HEAD) &&
302 echo The other day this did not work. >M &&
303 echo And then Bob told me how to fix it. >>M &&
304 echo OTHER >F &&
305 GIT_AUTHOR_DATE="2005-05-26 23:41" \
306 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
307 h_OTHER=$(git rev-parse --verify HEAD) &&
308 GIT_AUTHOR_DATE="2005-05-26 23:44" \
309 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
310 h_FIXED=$(git rev-parse --verify HEAD) &&
311 echo Merged initial commit and a later commit. >M &&
312 echo $h_TEST >.git/MERGE_HEAD &&
313 GIT_AUTHOR_DATE="2005-05-26 23:45" \
314 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
315 h_MERGED=$(git rev-parse --verify HEAD) &&
316 rm -f M'
318 cat >expect <<EOF
319 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
320 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
321 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
322 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
324 test_expect_success \
325 'git commit logged updates' \
326 "test_cmp expect .git/logs/$m"
327 unset h_TEST h_OTHER h_FIXED h_MERGED
329 test_expect_success \
330 'git cat-file blob master:F (expect OTHER)' \
331 'test OTHER = $(git cat-file blob master:F)'
332 test_expect_success \
333 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
334 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")'
335 test_expect_success \
336 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
337 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'
339 a=refs/heads/a
340 b=refs/heads/b
341 c=refs/heads/c
342 E='""'
343 F='%s\0'
344 pws='path with space'
346 test_expect_success 'stdin test setup' '
347 echo "$pws" >"$pws" &&
348 git add -- "$pws" &&
349 git commit -m "$pws"
352 test_expect_success '-z fails without --stdin' '
353 test_must_fail git update-ref -z $m $m $m 2>err &&
354 grep "usage: git update-ref" err
357 test_expect_success 'stdin works with no input' '
358 >stdin &&
359 git update-ref --stdin <stdin &&
360 git rev-parse --verify -q $m
363 test_expect_success 'stdin fails on empty line' '
364 echo "" >stdin &&
365 test_must_fail git update-ref --stdin <stdin 2>err &&
366 grep "fatal: empty command in input" err
369 test_expect_success 'stdin fails on only whitespace' '
370 echo " " >stdin &&
371 test_must_fail git update-ref --stdin <stdin 2>err &&
372 grep "fatal: whitespace before command: " err
375 test_expect_success 'stdin fails on leading whitespace' '
376 echo " create $a $m" >stdin &&
377 test_must_fail git update-ref --stdin <stdin 2>err &&
378 grep "fatal: whitespace before command: create $a $m" err
381 test_expect_success 'stdin fails on unknown command' '
382 echo "unknown $a" >stdin &&
383 test_must_fail git update-ref --stdin <stdin 2>err &&
384 grep "fatal: unknown command: unknown $a" err
387 test_expect_success 'stdin fails on unbalanced quotes' '
388 echo "create $a \"master" >stdin &&
389 test_must_fail git update-ref --stdin <stdin 2>err &&
390 grep "fatal: badly quoted argument: \\\"master" err
393 test_expect_success 'stdin fails on invalid escape' '
394 echo "create $a \"ma\zter\"" >stdin &&
395 test_must_fail git update-ref --stdin <stdin 2>err &&
396 grep "fatal: badly quoted argument: \\\"ma\\\\zter\\\"" err
399 test_expect_success 'stdin fails on junk after quoted argument' '
400 echo "create \"$a\"master" >stdin &&
401 test_must_fail git update-ref --stdin <stdin 2>err &&
402 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"master" err
405 test_expect_success 'stdin fails create with no ref' '
406 echo "create " >stdin &&
407 test_must_fail git update-ref --stdin <stdin 2>err &&
408 grep "fatal: create: missing <ref>" err
411 test_expect_success 'stdin fails create with bad ref name' '
412 echo "create ~a $m" >stdin &&
413 test_must_fail git update-ref --stdin <stdin 2>err &&
414 grep "fatal: invalid ref format: ~a" err
417 test_expect_success 'stdin fails create with no new value' '
418 echo "create $a" >stdin &&
419 test_must_fail git update-ref --stdin <stdin 2>err &&
420 grep "fatal: create $a: missing <newvalue>" err
423 test_expect_success 'stdin fails create with too many arguments' '
424 echo "create $a $m $m" >stdin &&
425 test_must_fail git update-ref --stdin <stdin 2>err &&
426 grep "fatal: create $a: extra input: $m" err
429 test_expect_success 'stdin fails update with no ref' '
430 echo "update " >stdin &&
431 test_must_fail git update-ref --stdin <stdin 2>err &&
432 grep "fatal: update: missing <ref>" err
435 test_expect_success 'stdin fails update with bad ref name' '
436 echo "update ~a $m" >stdin &&
437 test_must_fail git update-ref --stdin <stdin 2>err &&
438 grep "fatal: invalid ref format: ~a" err
441 test_expect_success 'stdin fails update with no new value' '
442 echo "update $a" >stdin &&
443 test_must_fail git update-ref --stdin <stdin 2>err &&
444 grep "fatal: update $a: missing <newvalue>" err
447 test_expect_success 'stdin fails update with too many arguments' '
448 echo "update $a $m $m $m" >stdin &&
449 test_must_fail git update-ref --stdin <stdin 2>err &&
450 grep "fatal: update $a: extra input: $m" err
453 test_expect_success 'stdin fails delete with no ref' '
454 echo "delete " >stdin &&
455 test_must_fail git update-ref --stdin <stdin 2>err &&
456 grep "fatal: delete: missing <ref>" err
459 test_expect_success 'stdin fails delete with bad ref name' '
460 echo "delete ~a $m" >stdin &&
461 test_must_fail git update-ref --stdin <stdin 2>err &&
462 grep "fatal: invalid ref format: ~a" err
465 test_expect_success 'stdin fails delete with too many arguments' '
466 echo "delete $a $m $m" >stdin &&
467 test_must_fail git update-ref --stdin <stdin 2>err &&
468 grep "fatal: delete $a: extra input: $m" err
471 test_expect_success 'stdin fails verify with too many arguments' '
472 echo "verify $a $m $m" >stdin &&
473 test_must_fail git update-ref --stdin <stdin 2>err &&
474 grep "fatal: verify $a: extra input: $m" err
477 test_expect_success 'stdin fails option with unknown name' '
478 echo "option unknown" >stdin &&
479 test_must_fail git update-ref --stdin <stdin 2>err &&
480 grep "fatal: option unknown: unknown" err
483 test_expect_success 'stdin fails with duplicate refs' '
484 cat >stdin <<-EOF &&
485 create $a $m
486 create $b $m
487 create $a $m
489 test_must_fail git update-ref --stdin <stdin 2>err &&
490 grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
493 test_expect_success 'stdin create ref works' '
494 echo "create $a $m" >stdin &&
495 git update-ref --stdin <stdin &&
496 git rev-parse $m >expect &&
497 git rev-parse $a >actual &&
498 test_cmp expect actual
501 test_expect_success 'stdin succeeds with quoted argument' '
502 git update-ref -d $a &&
503 echo "create $a \"$m\"" >stdin &&
504 git update-ref --stdin <stdin &&
505 git rev-parse $m >expect &&
506 git rev-parse $a >actual &&
507 test_cmp expect actual
510 test_expect_success 'stdin succeeds with escaped character' '
511 git update-ref -d $a &&
512 echo "create $a \"ma\\163ter\"" >stdin &&
513 git update-ref --stdin <stdin &&
514 git rev-parse $m >expect &&
515 git rev-parse $a >actual &&
516 test_cmp expect actual
519 test_expect_success 'stdin update ref creates with zero old value' '
520 echo "update $b $m $Z" >stdin &&
521 git update-ref --stdin <stdin &&
522 git rev-parse $m >expect &&
523 git rev-parse $b >actual &&
524 test_cmp expect actual &&
525 git update-ref -d $b
528 test_expect_success 'stdin update ref creates with empty old value' '
529 echo "update $b $m $E" >stdin &&
530 git update-ref --stdin <stdin &&
531 git rev-parse $m >expect &&
532 git rev-parse $b >actual &&
533 test_cmp expect actual
536 test_expect_success 'stdin create ref works with path with space to blob' '
537 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
538 git update-ref --stdin <stdin &&
539 git rev-parse "$m:$pws" >expect &&
540 git rev-parse refs/blobs/pws >actual &&
541 test_cmp expect actual &&
542 git update-ref -d refs/blobs/pws
545 test_expect_success 'stdin update ref fails with wrong old value' '
546 echo "update $c $m $m~1" >stdin &&
547 test_must_fail git update-ref --stdin <stdin 2>err &&
548 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
549 test_must_fail git rev-parse --verify -q $c
552 test_expect_success 'stdin update ref fails with bad old value' '
553 echo "update $c $m does-not-exist" >stdin &&
554 test_must_fail git update-ref --stdin <stdin 2>err &&
555 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
556 test_must_fail git rev-parse --verify -q $c
559 test_expect_success 'stdin create ref fails with bad new value' '
560 echo "create $c does-not-exist" >stdin &&
561 test_must_fail git update-ref --stdin <stdin 2>err &&
562 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
563 test_must_fail git rev-parse --verify -q $c
566 test_expect_success 'stdin create ref fails with zero new value' '
567 echo "create $c " >stdin &&
568 test_must_fail git update-ref --stdin <stdin 2>err &&
569 grep "fatal: create $c: zero <newvalue>" err &&
570 test_must_fail git rev-parse --verify -q $c
573 test_expect_success 'stdin update ref works with right old value' '
574 echo "update $b $m~1 $m" >stdin &&
575 git update-ref --stdin <stdin &&
576 git rev-parse $m~1 >expect &&
577 git rev-parse $b >actual &&
578 test_cmp expect actual
581 test_expect_success 'stdin delete ref fails with wrong old value' '
582 echo "delete $a $m~1" >stdin &&
583 test_must_fail git update-ref --stdin <stdin 2>err &&
584 grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
585 git rev-parse $m >expect &&
586 git rev-parse $a >actual &&
587 test_cmp expect actual
590 test_expect_success 'stdin delete ref fails with zero old value' '
591 echo "delete $a " >stdin &&
592 test_must_fail git update-ref --stdin <stdin 2>err &&
593 grep "fatal: delete $a: zero <oldvalue>" err &&
594 git rev-parse $m >expect &&
595 git rev-parse $a >actual &&
596 test_cmp expect actual
599 test_expect_success 'stdin update symref works option no-deref' '
600 git symbolic-ref TESTSYMREF $b &&
601 cat >stdin <<-EOF &&
602 option no-deref
603 update TESTSYMREF $a $b
605 git update-ref --stdin <stdin &&
606 git rev-parse TESTSYMREF >expect &&
607 git rev-parse $a >actual &&
608 test_cmp expect actual &&
609 git rev-parse $m~1 >expect &&
610 git rev-parse $b >actual &&
611 test_cmp expect actual
614 test_expect_success 'stdin delete symref works option no-deref' '
615 git symbolic-ref TESTSYMREF $b &&
616 cat >stdin <<-EOF &&
617 option no-deref
618 delete TESTSYMREF $b
620 git update-ref --stdin <stdin &&
621 test_must_fail git rev-parse --verify -q TESTSYMREF &&
622 git rev-parse $m~1 >expect &&
623 git rev-parse $b >actual &&
624 test_cmp expect actual
627 test_expect_success 'stdin delete ref works with right old value' '
628 echo "delete $b $m~1" >stdin &&
629 git update-ref --stdin <stdin &&
630 test_must_fail git rev-parse --verify -q $b
633 test_expect_success 'stdin update/create/verify combination works' '
634 cat >stdin <<-EOF &&
635 update $a $m
636 create $b $m
637 verify $c
639 git update-ref --stdin <stdin &&
640 git rev-parse $m >expect &&
641 git rev-parse $a >actual &&
642 test_cmp expect actual &&
643 git rev-parse $b >actual &&
644 test_cmp expect actual &&
645 test_must_fail git rev-parse --verify -q $c
648 test_expect_success 'stdin update refs works with identity updates' '
649 cat >stdin <<-EOF &&
650 update $a $m $m
651 update $b $m $m
652 update $c $Z $E
654 git update-ref --stdin <stdin &&
655 git rev-parse $m >expect &&
656 git rev-parse $a >actual &&
657 test_cmp expect actual &&
658 git rev-parse $b >actual &&
659 test_cmp expect actual &&
660 test_must_fail git rev-parse --verify -q $c
663 test_expect_success 'stdin update refs fails with wrong old value' '
664 git update-ref $c $m &&
665 cat >stdin <<-EOF &&
666 update $a $m $m
667 update $b $m $m
668 update $c ''
670 test_must_fail git update-ref --stdin <stdin 2>err &&
671 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
672 git rev-parse $m >expect &&
673 git rev-parse $a >actual &&
674 test_cmp expect actual &&
675 git rev-parse $b >actual &&
676 test_cmp expect actual &&
677 git rev-parse $c >actual &&
678 test_cmp expect actual
681 test_expect_success 'stdin delete refs works with packed and loose refs' '
682 git pack-refs --all &&
683 git update-ref $c $m~1 &&
684 cat >stdin <<-EOF &&
685 delete $a $m
686 update $b $Z $m
687 update $c $E $m~1
689 git update-ref --stdin <stdin &&
690 test_must_fail git rev-parse --verify -q $a &&
691 test_must_fail git rev-parse --verify -q $b &&
692 test_must_fail git rev-parse --verify -q $c
695 test_expect_success 'stdin -z works on empty input' '
696 >stdin &&
697 git update-ref -z --stdin <stdin &&
698 git rev-parse --verify -q $m
701 test_expect_success 'stdin -z fails on empty line' '
702 echo "" >stdin &&
703 test_must_fail git update-ref -z --stdin <stdin 2>err &&
704 grep "fatal: whitespace before command: " err
707 test_expect_success 'stdin -z fails on empty command' '
708 printf $F "" >stdin &&
709 test_must_fail git update-ref -z --stdin <stdin 2>err &&
710 grep "fatal: empty command in input" err
713 test_expect_success 'stdin -z fails on only whitespace' '
714 printf $F " " >stdin &&
715 test_must_fail git update-ref -z --stdin <stdin 2>err &&
716 grep "fatal: whitespace before command: " err
719 test_expect_success 'stdin -z fails on leading whitespace' '
720 printf $F " create $a" "$m" >stdin &&
721 test_must_fail git update-ref -z --stdin <stdin 2>err &&
722 grep "fatal: whitespace before command: create $a" err
725 test_expect_success 'stdin -z fails on unknown command' '
726 printf $F "unknown $a" >stdin &&
727 test_must_fail git update-ref -z --stdin <stdin 2>err &&
728 grep "fatal: unknown command: unknown $a" err
731 test_expect_success 'stdin -z fails create with no ref' '
732 printf $F "create " >stdin &&
733 test_must_fail git update-ref -z --stdin <stdin 2>err &&
734 grep "fatal: create: missing <ref>" err
737 test_expect_success 'stdin -z fails create with bad ref name' '
738 printf $F "create ~a " "$m" >stdin &&
739 test_must_fail git update-ref -z --stdin <stdin 2>err &&
740 grep "fatal: invalid ref format: ~a " err
743 test_expect_success 'stdin -z fails create with no new value' '
744 printf $F "create $a" >stdin &&
745 test_must_fail git update-ref -z --stdin <stdin 2>err &&
746 grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
749 test_expect_success 'stdin -z fails create with too many arguments' '
750 printf $F "create $a" "$m" "$m" >stdin &&
751 test_must_fail git update-ref -z --stdin <stdin 2>err &&
752 grep "fatal: unknown command: $m" err
755 test_expect_success 'stdin -z fails update with no ref' '
756 printf $F "update " >stdin &&
757 test_must_fail git update-ref -z --stdin <stdin 2>err &&
758 grep "fatal: update: missing <ref>" err
761 test_expect_success 'stdin -z fails update with too few args' '
762 printf $F "update $a" "$m" >stdin &&
763 test_must_fail git update-ref -z --stdin <stdin 2>err &&
764 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
767 test_expect_success 'stdin -z fails update with bad ref name' '
768 printf $F "update ~a" "$m" "" >stdin &&
769 test_must_fail git update-ref -z --stdin <stdin 2>err &&
770 grep "fatal: invalid ref format: ~a" err
773 test_expect_success 'stdin -z emits warning with empty new value' '
774 git update-ref $a $m &&
775 printf $F "update $a" "" "" >stdin &&
776 git update-ref -z --stdin <stdin 2>err &&
777 grep "warning: update $a: missing <newvalue>, treating as zero" err &&
778 test_must_fail git rev-parse --verify -q $a
781 test_expect_success 'stdin -z fails update with no new value' '
782 printf $F "update $a" >stdin &&
783 test_must_fail git update-ref -z --stdin <stdin 2>err &&
784 grep "fatal: update $a: unexpected end of input when reading <newvalue>" err
787 test_expect_success 'stdin -z fails update with no old value' '
788 printf $F "update $a" "$m" >stdin &&
789 test_must_fail git update-ref -z --stdin <stdin 2>err &&
790 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
793 test_expect_success 'stdin -z fails update with too many arguments' '
794 printf $F "update $a" "$m" "$m" "$m" >stdin &&
795 test_must_fail git update-ref -z --stdin <stdin 2>err &&
796 grep "fatal: unknown command: $m" err
799 test_expect_success 'stdin -z fails delete with no ref' '
800 printf $F "delete " >stdin &&
801 test_must_fail git update-ref -z --stdin <stdin 2>err &&
802 grep "fatal: delete: missing <ref>" err
805 test_expect_success 'stdin -z fails delete with bad ref name' '
806 printf $F "delete ~a" "$m" >stdin &&
807 test_must_fail git update-ref -z --stdin <stdin 2>err &&
808 grep "fatal: invalid ref format: ~a" err
811 test_expect_success 'stdin -z fails delete with no old value' '
812 printf $F "delete $a" >stdin &&
813 test_must_fail git update-ref -z --stdin <stdin 2>err &&
814 grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
817 test_expect_success 'stdin -z fails delete with too many arguments' '
818 printf $F "delete $a" "$m" "$m" >stdin &&
819 test_must_fail git update-ref -z --stdin <stdin 2>err &&
820 grep "fatal: unknown command: $m" err
823 test_expect_success 'stdin -z fails verify with too many arguments' '
824 printf $F "verify $a" "$m" "$m" >stdin &&
825 test_must_fail git update-ref -z --stdin <stdin 2>err &&
826 grep "fatal: unknown command: $m" err
829 test_expect_success 'stdin -z fails verify with no old value' '
830 printf $F "verify $a" >stdin &&
831 test_must_fail git update-ref -z --stdin <stdin 2>err &&
832 grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err
835 test_expect_success 'stdin -z fails option with unknown name' '
836 printf $F "option unknown" >stdin &&
837 test_must_fail git update-ref -z --stdin <stdin 2>err &&
838 grep "fatal: option unknown: unknown" err
841 test_expect_success 'stdin -z fails with duplicate refs' '
842 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
843 test_must_fail git update-ref -z --stdin <stdin 2>err &&
844 grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
847 test_expect_success 'stdin -z create ref works' '
848 printf $F "create $a" "$m" >stdin &&
849 git update-ref -z --stdin <stdin &&
850 git rev-parse $m >expect &&
851 git rev-parse $a >actual &&
852 test_cmp expect actual
855 test_expect_success 'stdin -z update ref creates with zero old value' '
856 printf $F "update $b" "$m" "$Z" >stdin &&
857 git update-ref -z --stdin <stdin &&
858 git rev-parse $m >expect &&
859 git rev-parse $b >actual &&
860 test_cmp expect actual &&
861 git update-ref -d $b
864 test_expect_success 'stdin -z update ref creates with empty old value' '
865 printf $F "update $b" "$m" "" >stdin &&
866 git update-ref -z --stdin <stdin &&
867 git rev-parse $m >expect &&
868 git rev-parse $b >actual &&
869 test_cmp expect actual
872 test_expect_success 'stdin -z create ref works with path with space to blob' '
873 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
874 git update-ref -z --stdin <stdin &&
875 git rev-parse "$m:$pws" >expect &&
876 git rev-parse refs/blobs/pws >actual &&
877 test_cmp expect actual &&
878 git update-ref -d refs/blobs/pws
881 test_expect_success 'stdin -z update ref fails with wrong old value' '
882 printf $F "update $c" "$m" "$m~1" >stdin &&
883 test_must_fail git update-ref -z --stdin <stdin 2>err &&
884 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
885 test_must_fail git rev-parse --verify -q $c
888 test_expect_success 'stdin -z update ref fails with bad old value' '
889 printf $F "update $c" "$m" "does-not-exist" >stdin &&
890 test_must_fail git update-ref -z --stdin <stdin 2>err &&
891 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
892 test_must_fail git rev-parse --verify -q $c
895 test_expect_success 'stdin -z create ref fails when ref exists' '
896 git update-ref $c $m &&
897 git rev-parse "$c" >expect &&
898 printf $F "create $c" "$m~1" >stdin &&
899 test_must_fail git update-ref -z --stdin <stdin 2>err &&
900 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
901 git rev-parse "$c" >actual &&
902 test_cmp expect actual
905 test_expect_success 'stdin -z create ref fails with bad new value' '
906 git update-ref -d "$c" &&
907 printf $F "create $c" "does-not-exist" >stdin &&
908 test_must_fail git update-ref -z --stdin <stdin 2>err &&
909 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
910 test_must_fail git rev-parse --verify -q $c
913 test_expect_success 'stdin -z create ref fails with empty new value' '
914 printf $F "create $c" "" >stdin &&
915 test_must_fail git update-ref -z --stdin <stdin 2>err &&
916 grep "fatal: create $c: missing <newvalue>" err &&
917 test_must_fail git rev-parse --verify -q $c
920 test_expect_success 'stdin -z update ref works with right old value' '
921 printf $F "update $b" "$m~1" "$m" >stdin &&
922 git update-ref -z --stdin <stdin &&
923 git rev-parse $m~1 >expect &&
924 git rev-parse $b >actual &&
925 test_cmp expect actual
928 test_expect_success 'stdin -z delete ref fails with wrong old value' '
929 printf $F "delete $a" "$m~1" >stdin &&
930 test_must_fail git update-ref -z --stdin <stdin 2>err &&
931 grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
932 git rev-parse $m >expect &&
933 git rev-parse $a >actual &&
934 test_cmp expect actual
937 test_expect_success 'stdin -z delete ref fails with zero old value' '
938 printf $F "delete $a" "$Z" >stdin &&
939 test_must_fail git update-ref -z --stdin <stdin 2>err &&
940 grep "fatal: delete $a: zero <oldvalue>" err &&
941 git rev-parse $m >expect &&
942 git rev-parse $a >actual &&
943 test_cmp expect actual
946 test_expect_success 'stdin -z update symref works option no-deref' '
947 git symbolic-ref TESTSYMREF $b &&
948 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
949 git update-ref -z --stdin <stdin &&
950 git rev-parse TESTSYMREF >expect &&
951 git rev-parse $a >actual &&
952 test_cmp expect actual &&
953 git rev-parse $m~1 >expect &&
954 git rev-parse $b >actual &&
955 test_cmp expect actual
958 test_expect_success 'stdin -z delete symref works option no-deref' '
959 git symbolic-ref TESTSYMREF $b &&
960 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
961 git update-ref -z --stdin <stdin &&
962 test_must_fail git rev-parse --verify -q TESTSYMREF &&
963 git rev-parse $m~1 >expect &&
964 git rev-parse $b >actual &&
965 test_cmp expect actual
968 test_expect_success 'stdin -z delete ref works with right old value' '
969 printf $F "delete $b" "$m~1" >stdin &&
970 git update-ref -z --stdin <stdin &&
971 test_must_fail git rev-parse --verify -q $b
974 test_expect_success 'stdin -z update/create/verify combination works' '
975 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
976 git update-ref -z --stdin <stdin &&
977 git rev-parse $m >expect &&
978 git rev-parse $a >actual &&
979 test_cmp expect actual &&
980 git rev-parse $b >actual &&
981 test_cmp expect actual &&
982 test_must_fail git rev-parse --verify -q $c
985 test_expect_success 'stdin -z update refs works with identity updates' '
986 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
987 git update-ref -z --stdin <stdin &&
988 git rev-parse $m >expect &&
989 git rev-parse $a >actual &&
990 test_cmp expect actual &&
991 git rev-parse $b >actual &&
992 test_cmp expect actual &&
993 test_must_fail git rev-parse --verify -q $c
996 test_expect_success 'stdin -z update refs fails with wrong old value' '
997 git update-ref $c $m &&
998 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
999 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1000 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
1001 git rev-parse $m >expect &&
1002 git rev-parse $a >actual &&
1003 test_cmp expect actual &&
1004 git rev-parse $b >actual &&
1005 test_cmp expect actual &&
1006 git rev-parse $c >actual &&
1007 test_cmp expect actual
1010 test_expect_success 'stdin -z delete refs works with packed and loose refs' '
1011 git pack-refs --all &&
1012 git update-ref $c $m~1 &&
1013 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
1014 git update-ref -z --stdin <stdin &&
1015 test_must_fail git rev-parse --verify -q $a &&
1016 test_must_fail git rev-parse --verify -q $b &&
1017 test_must_fail git rev-parse --verify -q $c
1020 test_done