3 # Copyright (c) 2006 Shawn Pearce
6 test_description
='Test git update-ref and basic ref logging'
16 create_test_commits
()
19 for name
in A B C D E F
22 T
=$(git write-tree) &&
23 sha1
=$(echo $name | git commit-tree $T) &&
28 test_expect_success setup
'
29 git checkout --orphan main &&
30 create_test_commits "" &&
33 git init --bare -b main &&
34 create_test_commits "bare" &&
38 test_expect_success
"create $m" '
39 git update-ref $m $A &&
40 test $A = $(git show-ref -s --verify $m)
42 test_expect_success
"create $m with oldvalue verification" '
43 git update-ref $m $B $A &&
44 test $B = $(git show-ref -s --verify $m)
46 test_expect_success
"fail to delete $m with stale ref" '
47 test_must_fail git update-ref -d $m $A &&
48 test $B = "$(git show-ref -s --verify $m)"
50 test_expect_success
"delete $m" '
51 test_when_finished "git update-ref -d $m" &&
52 git update-ref -d $m $B &&
53 test_must_fail git show-ref --verify -q $m
56 test_expect_success
"delete $m without oldvalue verification" '
57 test_when_finished "git update-ref -d $m" &&
58 git update-ref $m $A &&
59 test $A = $(git show-ref -s --verify $m) &&
60 git update-ref -d $m &&
61 test_must_fail git show-ref --verify -q $m
64 test_expect_success
"fail to create $n due to file/directory conflict" '
65 test_when_finished "git update-ref -d refs/heads/gu" &&
66 git update-ref refs/heads/gu $A &&
67 test_must_fail git update-ref refs/heads/gu/fixes $A
70 test_expect_success
"create $m (by HEAD)" '
71 git update-ref HEAD $A &&
72 test $A = $(git show-ref -s --verify $m)
74 test_expect_success
"create $m (by HEAD) with oldvalue verification" '
75 git update-ref HEAD $B $A &&
76 test $B = $(git show-ref -s --verify $m)
78 test_expect_success
"fail to delete $m (by HEAD) with stale ref" '
79 test_must_fail git update-ref -d HEAD $A &&
80 test $B = $(git show-ref -s --verify $m)
82 test_expect_success
"delete $m (by HEAD)" '
83 test_when_finished "git update-ref -d $m" &&
84 git update-ref -d HEAD $B &&
85 test_must_fail git show-ref --verify -q $m
88 test_expect_success
"deleting current branch adds message to HEAD's log" '
89 test_when_finished "git update-ref -d $m" &&
90 git update-ref $m $A &&
91 git symbolic-ref HEAD $m &&
92 git update-ref -m delete-$m -d $m &&
93 test_must_fail git show-ref --verify -q $m &&
94 test-tool ref-store main for-each-reflog-ent HEAD >actual &&
95 grep "delete-$m$" actual
98 test_expect_success
"deleting by HEAD adds message to HEAD's log" '
99 test_when_finished "git update-ref -d $m" &&
100 git update-ref $m $A &&
101 git symbolic-ref HEAD $m &&
102 git update-ref -m delete-by-head -d HEAD &&
103 test_must_fail git show-ref --verify -q $m &&
104 test-tool ref-store main for-each-reflog-ent HEAD >actual &&
105 grep "delete-by-head$" actual
108 test_expect_success
'update-ref does not create reflogs by default' '
109 test_when_finished "git update-ref -d $outside" &&
110 git update-ref $outside $A &&
111 git rev-parse $A >expect &&
112 git rev-parse $outside >actual &&
113 test_cmp expect actual &&
114 test_must_fail git reflog exists $outside
117 test_expect_success
'update-ref creates reflogs with --create-reflog' '
118 test_when_finished "git update-ref -d $outside" &&
119 git update-ref --create-reflog $outside $A &&
120 git rev-parse $A >expect &&
121 git rev-parse $outside >actual &&
122 test_cmp expect actual &&
123 git reflog exists $outside
126 test_expect_success
'creates no reflog in bare repository' '
127 git -C $bare update-ref $m $bareA &&
128 git -C $bare rev-parse $bareA >expect &&
129 git -C $bare rev-parse $m >actual &&
130 test_cmp expect actual &&
131 test_must_fail git -C $bare reflog exists $m
134 test_expect_success
'core.logAllRefUpdates=true creates reflog in bare repository' '
135 test_when_finished "git -C $bare config --unset core.logAllRefUpdates && \
136 test-tool ref-store main delete-reflog $m" &&
137 git -C $bare config core.logAllRefUpdates true &&
138 git -C $bare update-ref $m $bareB &&
139 git -C $bare rev-parse $bareB >expect &&
140 git -C $bare rev-parse $m >actual &&
141 test_cmp expect actual &&
142 git -C $bare reflog exists $m
145 test_expect_success
'core.logAllRefUpdates=true does not create reflog by default' '
146 test_config core.logAllRefUpdates true &&
147 test_when_finished "git update-ref -d $outside" &&
148 git update-ref $outside $A &&
149 git rev-parse $A >expect &&
150 git rev-parse $outside >actual &&
151 test_cmp expect actual &&
152 test_must_fail git reflog exists $outside
155 test_expect_success
'core.logAllRefUpdates=always creates reflog by default' '
156 test_config core.logAllRefUpdates always &&
157 test_when_finished "git update-ref -d $outside" &&
158 git update-ref $outside $A &&
159 git rev-parse $A >expect &&
160 git rev-parse $outside >actual &&
161 test_cmp expect actual &&
162 git reflog exists $outside
165 test_expect_success
'core.logAllRefUpdates=always creates reflog for ORIG_HEAD' '
166 test_config core.logAllRefUpdates always &&
167 git update-ref ORIG_HEAD $A &&
168 git reflog exists ORIG_HEAD
171 test_expect_success
'--no-create-reflog overrides core.logAllRefUpdates=always' '
172 test_config core.logAllRefUpdates true &&
173 test_when_finished "git update-ref -d $outside" &&
174 git update-ref --no-create-reflog $outside $A &&
175 git rev-parse $A >expect &&
176 git rev-parse $outside >actual &&
177 test_cmp expect actual &&
178 test_must_fail git reflog exists $outside
181 test_expect_success
"create $m (by HEAD)" '
182 git update-ref HEAD $A &&
183 test $A = $(git show-ref -s --verify $m)
185 test_expect_success
'pack refs' '
188 test_expect_success
"move $m (by HEAD)" '
189 git update-ref HEAD $B $A &&
190 test $B = $(git show-ref -s --verify $m)
192 test_expect_success
"delete $m (by HEAD) should remove both packed and loose $m" '
193 test_when_finished "git update-ref -d $m" &&
194 git update-ref -d HEAD $B &&
195 ! grep "$m" .git/packed-refs &&
196 test_must_fail git show-ref --verify -q $m
199 test_expect_success
'delete symref without dereference' '
200 test_when_finished "git update-ref -d $m" &&
204 git symbolic-ref SYMREF $m &&
205 git update-ref --no-deref -d SYMREF &&
206 git show-ref --verify -q $m &&
207 test_must_fail git show-ref --verify -q SYMREF &&
208 test_must_fail git symbolic-ref SYMREF
211 test_expect_success
'delete symref without dereference when the referred ref is packed' '
212 test_when_finished "git update-ref -d $m" &&
216 git symbolic-ref SYMREF $m &&
217 git pack-refs --all &&
218 git update-ref --no-deref -d SYMREF &&
219 git show-ref --verify -q $m &&
220 test_must_fail git show-ref --verify -q SYMREF &&
221 test_must_fail git symbolic-ref SYMREF
224 test_expect_success
'update-ref -d is not confused by self-reference' '
225 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" &&
226 git symbolic-ref refs/heads/self refs/heads/self &&
227 git symbolic-ref --no-recurse refs/heads/self &&
228 test_must_fail git update-ref -d refs/heads/self &&
229 git symbolic-ref --no-recurse refs/heads/self
232 test_expect_success
'update-ref --no-deref -d can delete self-reference' '
233 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" &&
234 git symbolic-ref refs/heads/self refs/heads/self &&
235 git symbolic-ref --no-recurse refs/heads/self &&
236 git update-ref --no-deref -d refs/heads/self &&
237 test_must_fail git show-ref --verify -q refs/heads/self
240 test_expect_success REFFILES
'update-ref --no-deref -d can delete reference to bad ref' '
241 >.git/refs/heads/bad &&
242 test_when_finished "rm -f .git/refs/heads/bad" &&
243 git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
244 test_when_finished "git update-ref -d refs/heads/ref-to-bad" &&
245 git symbolic-ref --no-recurse refs/heads/ref-to-bad &&
246 git update-ref --no-deref -d refs/heads/ref-to-bad &&
247 test_must_fail git show-ref --verify -q refs/heads/ref-to-bad
250 test_expect_success
'(not) create HEAD with old sha1' '
251 test_must_fail git update-ref HEAD $A $B
253 test_expect_success
"(not) prior created .git/$m" '
254 test_when_finished "git update-ref -d $m" &&
255 test_must_fail git show-ref --verify -q $m
258 test_expect_success
'create HEAD' '
259 git update-ref HEAD $A
261 test_expect_success
'(not) change HEAD with wrong SHA1' '
262 test_must_fail git update-ref HEAD $B $Z
264 test_expect_success
"(not) changed .git/$m" '
265 test_when_finished "git update-ref -d $m" &&
266 ! test $B = $(git show-ref -s --verify $m)
269 test_expect_success
"clean up reflog" '
270 test-tool ref-store main delete-reflog $m
273 test_expect_success
"create $m (logged by touch)" '
274 test_config core.logAllRefUpdates false &&
275 GIT_COMMITTER_DATE="2005-05-26 23:30" \
276 git update-ref --create-reflog HEAD $A -m "Initial Creation" &&
277 test $A = $(git show-ref -s --verify $m)
279 test_expect_success
"update $m (logged by touch)" '
280 test_config core.logAllRefUpdates false &&
281 GIT_COMMITTER_DATE="2005-05-26 23:31" \
282 git update-ref HEAD $B $A -m "Switch" &&
283 test $B = $(git show-ref -s --verify $m)
285 test_expect_success
"set $m (logged by touch)" '
286 test_config core.logAllRefUpdates false &&
287 GIT_COMMITTER_DATE="2005-05-26 23:41" \
288 git update-ref HEAD $A &&
289 test $A = $(git show-ref -s --verify $m)
293 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
294 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
295 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
297 test_expect_success
"verifying $m's log (logged by touch)" '
298 test_when_finished "git update-ref -d $m && git reflog expire --expire=all --all && rm -rf actual expect" &&
299 test-tool ref-store main for-each-reflog-ent $m >actual &&
300 test_cmp actual expect
303 test_expect_success
"create $m (logged by config)" '
304 test_config core.logAllRefUpdates true &&
305 GIT_COMMITTER_DATE="2005-05-26 23:32" \
306 git update-ref HEAD $A -m "Initial Creation" &&
307 test $A = $(git show-ref -s --verify $m)
309 test_expect_success
"update $m (logged by config)" '
310 test_config core.logAllRefUpdates true &&
311 GIT_COMMITTER_DATE="2005-05-26 23:33" \
312 git update-ref HEAD $B $A -m "Switch" &&
313 test $B = $(git show-ref -s --verify $m)
315 test_expect_success
"set $m (logged by config)" '
316 test_config core.logAllRefUpdates true &&
317 GIT_COMMITTER_DATE="2005-05-26 23:43" \
318 git update-ref HEAD $A &&
319 test $A = $(git show-ref -s --verify $m)
323 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
324 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
325 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
327 test_expect_success
"verifying $m's log (logged by config)" '
328 test_when_finished "git update-ref -d $m && git reflog expire --expire=all --all && rm -rf actual expect" &&
329 test-tool ref-store main for-each-reflog-ent $m >actual &&
330 test_cmp actual expect
333 test_expect_success
'set up for querying the reflog' '
334 git update-ref -d $m &&
335 test-tool ref-store main delete-reflog $m &&
337 GIT_COMMITTER_DATE="1117150320 -0500" git update-ref $m $C &&
338 GIT_COMMITTER_DATE="1117150350 -0500" git update-ref $m $A &&
339 GIT_COMMITTER_DATE="1117150380 -0500" git update-ref $m $B &&
340 GIT_COMMITTER_DATE="1117150680 -0500" git update-ref $m $F &&
341 GIT_COMMITTER_DATE="1117150980 -0500" git update-ref $m $E &&
342 git update-ref $m $D &&
343 # Delete the last reflog entry so that the tip of m and the reflog for
345 git reflog delete $m@{0} &&
347 cat >expect <<-EOF &&
348 $Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
349 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
350 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
351 $B $F $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
352 $F $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
354 test-tool ref-store main for-each-reflog-ent $m >actual &&
355 test_cmp expect actual
358 ed
="Thu, 26 May 2005 18:32:00 -0500"
359 gd
="Thu, 26 May 2005 18:33:00 -0500"
360 ld
="Thu, 26 May 2005 18:43:00 -0500"
361 test_expect_success
'Query "main@{May 25 2005}" (before history)' '
362 test_when_finished "rm -f o e" &&
363 git rev-parse --verify "main@{May 25 2005}" >o 2>e &&
366 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
369 test_expect_success
'Query main@{2005-05-25} (before history)' '
370 test_when_finished "rm -f o e" &&
371 git rev-parse --verify main@{2005-05-25} >o 2>e &&
374 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
377 test_expect_success
'Query "main@{May 26 2005 23:31:59}" (1 second before history)' '
378 test_when_finished "rm -f o e" &&
379 git rev-parse --verify "main@{May 26 2005 23:31:59}" >o 2>e &&
382 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
385 test_expect_success
'Query "main@{May 26 2005 23:32:00}" (exactly history start)' '
386 test_when_finished "rm -f o e" &&
387 git rev-parse --verify "main@{May 26 2005 23:32:00}" >o 2>e &&
392 test_expect_success
'Query "main@{May 26 2005 23:32:30}" (first non-creation change)' '
393 test_when_finished "rm -f o e" &&
394 git rev-parse --verify "main@{May 26 2005 23:32:30}" >o 2>e &&
399 test_expect_success
'Query "main@{2005-05-26 23:33:01}" (middle of history with gap)' '
400 test_when_finished "rm -f o e" &&
401 git rev-parse --verify "main@{2005-05-26 23:33:01}" >o 2>e &&
405 test_expect_success
'Query "main@{2005-05-26 23:38:00}" (middle of history)' '
406 test_when_finished "rm -f o e" &&
407 git rev-parse --verify "main@{2005-05-26 23:38:00}" >o 2>e &&
412 test_expect_success
'Query "main@{2005-05-26 23:43:00}" (exact end of history)' '
413 test_when_finished "rm -f o e" &&
414 git rev-parse --verify "main@{2005-05-26 23:43:00}" >o 2>e &&
419 test_expect_success
'Query "main@{2005-05-28}" (past end of history)' '
420 test_when_finished "rm -f o e" &&
421 git rev-parse --verify "main@{2005-05-28}" >o 2>e &&
424 test_grep -F "warning: log for ref $m unexpectedly ended on $ld" e
430 test_expect_success
'query reflog with gap' '
431 test_when_finished "git update-ref -d $m" &&
433 GIT_COMMITTER_DATE="1117150320 -0500" git update-ref $m $A &&
434 GIT_COMMITTER_DATE="1117150380 -0500" git update-ref $m $B &&
435 GIT_COMMITTER_DATE="1117150480 -0500" git update-ref $m $C &&
436 GIT_COMMITTER_DATE="1117150580 -0500" git update-ref $m $D &&
437 GIT_COMMITTER_DATE="1117150680 -0500" git update-ref $m $F &&
438 git reflog delete $m@{2} &&
440 git rev-parse --verify "main@{2005-05-26 23:33:01}" >actual 2>stderr &&
442 test_cmp expect actual &&
443 test_grep -F "warning: log for ref $m has gap after $gd" stderr
446 test_expect_success
'creating initial files' '
447 test_when_finished rm -f M &&
450 GIT_AUTHOR_DATE="2005-05-26 23:30" \
451 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
452 h_TEST=$(git rev-parse --verify HEAD) &&
453 echo The other day this did not work. >M &&
454 echo And then Bob told me how to fix it. >>M &&
456 GIT_AUTHOR_DATE="2005-05-26 23:41" \
457 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
458 h_OTHER=$(git rev-parse --verify HEAD) &&
459 GIT_AUTHOR_DATE="2005-05-26 23:44" \
460 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
461 h_FIXED=$(git rev-parse --verify HEAD) &&
462 echo Merged initial commit and a later commit. >M &&
463 echo $h_TEST >.git/MERGE_HEAD &&
464 GIT_AUTHOR_DATE="2005-05-26 23:45" \
465 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
466 h_MERGED=$(git rev-parse --verify HEAD)
470 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
471 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
472 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
473 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
475 test_expect_success
'git commit logged updates' '
476 test-tool ref-store main for-each-reflog-ent $m >actual &&
477 test_cmp expect actual
479 unset h_TEST h_OTHER h_FIXED h_MERGED
481 test_expect_success
'git cat-file blob main:F (expect OTHER)' '
482 test OTHER = $(git cat-file blob main:F)
484 test_expect_success
'git cat-file blob main@{2005-05-26 23:30}:F (expect TEST)' '
485 test TEST = $(git cat-file blob "main@{2005-05-26 23:30}:F")
487 test_expect_success
'git cat-file blob main@{2005-05-26 23:42}:F (expect OTHER)' '
488 test OTHER = $(git cat-file blob "main@{2005-05-26 23:42}:F")
491 # Test adding and deleting pseudorefs
493 test_expect_success
'given old value for missing pseudoref, do not create' '
494 test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
495 test_must_fail git rev-parse PSEUDOREF &&
496 test_grep "unable to resolve reference" err
499 test_expect_success
'create pseudoref' '
500 git update-ref PSEUDOREF $A &&
501 test $A = $(git show-ref -s --verify PSEUDOREF)
504 test_expect_success
'overwrite pseudoref with no old value given' '
505 git update-ref PSEUDOREF $B &&
506 test $B = $(git show-ref -s --verify PSEUDOREF)
509 test_expect_success
'overwrite pseudoref with correct old value' '
510 git update-ref PSEUDOREF $C $B &&
511 test $C = $(git show-ref -s --verify PSEUDOREF)
514 test_expect_success
'do not overwrite pseudoref with wrong old value' '
515 test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
516 test $C = $(git show-ref -s --verify PSEUDOREF) &&
517 test_grep "cannot lock ref.*expected" err
520 test_expect_success
'delete pseudoref' '
521 git update-ref -d PSEUDOREF &&
522 test_must_fail git show-ref -s --verify PSEUDOREF
525 test_expect_success
'do not delete pseudoref with wrong old value' '
526 git update-ref PSEUDOREF $A &&
527 test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
528 test $A = $(git show-ref -s --verify PSEUDOREF) &&
529 test_grep "cannot lock ref.*expected" err
532 test_expect_success
'delete pseudoref with correct old value' '
533 git update-ref -d PSEUDOREF $A &&
534 test_must_fail git show-ref -s --verify PSEUDOREF
537 test_expect_success
'create pseudoref with old OID zero' '
538 git update-ref PSEUDOREF $A $Z &&
539 test $A = $(git show-ref -s --verify PSEUDOREF)
542 test_expect_success
'do not overwrite pseudoref with old OID zero' '
543 test_when_finished git update-ref -d PSEUDOREF &&
544 test_must_fail git update-ref PSEUDOREF $B $Z 2>err &&
545 test $A = $(git show-ref -s --verify PSEUDOREF) &&
546 test_grep "already exists" err
556 pws
='path with space'
558 test_expect_success
'stdin test setup' '
559 echo "$pws" >"$pws" &&
564 test_expect_success
'-z fails without --stdin' '
565 test_must_fail git update-ref -z $m $m $m 2>err &&
566 test_grep "usage: git update-ref" err
569 test_expect_success
'stdin works with no input' '
571 git update-ref --stdin <stdin &&
572 git rev-parse --verify -q $m
575 test_expect_success
'stdin fails on empty line' '
577 test_must_fail git update-ref --stdin <stdin 2>err &&
578 grep "fatal: empty command in input" err
581 test_expect_success
'stdin fails on only whitespace' '
583 test_must_fail git update-ref --stdin <stdin 2>err &&
584 grep "fatal: whitespace before command: " err
587 test_expect_success
'stdin fails on leading whitespace' '
588 echo " create $a $m" >stdin &&
589 test_must_fail git update-ref --stdin <stdin 2>err &&
590 grep "fatal: whitespace before command: create $a $m" err
593 test_expect_success
'stdin fails on unknown command' '
594 echo "unknown $a" >stdin &&
595 test_must_fail git update-ref --stdin <stdin 2>err &&
596 grep "fatal: unknown command: unknown $a" err
599 test_expect_success
'stdin fails on unbalanced quotes' '
600 echo "create $a \"main" >stdin &&
601 test_must_fail git update-ref --stdin <stdin 2>err &&
602 grep "fatal: badly quoted argument: \\\"main" err
605 test_expect_success
'stdin fails on invalid escape' '
606 echo "create $a \"ma\zn\"" >stdin &&
607 test_must_fail git update-ref --stdin <stdin 2>err &&
608 grep "fatal: badly quoted argument: \\\"ma\\\\zn\\\"" err
611 test_expect_success
'stdin fails on junk after quoted argument' '
612 echo "create \"$a\"main" >stdin &&
613 test_must_fail git update-ref --stdin <stdin 2>err &&
614 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"main" err
617 test_expect_success
'stdin fails create with no ref' '
618 echo "create " >stdin &&
619 test_must_fail git update-ref --stdin <stdin 2>err &&
620 grep "fatal: create: missing <ref>" err
623 test_expect_success
'stdin fails create with no new value' '
624 echo "create $a" >stdin &&
625 test_must_fail git update-ref --stdin <stdin 2>err &&
626 grep "fatal: create $a: missing <new-oid>" err
629 test_expect_success
'stdin fails create with too many arguments' '
630 echo "create $a $m $m" >stdin &&
631 test_must_fail git update-ref --stdin <stdin 2>err &&
632 grep "fatal: create $a: extra input: $m" err
635 test_expect_success
'stdin fails update with no ref' '
636 echo "update " >stdin &&
637 test_must_fail git update-ref --stdin <stdin 2>err &&
638 grep "fatal: update: missing <ref>" err
641 test_expect_success
'stdin fails update with no new value' '
642 echo "update $a" >stdin &&
643 test_must_fail git update-ref --stdin <stdin 2>err &&
644 grep "fatal: update $a: missing <new-oid>" err
647 test_expect_success
'stdin fails update with too many arguments' '
648 echo "update $a $m $m $m" >stdin &&
649 test_must_fail git update-ref --stdin <stdin 2>err &&
650 grep "fatal: update $a: extra input: $m" err
653 test_expect_success
'stdin fails delete with no ref' '
654 echo "delete " >stdin &&
655 test_must_fail git update-ref --stdin <stdin 2>err &&
656 grep "fatal: delete: missing <ref>" err
659 test_expect_success
'stdin fails delete with too many arguments' '
660 echo "delete $a $m $m" >stdin &&
661 test_must_fail git update-ref --stdin <stdin 2>err &&
662 grep "fatal: delete $a: extra input: $m" err
665 test_expect_success
'stdin fails verify with too many arguments' '
666 echo "verify $a $m $m" >stdin &&
667 test_must_fail git update-ref --stdin <stdin 2>err &&
668 grep "fatal: verify $a: extra input: $m" err
671 test_expect_success
'stdin fails option with unknown name' '
672 echo "option unknown" >stdin &&
673 test_must_fail git update-ref --stdin <stdin 2>err &&
674 grep "fatal: option unknown: unknown" err
677 test_expect_success
'stdin fails with duplicate refs' '
683 test_must_fail git update-ref --stdin <stdin 2>err &&
684 test_grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
687 test_expect_success
'stdin create ref works' '
688 echo "create $a $m" >stdin &&
689 git update-ref --stdin <stdin &&
690 git rev-parse $m >expect &&
691 git rev-parse $a >actual &&
692 test_cmp expect actual
695 test_expect_success
'stdin does not create reflogs by default' '
696 test_when_finished "git update-ref -d $outside" &&
697 echo "create $outside $m" >stdin &&
698 git update-ref --stdin <stdin &&
699 git rev-parse $m >expect &&
700 git rev-parse $outside >actual &&
701 test_cmp expect actual &&
702 test_must_fail git reflog exists $outside
705 test_expect_success
'stdin creates reflogs with --create-reflog' '
706 test_when_finished "git update-ref -d $outside" &&
707 echo "create $outside $m" >stdin &&
708 git update-ref --create-reflog --stdin <stdin &&
709 git rev-parse $m >expect &&
710 git rev-parse $outside >actual &&
711 test_cmp expect actual &&
712 git reflog exists $outside
715 test_expect_success
'stdin succeeds with quoted argument' '
716 git update-ref -d $a &&
717 echo "create $a \"$m\"" >stdin &&
718 git update-ref --stdin <stdin &&
719 git rev-parse $m >expect &&
720 git rev-parse $a >actual &&
721 test_cmp expect actual
724 test_expect_success
'stdin succeeds with escaped character' '
725 git update-ref -d $a &&
726 echo "create $a \"ma\\151n\"" >stdin &&
727 git update-ref --stdin <stdin &&
728 git rev-parse $m >expect &&
729 git rev-parse $a >actual &&
730 test_cmp expect actual
733 test_expect_success
'stdin update ref creates with zero old value' '
734 echo "update $b $m $Z" >stdin &&
735 git update-ref --stdin <stdin &&
736 git rev-parse $m >expect &&
737 git rev-parse $b >actual &&
738 test_cmp expect actual &&
742 test_expect_success
'stdin update ref creates with empty old value' '
743 echo "update $b $m $E" >stdin &&
744 git update-ref --stdin <stdin &&
745 git rev-parse $m >expect &&
746 git rev-parse $b >actual &&
747 test_cmp expect actual
750 test_expect_success
'stdin create ref works with path with space to blob' '
751 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
752 git update-ref --stdin <stdin &&
753 git rev-parse "$m:$pws" >expect &&
754 git rev-parse refs/blobs/pws >actual &&
755 test_cmp expect actual &&
756 git update-ref -d refs/blobs/pws
759 test_expect_success
'stdin update ref fails with wrong old value' '
760 echo "update $c $m $m~1" >stdin &&
761 test_must_fail git update-ref --stdin <stdin 2>err &&
762 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
763 test_must_fail git rev-parse --verify -q $c
766 test_expect_success
'stdin update ref fails with bad old value' '
767 echo "update $c $m does-not-exist" >stdin &&
768 test_must_fail git update-ref --stdin <stdin 2>err &&
769 grep "fatal: update $c: invalid <old-oid>: does-not-exist" err &&
770 test_must_fail git rev-parse --verify -q $c
773 test_expect_success
'stdin create ref fails with bad new value' '
774 echo "create $c does-not-exist" >stdin &&
775 test_must_fail git update-ref --stdin <stdin 2>err &&
776 grep "fatal: create $c: invalid <new-oid>: does-not-exist" err &&
777 test_must_fail git rev-parse --verify -q $c
780 test_expect_success
'stdin create ref fails with zero new value' '
781 echo "create $c " >stdin &&
782 test_must_fail git update-ref --stdin <stdin 2>err &&
783 grep "fatal: create $c: zero <new-oid>" err &&
784 test_must_fail git rev-parse --verify -q $c
787 test_expect_success
'stdin update ref works with right old value' '
788 echo "update $b $m~1 $m" >stdin &&
789 git update-ref --stdin <stdin &&
790 git rev-parse $m~1 >expect &&
791 git rev-parse $b >actual &&
792 test_cmp expect actual
795 test_expect_success
'stdin delete ref fails with wrong old value' '
796 echo "delete $a $m~1" >stdin &&
797 test_must_fail git update-ref --stdin <stdin 2>err &&
798 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
799 git rev-parse $m >expect &&
800 git rev-parse $a >actual &&
801 test_cmp expect actual
804 test_expect_success
'stdin delete ref fails with zero old value' '
805 echo "delete $a " >stdin &&
806 test_must_fail git update-ref --stdin <stdin 2>err &&
807 grep "fatal: delete $a: zero <old-oid>" err &&
808 git rev-parse $m >expect &&
809 git rev-parse $a >actual &&
810 test_cmp expect actual
813 test_expect_success
'stdin update symref works option no-deref' '
814 git symbolic-ref TESTSYMREF $b &&
817 update TESTSYMREF $a $b
819 git update-ref --stdin <stdin &&
820 git rev-parse TESTSYMREF >expect &&
821 git rev-parse $a >actual &&
822 test_cmp expect actual &&
823 git rev-parse $m~1 >expect &&
824 git rev-parse $b >actual &&
825 test_cmp expect actual
828 test_expect_success
'stdin delete symref works option no-deref' '
829 git symbolic-ref TESTSYMREF $b &&
834 git update-ref --stdin <stdin &&
835 test_must_fail git rev-parse --verify -q TESTSYMREF &&
836 git rev-parse $m~1 >expect &&
837 git rev-parse $b >actual &&
838 test_cmp expect actual
841 test_expect_success
'stdin update symref works flag --no-deref' '
842 git symbolic-ref TESTSYMREFONE $b &&
843 git symbolic-ref TESTSYMREFTWO $b &&
845 update TESTSYMREFONE $a $b
846 update TESTSYMREFTWO $a $b
848 git update-ref --no-deref --stdin <stdin &&
849 git rev-parse TESTSYMREFONE TESTSYMREFTWO >expect &&
850 git rev-parse $a $a >actual &&
851 test_cmp expect actual &&
852 git rev-parse $m~1 >expect &&
853 git rev-parse $b >actual &&
854 test_cmp expect actual
857 test_expect_success
'stdin delete symref works flag --no-deref' '
858 git symbolic-ref TESTSYMREFONE $b &&
859 git symbolic-ref TESTSYMREFTWO $b &&
861 delete TESTSYMREFONE $b
862 delete TESTSYMREFTWO $b
864 git update-ref --no-deref --stdin <stdin &&
865 test_must_fail git rev-parse --verify -q TESTSYMREFONE &&
866 test_must_fail git rev-parse --verify -q TESTSYMREFTWO &&
867 git rev-parse $m~1 >expect &&
868 git rev-parse $b >actual &&
869 test_cmp expect actual
872 test_expect_success
'stdin delete ref works with right old value' '
873 echo "delete $b $m~1" >stdin &&
874 git update-ref --stdin <stdin &&
875 test_must_fail git rev-parse --verify -q $b
878 test_expect_success
'stdin update/create/verify combination works' '
884 git update-ref --stdin <stdin &&
885 git rev-parse $m >expect &&
886 git rev-parse $a >actual &&
887 test_cmp expect actual &&
888 git rev-parse $b >actual &&
889 test_cmp expect actual &&
890 test_must_fail git rev-parse --verify -q $c
893 test_expect_success
'stdin verify succeeds for correct value' '
894 test-tool ref-store main for-each-reflog-ent $m >before &&
895 git rev-parse $m >expect &&
896 echo "verify $m $m" >stdin &&
897 git update-ref --stdin <stdin &&
898 git rev-parse $m >actual &&
899 test_cmp expect actual &&
900 test-tool ref-store main for-each-reflog-ent $m >after &&
901 test_cmp before after
904 test_expect_success
'stdin verify succeeds for missing reference' '
905 test-tool ref-store main for-each-reflog-ent $m >before &&
906 echo "verify refs/heads/missing $Z" >stdin &&
907 git update-ref --stdin <stdin &&
908 test_must_fail git rev-parse --verify -q refs/heads/missing &&
909 test-tool ref-store main for-each-reflog-ent $m >after &&
910 test_cmp before after
913 test_expect_success
'stdin verify treats no value as missing' '
914 echo "verify refs/heads/missing" >stdin &&
915 git update-ref --stdin <stdin &&
916 test_must_fail git rev-parse --verify -q refs/heads/missing
919 test_expect_success
'stdin verify fails for wrong value' '
920 git rev-parse $m >expect &&
921 echo "verify $m $m~1" >stdin &&
922 test_must_fail git update-ref --stdin <stdin &&
923 git rev-parse $m >actual &&
924 test_cmp expect actual
927 test_expect_success
'stdin verify fails for mistaken null value' '
928 git rev-parse $m >expect &&
929 echo "verify $m $Z" >stdin &&
930 test_must_fail git update-ref --stdin <stdin &&
931 git rev-parse $m >actual &&
932 test_cmp expect actual
935 test_expect_success
'stdin verify fails for mistaken empty value' '
936 M=$(git rev-parse $m) &&
937 test_when_finished "git update-ref $m $M" &&
938 git rev-parse $m >expect &&
939 echo "verify $m" >stdin &&
940 test_must_fail git update-ref --stdin <stdin &&
941 git rev-parse $m >actual &&
942 test_cmp expect actual
945 test_expect_success
'stdin update refs works with identity updates' '
951 git update-ref --stdin <stdin &&
952 git rev-parse $m >expect &&
953 git rev-parse $a >actual &&
954 test_cmp expect actual &&
955 git rev-parse $b >actual &&
956 test_cmp expect actual &&
957 test_must_fail git rev-parse --verify -q $c
960 test_expect_success
'stdin update refs fails with wrong old value' '
961 git update-ref $c $m &&
967 test_must_fail git update-ref --stdin <stdin 2>err &&
968 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
969 git rev-parse $m >expect &&
970 git rev-parse $a >actual &&
971 test_cmp expect actual &&
972 git rev-parse $b >actual &&
973 test_cmp expect actual &&
974 git rev-parse $c >actual &&
975 test_cmp expect actual
978 test_expect_success
'stdin delete refs works with packed and loose refs' '
979 git pack-refs --all &&
980 git update-ref $c $m~1 &&
986 git update-ref --stdin <stdin &&
987 test_must_fail git rev-parse --verify -q $a &&
988 test_must_fail git rev-parse --verify -q $b &&
989 test_must_fail git rev-parse --verify -q $c
992 test_expect_success
'stdin -z works on empty input' '
994 git update-ref -z --stdin <stdin &&
995 git rev-parse --verify -q $m
998 test_expect_success
'stdin -z fails on empty line' '
1000 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1001 grep "fatal: whitespace before command: " err
1004 test_expect_success
'stdin -z fails on empty command' '
1005 printf $F "" >stdin &&
1006 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1007 grep "fatal: empty command in input" err
1010 test_expect_success
'stdin -z fails on only whitespace' '
1011 printf $F " " >stdin &&
1012 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1013 grep "fatal: whitespace before command: " err
1016 test_expect_success
'stdin -z fails on leading whitespace' '
1017 printf $F " create $a" "$m" >stdin &&
1018 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1019 grep "fatal: whitespace before command: create $a" err
1022 test_expect_success
'stdin -z fails on unknown command' '
1023 printf $F "unknown $a" >stdin &&
1024 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1025 grep "fatal: unknown command: unknown $a" err
1028 test_expect_success
'stdin -z fails create with no ref' '
1029 printf $F "create " >stdin &&
1030 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1031 grep "fatal: create: missing <ref>" err
1034 test_expect_success
'stdin -z fails create with no new value' '
1035 printf $F "create $a" >stdin &&
1036 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1037 grep "fatal: create $a: unexpected end of input when reading <new-oid>" err
1040 test_expect_success
'stdin -z fails create with too many arguments' '
1041 printf $F "create $a" "$m" "$m" >stdin &&
1042 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1043 grep "fatal: unknown command: $m" err
1046 test_expect_success
'stdin -z fails update with no ref' '
1047 printf $F "update " >stdin &&
1048 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1049 grep "fatal: update: missing <ref>" err
1052 test_expect_success
'stdin -z fails update with too few args' '
1053 printf $F "update $a" "$m" >stdin &&
1054 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1055 grep "fatal: update $a: unexpected end of input when reading <old-oid>" err
1058 test_expect_success
'stdin -z emits warning with empty new value' '
1059 git update-ref $a $m &&
1060 printf $F "update $a" "" "" >stdin &&
1061 git update-ref -z --stdin <stdin 2>err &&
1062 grep "warning: update $a: missing <new-oid>, treating as zero" err &&
1063 test_must_fail git rev-parse --verify -q $a
1066 test_expect_success
'stdin -z fails update with no new value' '
1067 printf $F "update $a" >stdin &&
1068 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1069 grep "fatal: update $a: unexpected end of input when reading <new-oid>" err
1072 test_expect_success
'stdin -z fails update with no old value' '
1073 printf $F "update $a" "$m" >stdin &&
1074 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1075 grep "fatal: update $a: unexpected end of input when reading <old-oid>" err
1078 test_expect_success
'stdin -z fails update with too many arguments' '
1079 printf $F "update $a" "$m" "$m" "$m" >stdin &&
1080 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1081 grep "fatal: unknown command: $m" err
1084 test_expect_success
'stdin -z fails delete with no ref' '
1085 printf $F "delete " >stdin &&
1086 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1087 grep "fatal: delete: missing <ref>" err
1090 test_expect_success
'stdin -z fails delete with no old value' '
1091 printf $F "delete $a" >stdin &&
1092 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1093 grep "fatal: delete $a: unexpected end of input when reading <old-oid>" err
1096 test_expect_success
'stdin -z fails delete with too many arguments' '
1097 printf $F "delete $a" "$m" "$m" >stdin &&
1098 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1099 grep "fatal: unknown command: $m" err
1102 test_expect_success
'stdin -z fails verify with too many arguments' '
1103 printf $F "verify $a" "$m" "$m" >stdin &&
1104 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1105 grep "fatal: unknown command: $m" err
1108 test_expect_success
'stdin -z fails verify with no old value' '
1109 printf $F "verify $a" >stdin &&
1110 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1111 grep "fatal: verify $a: unexpected end of input when reading <old-oid>" err
1114 test_expect_success
'stdin -z fails option with unknown name' '
1115 printf $F "option unknown" >stdin &&
1116 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1117 grep "fatal: option unknown: unknown" err
1120 test_expect_success
'stdin -z fails with duplicate refs' '
1121 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
1122 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1123 test_grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
1126 test_expect_success
'stdin -z create ref works' '
1127 printf $F "create $a" "$m" >stdin &&
1128 git update-ref -z --stdin <stdin &&
1129 git rev-parse $m >expect &&
1130 git rev-parse $a >actual &&
1131 test_cmp expect actual
1134 test_expect_success
'stdin -z update ref creates with zero old value' '
1135 printf $F "update $b" "$m" "$Z" >stdin &&
1136 git update-ref -z --stdin <stdin &&
1137 git rev-parse $m >expect &&
1138 git rev-parse $b >actual &&
1139 test_cmp expect actual &&
1140 git update-ref -d $b
1143 test_expect_success
'stdin -z update ref creates with empty old value' '
1144 printf $F "update $b" "$m" "" >stdin &&
1145 git update-ref -z --stdin <stdin &&
1146 git rev-parse $m >expect &&
1147 git rev-parse $b >actual &&
1148 test_cmp expect actual
1151 test_expect_success
'stdin -z create ref works with path with space to blob' '
1152 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
1153 git update-ref -z --stdin <stdin &&
1154 git rev-parse "$m:$pws" >expect &&
1155 git rev-parse refs/blobs/pws >actual &&
1156 test_cmp expect actual &&
1157 git update-ref -d refs/blobs/pws
1160 test_expect_success
'stdin -z update ref fails with wrong old value' '
1161 printf $F "update $c" "$m" "$m~1" >stdin &&
1162 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1163 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1164 test_must_fail git rev-parse --verify -q $c
1167 test_expect_success
'stdin -z update ref fails with bad old value' '
1168 printf $F "update $c" "$m" "does-not-exist" >stdin &&
1169 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1170 grep "fatal: update $c: invalid <old-oid>: does-not-exist" err &&
1171 test_must_fail git rev-parse --verify -q $c
1174 test_expect_success
'stdin -z create ref fails when ref exists' '
1175 git update-ref $c $m &&
1176 git rev-parse "$c" >expect &&
1177 printf $F "create $c" "$m~1" >stdin &&
1178 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1179 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1180 git rev-parse "$c" >actual &&
1181 test_cmp expect actual
1184 test_expect_success
'stdin -z create ref fails with bad new value' '
1185 git update-ref -d "$c" &&
1186 printf $F "create $c" "does-not-exist" >stdin &&
1187 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1188 grep "fatal: create $c: invalid <new-oid>: does-not-exist" err &&
1189 test_must_fail git rev-parse --verify -q $c
1192 test_expect_success
'stdin -z create ref fails with empty new value' '
1193 printf $F "create $c" "" >stdin &&
1194 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1195 grep "fatal: create $c: missing <new-oid>" err &&
1196 test_must_fail git rev-parse --verify -q $c
1199 test_expect_success
'stdin -z update ref works with right old value' '
1200 printf $F "update $b" "$m~1" "$m" >stdin &&
1201 git update-ref -z --stdin <stdin &&
1202 git rev-parse $m~1 >expect &&
1203 git rev-parse $b >actual &&
1204 test_cmp expect actual
1207 test_expect_success
'stdin -z delete ref fails with wrong old value' '
1208 printf $F "delete $a" "$m~1" >stdin &&
1209 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1210 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
1211 git rev-parse $m >expect &&
1212 git rev-parse $a >actual &&
1213 test_cmp expect actual
1216 test_expect_success
'stdin -z delete ref fails with zero old value' '
1217 printf $F "delete $a" "$Z" >stdin &&
1218 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1219 grep "fatal: delete $a: zero <old-oid>" err &&
1220 git rev-parse $m >expect &&
1221 git rev-parse $a >actual &&
1222 test_cmp expect actual
1225 test_expect_success
'stdin -z update symref works option no-deref' '
1226 git symbolic-ref TESTSYMREF $b &&
1227 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
1228 git update-ref -z --stdin <stdin &&
1229 git rev-parse TESTSYMREF >expect &&
1230 git rev-parse $a >actual &&
1231 test_cmp expect actual &&
1232 git rev-parse $m~1 >expect &&
1233 git rev-parse $b >actual &&
1234 test_cmp expect actual
1237 test_expect_success
'stdin -z delete symref works option no-deref' '
1238 git symbolic-ref TESTSYMREF $b &&
1239 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
1240 git update-ref -z --stdin <stdin &&
1241 test_must_fail git rev-parse --verify -q TESTSYMREF &&
1242 git rev-parse $m~1 >expect &&
1243 git rev-parse $b >actual &&
1244 test_cmp expect actual
1247 test_expect_success
'stdin -z delete ref works with right old value' '
1248 printf $F "delete $b" "$m~1" >stdin &&
1249 git update-ref -z --stdin <stdin &&
1250 test_must_fail git rev-parse --verify -q $b
1253 test_expect_success
'stdin -z update/create/verify combination works' '
1254 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
1255 git update-ref -z --stdin <stdin &&
1256 git rev-parse $m >expect &&
1257 git rev-parse $a >actual &&
1258 test_cmp expect actual &&
1259 git rev-parse $b >actual &&
1260 test_cmp expect actual &&
1261 test_must_fail git rev-parse --verify -q $c
1264 test_expect_success
'stdin -z verify succeeds for correct value' '
1265 git rev-parse $m >expect &&
1266 printf $F "verify $m" "$m" >stdin &&
1267 git update-ref -z --stdin <stdin &&
1268 git rev-parse $m >actual &&
1269 test_cmp expect actual
1272 test_expect_success
'stdin -z verify succeeds for missing reference' '
1273 printf $F "verify refs/heads/missing" "$Z" >stdin &&
1274 git update-ref -z --stdin <stdin &&
1275 test_must_fail git rev-parse --verify -q refs/heads/missing
1278 test_expect_success
'stdin -z verify treats no value as missing' '
1279 printf $F "verify refs/heads/missing" "" >stdin &&
1280 git update-ref -z --stdin <stdin &&
1281 test_must_fail git rev-parse --verify -q refs/heads/missing
1284 test_expect_success
'stdin -z verify fails for wrong value' '
1285 git rev-parse $m >expect &&
1286 printf $F "verify $m" "$m~1" >stdin &&
1287 test_must_fail git update-ref -z --stdin <stdin &&
1288 git rev-parse $m >actual &&
1289 test_cmp expect actual
1292 test_expect_success
'stdin -z verify fails for mistaken null value' '
1293 git rev-parse $m >expect &&
1294 printf $F "verify $m" "$Z" >stdin &&
1295 test_must_fail git update-ref -z --stdin <stdin &&
1296 git rev-parse $m >actual &&
1297 test_cmp expect actual
1300 test_expect_success
'stdin -z verify fails for mistaken empty value' '
1301 M=$(git rev-parse $m) &&
1302 test_when_finished "git update-ref $m $M" &&
1303 git rev-parse $m >expect &&
1304 printf $F "verify $m" "" >stdin &&
1305 test_must_fail git update-ref -z --stdin <stdin &&
1306 git rev-parse $m >actual &&
1307 test_cmp expect actual
1310 test_expect_success
'stdin -z update refs works with identity updates' '
1311 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
1312 git update-ref -z --stdin <stdin &&
1313 git rev-parse $m >expect &&
1314 git rev-parse $a >actual &&
1315 test_cmp expect actual &&
1316 git rev-parse $b >actual &&
1317 test_cmp expect actual &&
1318 test_must_fail git rev-parse --verify -q $c
1321 test_expect_success
'stdin -z update refs fails with wrong old value' '
1322 git update-ref $c $m &&
1323 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
1324 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1325 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1326 git rev-parse $m >expect &&
1327 git rev-parse $a >actual &&
1328 test_cmp expect actual &&
1329 git rev-parse $b >actual &&
1330 test_cmp expect actual &&
1331 git rev-parse $c >actual &&
1332 test_cmp expect actual
1335 test_expect_success
'stdin -z delete refs works with packed and loose refs' '
1336 git pack-refs --all &&
1337 git update-ref $c $m~1 &&
1338 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
1339 git update-ref -z --stdin <stdin &&
1340 test_must_fail git rev-parse --verify -q $a &&
1341 test_must_fail git rev-parse --verify -q $b &&
1342 test_must_fail git rev-parse --verify -q $c
1345 test_expect_success
'fails with duplicate HEAD update' '
1346 git branch target1 $A &&
1347 git checkout target1 &&
1348 cat >stdin <<-EOF &&
1349 update refs/heads/target1 $C
1353 test_must_fail git update-ref --stdin <stdin 2>err &&
1354 test_grep "fatal: multiple updates for '\''HEAD'\'' (including one via its referent .refs/heads/target1.) are not allowed" err &&
1355 echo "refs/heads/target1" >expect &&
1356 git symbolic-ref HEAD >actual &&
1357 test_cmp expect actual &&
1358 echo "$A" >expect &&
1359 git rev-parse refs/heads/target1 >actual &&
1360 test_cmp expect actual
1363 test_expect_success
'fails with duplicate ref update via symref' '
1364 test_when_finished "git symbolic-ref -d refs/heads/symref2" &&
1365 git branch target2 $A &&
1366 git symbolic-ref refs/heads/symref2 refs/heads/target2 &&
1367 cat >stdin <<-EOF &&
1368 update refs/heads/target2 $C
1369 update refs/heads/symref2 $B
1371 test_must_fail git update-ref --stdin <stdin 2>err &&
1372 test_grep "fatal: multiple updates for '\''refs/heads/target2'\'' (including one via symref .refs/heads/symref2.) are not allowed" err &&
1373 echo "refs/heads/target2" >expect &&
1374 git symbolic-ref refs/heads/symref2 >actual &&
1375 test_cmp expect actual &&
1376 echo "$A" >expect &&
1377 git rev-parse refs/heads/target2 >actual &&
1378 test_cmp expect actual
1381 test_expect_success ULIMIT_FILE_DESCRIPTORS
'large transaction creating branches does not burst open file limit' '
1383 test_seq -f "create refs/heads/%d HEAD" 33 >large_input &&
1384 run_with_limited_open_files git update-ref --stdin <large_input &&
1385 git rev-parse --verify -q refs/heads/33
1389 test_expect_success ULIMIT_FILE_DESCRIPTORS
'large transaction deleting branches does not burst open file limit' '
1391 test_seq -f "delete refs/heads/%d HEAD" 33 >large_input &&
1392 run_with_limited_open_files git update-ref --stdin <large_input &&
1393 test_must_fail git rev-parse --verify -q refs/heads/33
1397 test_expect_success
'handle per-worktree refs in refs/bisect' '
1398 git commit --allow-empty -m "initial commit" &&
1399 git worktree add -b branch worktree &&
1402 git commit --allow-empty -m "test commit" &&
1403 git for-each-ref >for-each-ref.out &&
1404 ! grep refs/bisect for-each-ref.out &&
1405 git update-ref refs/bisect/something HEAD &&
1406 git rev-parse refs/bisect/something >../worktree-head &&
1407 git for-each-ref | grep refs/bisect/something
1409 git show-ref >actual &&
1410 ! grep 'refs
/bisect
' actual &&
1411 test_must_fail git rev-parse refs/bisect/something &&
1412 git update-ref refs/bisect/something HEAD &&
1413 git rev-parse refs/bisect/something >main-head &&
1414 ! test_cmp main-head worktree-head
1417 test_expect_success
'transaction handles empty commit' '
1418 cat >stdin <<-EOF &&
1423 git update-ref --stdin <stdin >actual &&
1424 printf "%s: ok\n" start prepare commit >expect &&
1425 test_cmp expect actual
1428 test_expect_success
'transaction handles empty commit with missing prepare' '
1429 cat >stdin <<-EOF &&
1433 git update-ref --stdin <stdin >actual &&
1434 printf "%s: ok\n" start commit >expect &&
1435 test_cmp expect actual
1438 test_expect_success
'transaction handles sole commit' '
1439 cat >stdin <<-EOF &&
1442 git update-ref --stdin <stdin >actual &&
1443 printf "%s: ok\n" commit >expect &&
1444 test_cmp expect actual
1447 test_expect_success
'transaction handles empty abort' '
1448 cat >stdin <<-EOF &&
1453 git update-ref --stdin <stdin >actual &&
1454 printf "%s: ok\n" start prepare abort >expect &&
1455 test_cmp expect actual
1458 test_expect_success
'transaction exits on multiple aborts' '
1459 cat >stdin <<-EOF &&
1463 test_must_fail git update-ref --stdin <stdin >actual 2>err &&
1464 printf "%s: ok\n" abort >expect &&
1465 test_cmp expect actual &&
1466 grep "fatal: transaction is closed" err
1469 test_expect_success
'transaction exits on start after prepare' '
1470 cat >stdin <<-EOF &&
1474 test_must_fail git update-ref --stdin <stdin 2>err >actual &&
1475 printf "%s: ok\n" prepare >expect &&
1476 test_cmp expect actual &&
1477 grep "fatal: prepared transactions can only be closed" err
1480 test_expect_success
'transaction handles empty abort with missing prepare' '
1481 cat >stdin <<-EOF &&
1485 git update-ref --stdin <stdin >actual &&
1486 printf "%s: ok\n" start abort >expect &&
1487 test_cmp expect actual
1490 test_expect_success
'transaction handles sole abort' '
1491 cat >stdin <<-EOF &&
1494 git update-ref --stdin <stdin >actual &&
1495 printf "%s: ok\n" abort >expect &&
1496 test_cmp expect actual
1499 test_expect_success
'transaction can handle commit' '
1500 cat >stdin <<-EOF &&
1505 git update-ref --stdin <stdin >actual &&
1506 printf "%s: ok\n" start commit >expect &&
1507 test_cmp expect actual &&
1508 git rev-parse HEAD >expect &&
1509 git rev-parse $a >actual &&
1510 test_cmp expect actual
1513 test_expect_success
'transaction can handle abort' '
1514 cat >stdin <<-EOF &&
1519 git update-ref --stdin <stdin >actual &&
1520 printf "%s: ok\n" start abort >expect &&
1521 test_cmp expect actual &&
1522 test_must_fail git show-ref --verify -q $b
1525 test_expect_success
'transaction aborts by default' '
1526 cat >stdin <<-EOF &&
1530 git update-ref --stdin <stdin >actual &&
1531 printf "%s: ok\n" start >expect &&
1532 test_cmp expect actual &&
1533 test_must_fail git show-ref --verify -q $b
1536 test_expect_success
'transaction with prepare aborts by default' '
1537 cat >stdin <<-EOF &&
1542 git update-ref --stdin <stdin >actual &&
1543 printf "%s: ok\n" start prepare >expect &&
1544 test_cmp expect actual &&
1545 test_must_fail git show-ref --verify -q $b
1548 test_expect_success
'transaction can commit multiple times' '
1549 cat >stdin <<-EOF &&
1551 create refs/heads/branch-1 $A
1554 create refs/heads/branch-2 $B
1557 git update-ref --stdin <stdin >actual &&
1558 printf "%s: ok\n" start commit start commit >expect &&
1559 test_cmp expect actual &&
1560 echo "$A" >expect &&
1561 git rev-parse refs/heads/branch-1 >actual &&
1562 test_cmp expect actual &&
1563 echo "$B" >expect &&
1564 git rev-parse refs/heads/branch-2 >actual &&
1565 test_cmp expect actual
1568 test_expect_success
'transaction can create and delete' '
1569 cat >stdin <<-EOF &&
1571 create refs/heads/create-and-delete $A
1574 delete refs/heads/create-and-delete $A
1577 git update-ref --stdin <stdin >actual &&
1578 printf "%s: ok\n" start commit start commit >expect &&
1579 test_cmp expect actual &&
1580 test_must_fail git show-ref --verify refs/heads/create-and-delete
1583 test_expect_success
'transaction can commit after abort' '
1584 cat >stdin <<-EOF &&
1586 create refs/heads/abort $A
1589 create refs/heads/abort $A
1592 git update-ref --stdin <stdin >actual &&
1593 printf "%s: ok\n" start abort start commit >expect &&
1594 echo "$A" >expect &&
1595 git rev-parse refs/heads/abort >actual &&
1596 test_cmp expect actual
1599 test_expect_success
'transaction cannot restart ongoing transaction' '
1600 cat >stdin <<-EOF &&
1602 create refs/heads/restart $A
1606 test_must_fail git update-ref --stdin <stdin >actual &&
1607 printf "%s: ok\n" start >expect &&
1608 test_cmp expect actual &&
1609 test_must_fail git show-ref --verify refs/heads/restart
1612 test_expect_success PIPE
'transaction flushes status updates' '
1614 (git update-ref --stdin <in >out &) &&
1618 test_when_finished "exec 9>&-" &&
1619 test_when_finished "exec 8<&-" &&
1622 echo "start: ok" >expected &&
1624 echo "$line" >actual &&
1625 test_cmp expected actual &&
1627 echo "create refs/heads/flush $A" >&9 &&
1630 echo "prepare: ok" >expected &&
1632 echo "$line" >actual &&
1633 test_cmp expected actual &&
1635 # This must now fail given that we have locked the ref.
1636 test_must_fail git update-ref refs/heads/flush $B 2>stderr &&
1637 grep "fatal: update_ref failed for ref ${SQ}refs/heads/flush${SQ}: cannot lock ref" stderr &&
1640 echo "commit: ok" >expected &&
1642 echo "$line" >actual &&
1643 test_cmp expected actual
1659 test_expect_success
"stdin $type symref-verify fails without --no-deref" '
1660 git symbolic-ref refs/heads/symref $a &&
1661 format_command $type "symref-verify refs/heads/symref" "$a" >stdin &&
1662 test_must_fail git update-ref --stdin $type <stdin 2>err &&
1663 grep "fatal: symref-verify: cannot operate with deref mode" err
1666 test_expect_success
"stdin $type symref-verify fails with too many arguments" '
1667 format_command $type "symref-verify refs/heads/symref" "$a" "$a" >stdin &&
1668 test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1669 if test "$type" = "-z"
1671 grep "fatal: unknown command: $a" err
1673 grep "fatal: symref-verify refs/heads/symref: extra input: $a" err
1677 test_expect_success
"stdin $type symref-verify succeeds for correct value" '
1678 git symbolic-ref refs/heads/symref >expect &&
1679 test-tool ref-store main for-each-reflog-ent refs/heads/symref >before &&
1680 format_command $type "symref-verify refs/heads/symref" "$a" >stdin &&
1681 git update-ref --stdin $type --no-deref <stdin &&
1682 git symbolic-ref refs/heads/symref >actual &&
1683 test_cmp expect actual &&
1684 test-tool ref-store main for-each-reflog-ent refs/heads/symref >after &&
1685 test_cmp before after
1688 test_expect_success
"stdin $type symref-verify fails with no value" '
1689 git symbolic-ref refs/heads/symref >expect &&
1690 format_command $type "symref-verify refs/heads/symref" "" >stdin &&
1691 test_must_fail git update-ref --stdin $type --no-deref <stdin
1694 test_expect_success
"stdin $type symref-verify succeeds for dangling reference" '
1695 test_when_finished "git symbolic-ref -d refs/heads/symref2" &&
1696 test_must_fail git symbolic-ref refs/heads/nonexistent &&
1697 git symbolic-ref refs/heads/symref2 refs/heads/nonexistent &&
1698 format_command $type "symref-verify refs/heads/symref2" "refs/heads/nonexistent" >stdin &&
1699 git update-ref --stdin $type --no-deref <stdin
1702 test_expect_success
"stdin $type symref-verify fails for missing reference" '
1703 test-tool ref-store main for-each-reflog-ent refs/heads/symref >before &&
1704 format_command $type "symref-verify refs/heads/missing" "refs/heads/unknown" >stdin &&
1705 test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1706 grep "fatal: cannot lock ref ${SQ}refs/heads/missing${SQ}: unable to resolve reference ${SQ}refs/heads/missing${SQ}" err &&
1707 test_must_fail git rev-parse --verify -q refs/heads/missing &&
1708 test-tool ref-store main for-each-reflog-ent refs/heads/symref >after &&
1709 test_cmp before after
1712 test_expect_success
"stdin $type symref-verify fails for wrong value" '
1713 git symbolic-ref refs/heads/symref >expect &&
1714 format_command $type "symref-verify refs/heads/symref" "$b" >stdin &&
1715 test_must_fail git update-ref --stdin $type --no-deref <stdin &&
1716 git symbolic-ref refs/heads/symref >actual &&
1717 test_cmp expect actual
1720 test_expect_success
"stdin $type symref-verify fails for mistaken null value" '
1721 git symbolic-ref refs/heads/symref >expect &&
1722 format_command $type "symref-verify refs/heads/symref" "$Z" >stdin &&
1723 test_must_fail git update-ref --stdin $type --no-deref <stdin &&
1724 git symbolic-ref refs/heads/symref >actual &&
1725 test_cmp expect actual
1728 test_expect_success
"stdin $type symref-delete fails without --no-deref" '
1729 git symbolic-ref refs/heads/symref $a &&
1730 format_command $type "symref-delete refs/heads/symref" "$a" >stdin &&
1731 test_must_fail git update-ref --stdin $type <stdin 2>err &&
1732 grep "fatal: symref-delete: cannot operate with deref mode" err
1735 test_expect_success
"stdin $type symref-delete fails with no ref" '
1736 format_command $type "symref-delete " >stdin &&
1737 test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1738 grep "fatal: symref-delete: missing <ref>" err
1741 test_expect_success
"stdin $type symref-delete fails deleting regular ref" '
1742 test_when_finished "git update-ref -d refs/heads/regularref" &&
1743 git update-ref refs/heads/regularref $a &&
1744 format_command $type "symref-delete refs/heads/regularref" "$a" >stdin &&
1745 test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1746 grep "fatal: cannot lock ref ${SQ}refs/heads/regularref${SQ}: expected symref with target ${SQ}$a${SQ}: but is a regular ref" err
1749 test_expect_success
"stdin $type symref-delete fails with too many arguments" '
1750 format_command $type "symref-delete refs/heads/symref" "$a" "$a" >stdin &&
1751 test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1752 if test "$type" = "-z"
1754 grep "fatal: unknown command: $a" err
1756 grep "fatal: symref-delete refs/heads/symref: extra input: $a" err
1760 test_expect_success
"stdin $type symref-delete fails with wrong old value" '
1761 format_command $type "symref-delete refs/heads/symref" "$m" >stdin &&
1762 test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1763 grep "fatal: verifying symref target: ${SQ}refs/heads/symref${SQ}: is at $a but expected refs/heads/main" err &&
1764 git symbolic-ref refs/heads/symref >expect &&
1766 test_cmp expect actual
1769 test_expect_success
"stdin $type symref-delete works with right old value" '
1770 format_command $type "symref-delete refs/heads/symref" "$a" >stdin &&
1771 git update-ref --stdin $type --no-deref <stdin &&
1772 test_must_fail git rev-parse --verify -q refs/heads/symref
1775 test_expect_success
"stdin $type symref-delete works with empty old value" '
1776 git symbolic-ref refs/heads/symref $a >stdin &&
1777 format_command $type "symref-delete refs/heads/symref" "" >stdin &&
1778 git update-ref --stdin $type --no-deref <stdin &&
1779 test_must_fail git rev-parse --verify -q $b
1782 test_expect_success
"stdin $type symref-delete succeeds for dangling reference" '
1783 test_must_fail git symbolic-ref refs/heads/nonexistent &&
1784 git symbolic-ref refs/heads/symref2 refs/heads/nonexistent &&
1785 format_command $type "symref-delete refs/heads/symref2" "refs/heads/nonexistent" >stdin &&
1786 git update-ref --stdin $type --no-deref <stdin &&
1787 test_must_fail git symbolic-ref -d refs/heads/symref2
1790 test_expect_success
"stdin $type symref-delete deletes regular ref without target" '
1791 git update-ref refs/heads/regularref $a &&
1792 format_command $type "symref-delete refs/heads/regularref" >stdin &&
1793 git update-ref --stdin $type --no-deref <stdin
1796 test_expect_success
"stdin $type symref-create fails with too many arguments" '
1797 format_command $type "symref-create refs/heads/symref" "$a" "$a" >stdin &&
1798 test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1799 if test "$type" = "-z"
1801 grep "fatal: unknown command: $a" err
1803 grep "fatal: symref-create refs/heads/symref: extra input: $a" err
1807 test_expect_success
"stdin $type symref-create fails with no target" '
1808 format_command $type "symref-create refs/heads/symref" >stdin &&
1809 test_must_fail git update-ref --stdin $type --no-deref <stdin
1812 test_expect_success
"stdin $type symref-create fails with empty target" '
1813 format_command $type "symref-create refs/heads/symref" "" >stdin &&
1814 test_must_fail git update-ref --stdin $type --no-deref <stdin
1817 test_expect_success
"stdin $type symref-create works" '
1818 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1819 format_command $type "symref-create refs/heads/symref" "$a" >stdin &&
1820 git update-ref --stdin $type --no-deref <stdin &&
1821 git symbolic-ref refs/heads/symref >expect &&
1823 test_cmp expect actual
1826 test_expect_success
"stdin $type symref-create works with --no-deref" '
1827 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1828 format_command $type "symref-create refs/heads/symref" "$a" &&
1829 git update-ref --stdin $type <stdin 2>err
1832 test_expect_success
"stdin $type create dangling symref ref works" '
1833 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1834 format_command $type "symref-create refs/heads/symref" "refs/heads/unknown" >stdin &&
1835 git update-ref --stdin $type --no-deref <stdin &&
1836 git symbolic-ref refs/heads/symref >expect &&
1837 echo refs/heads/unknown >actual &&
1838 test_cmp expect actual
1841 test_expect_success
"stdin $type symref-create does not create reflogs by default" '
1842 test_when_finished "git symbolic-ref -d refs/symref" &&
1843 format_command $type "symref-create refs/symref" "$a" >stdin &&
1844 git update-ref --stdin $type --no-deref <stdin &&
1845 git symbolic-ref refs/symref >expect &&
1847 test_cmp expect actual &&
1848 test_must_fail git reflog exists refs/symref
1851 test_expect_success
"stdin $type symref-create reflogs with --create-reflog" '
1852 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1853 format_command $type "symref-create refs/heads/symref" "$a" >stdin &&
1854 git update-ref --create-reflog --stdin $type --no-deref <stdin &&
1855 git symbolic-ref refs/heads/symref >expect &&
1857 test_cmp expect actual &&
1858 git reflog exists refs/heads/symref
1861 test_expect_success
"stdin $type symref-update fails with too many arguments" '
1862 format_command $type "symref-update refs/heads/symref" "$a" "ref" "$a" "$a" >stdin &&
1863 test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1864 if test "$type" = "-z"
1866 grep "fatal: unknown command: $a" err
1868 grep "fatal: symref-update refs/heads/symref: extra input: $a" err
1872 test_expect_success
"stdin $type symref-update fails with wrong old value argument" '
1873 format_command $type "symref-update refs/heads/symref" "$a" "foo" "$a" "$a" >stdin &&
1874 test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1875 grep "fatal: symref-update refs/heads/symref: invalid arg ${SQ}foo${SQ} for old value" err
1878 test_expect_success
"stdin $type symref-update creates with zero old value" '
1879 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1880 format_command $type "symref-update refs/heads/symref" "$a" "oid" "$Z" >stdin &&
1881 git update-ref --stdin $type --no-deref <stdin &&
1883 git symbolic-ref refs/heads/symref >actual &&
1884 test_cmp expect actual
1887 test_expect_success
"stdin $type symref-update creates with no old value" '
1888 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1889 format_command $type "symref-update refs/heads/symref" "$a" >stdin &&
1890 git update-ref --stdin $type --no-deref <stdin &&
1892 git symbolic-ref refs/heads/symref >actual &&
1893 test_cmp expect actual
1896 test_expect_success
"stdin $type symref-update creates dangling" '
1897 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1898 test_must_fail git rev-parse refs/heads/nonexistent &&
1899 format_command $type "symref-update refs/heads/symref" "refs/heads/nonexistent" >stdin &&
1900 git update-ref --stdin $type --no-deref <stdin &&
1901 echo refs/heads/nonexistent >expect &&
1902 git symbolic-ref refs/heads/symref >actual &&
1903 test_cmp expect actual
1906 test_expect_success
"stdin $type symref-update fails with wrong old value" '
1907 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1908 git symbolic-ref refs/heads/symref $a &&
1909 format_command $type "symref-update refs/heads/symref" "$m" "ref" "$b" >stdin &&
1910 test_must_fail git update-ref --stdin $type --no-deref <stdin 2>err &&
1911 grep "fatal: verifying symref target: ${SQ}refs/heads/symref${SQ}: is at $a but expected $b" err &&
1912 test_must_fail git rev-parse --verify -q $c
1915 test_expect_success
"stdin $type symref-update updates dangling ref" '
1916 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1917 test_must_fail git rev-parse refs/heads/nonexistent &&
1918 git symbolic-ref refs/heads/symref refs/heads/nonexistent &&
1919 format_command $type "symref-update refs/heads/symref" "$a" >stdin &&
1920 git update-ref --stdin $type --no-deref <stdin &&
1922 git symbolic-ref refs/heads/symref >actual &&
1923 test_cmp expect actual
1926 test_expect_success
"stdin $type symref-update updates dangling ref with old value" '
1927 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1928 test_must_fail git rev-parse refs/heads/nonexistent &&
1929 git symbolic-ref refs/heads/symref refs/heads/nonexistent &&
1930 format_command $type "symref-update refs/heads/symref" "$a" "ref" "refs/heads/nonexistent" >stdin &&
1931 git update-ref --stdin $type --no-deref <stdin &&
1933 git symbolic-ref refs/heads/symref >actual &&
1934 test_cmp expect actual
1937 test_expect_success
"stdin $type symref-update fails update dangling ref with wrong old value" '
1938 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1939 test_must_fail git rev-parse refs/heads/nonexistent &&
1940 git symbolic-ref refs/heads/symref refs/heads/nonexistent &&
1941 format_command $type "symref-update refs/heads/symref" "$a" "ref" "refs/heads/wrongref" >stdin &&
1942 test_must_fail git update-ref --stdin $type --no-deref <stdin &&
1943 echo refs/heads/nonexistent >expect &&
1944 git symbolic-ref refs/heads/symref >actual &&
1945 test_cmp expect actual
1948 test_expect_success
"stdin $type symref-update works with right old value" '
1949 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1950 git symbolic-ref refs/heads/symref $a &&
1951 format_command $type "symref-update refs/heads/symref" "$m" "ref" "$a" >stdin &&
1952 git update-ref --stdin $type --no-deref <stdin &&
1954 git symbolic-ref refs/heads/symref >actual &&
1955 test_cmp expect actual
1958 test_expect_success
"stdin $type symref-update works with no old value" '
1959 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1960 git symbolic-ref refs/heads/symref $a &&
1961 format_command $type "symref-update refs/heads/symref" "$m" >stdin &&
1962 git update-ref --stdin $type --no-deref <stdin &&
1964 git symbolic-ref refs/heads/symref >actual &&
1965 test_cmp expect actual
1968 test_expect_success
"stdin $type symref-update fails with empty old ref-target" '
1969 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1970 git symbolic-ref refs/heads/symref $a &&
1971 format_command $type "symref-update refs/heads/symref" "$m" "ref" "" >stdin &&
1972 test_must_fail git update-ref --stdin $type --no-deref <stdin &&
1974 git symbolic-ref refs/heads/symref >actual &&
1975 test_cmp expect actual
1978 test_expect_success
"stdin $type symref-update creates (with deref)" '
1979 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
1980 format_command $type "symref-update refs/heads/symref" "$a" >stdin &&
1981 git update-ref --stdin $type <stdin &&
1983 git symbolic-ref --no-recurse refs/heads/symref >actual &&
1984 test_cmp expect actual &&
1985 test-tool ref-store main for-each-reflog-ent refs/heads/symref >actual &&
1986 grep "$Z $(git rev-parse $a)" actual
1989 test_expect_success
"stdin $type symref-update regular ref to symref with correct old-oid" '
1990 test_when_finished "git symbolic-ref -d --no-recurse refs/heads/regularref" &&
1991 git update-ref --no-deref refs/heads/regularref $a &&
1992 format_command $type "symref-update refs/heads/regularref" "$a" "oid" "$(git rev-parse $a)" >stdin &&
1993 git update-ref --stdin $type <stdin &&
1995 git symbolic-ref --no-recurse refs/heads/regularref >actual &&
1996 test_cmp expect actual &&
1997 test-tool ref-store main for-each-reflog-ent refs/heads/regularref >actual &&
1998 grep "$(git rev-parse $a) $(git rev-parse $a)" actual
2001 test_expect_success
"stdin $type symref-update regular ref to symref fails with wrong old-oid" '
2002 test_when_finished "git update-ref -d refs/heads/regularref" &&
2003 git update-ref --no-deref refs/heads/regularref $a &&
2004 format_command $type "symref-update refs/heads/regularref" "$a" "oid" "$(git rev-parse refs/heads/target2)" >stdin &&
2005 test_must_fail git update-ref --stdin $type <stdin 2>err &&
2006 grep "fatal: cannot lock ref ${SQ}refs/heads/regularref${SQ}: is at $(git rev-parse $a) but expected $(git rev-parse refs/heads/target2)" err &&
2007 echo $(git rev-parse $a) >expect &&
2008 git rev-parse refs/heads/regularref >actual &&
2009 test_cmp expect actual
2012 test_expect_success
"stdin $type symref-update regular ref to symref fails with invalid old-oid" '
2013 test_when_finished "git update-ref -d refs/heads/regularref" &&
2014 git update-ref --no-deref refs/heads/regularref $a &&
2015 format_command $type "symref-update refs/heads/regularref" "$a" "oid" "not-a-ref-oid" >stdin &&
2016 test_must_fail git update-ref --stdin $type <stdin 2>err &&
2017 grep "fatal: symref-update refs/heads/regularref: invalid oid: not-a-ref-oid" err &&
2018 echo $(git rev-parse $a) >expect &&
2019 git rev-parse refs/heads/regularref >actual &&
2020 test_cmp expect actual
2023 test_expect_success
"stdin $type symref-update existing symref with zero old-oid" '
2024 test_when_finished "git symbolic-ref -d --no-recurse refs/heads/symref" &&
2025 git symbolic-ref refs/heads/symref refs/heads/target2 &&
2026 format_command $type "symref-update refs/heads/symref" "$a" "oid" "$Z" >stdin &&
2027 test_must_fail git update-ref --stdin $type <stdin 2>err &&
2028 grep "fatal: cannot lock ref ${SQ}refs/heads/symref${SQ}: reference already exists" err &&
2029 echo refs/heads/target2 >expect &&
2030 git symbolic-ref refs/heads/symref >actual &&
2031 test_cmp expect actual
2034 test_expect_success
"stdin $type symref-update regular ref to symref (with deref)" '
2035 test_when_finished "git symbolic-ref -d refs/heads/symref" &&
2036 test_when_finished "git update-ref -d --no-deref refs/heads/symref2" &&
2037 git update-ref refs/heads/symref2 $a &&
2038 git symbolic-ref --no-recurse refs/heads/symref refs/heads/symref2 &&
2039 format_command $type "symref-update refs/heads/symref" "$a" >stdin &&
2040 git update-ref $type --stdin <stdin &&
2042 git symbolic-ref --no-recurse refs/heads/symref2 >actual &&
2043 test_cmp expect actual &&
2044 echo refs/heads/symref2 >expect &&
2045 git symbolic-ref --no-recurse refs/heads/symref >actual &&
2046 test_cmp expect actual &&
2047 test-tool ref-store main for-each-reflog-ent refs/heads/symref >actual &&
2048 grep "$(git rev-parse $a) $(git rev-parse $a)" actual
2051 test_expect_success
"stdin $type symref-update regular ref to symref" '
2052 test_when_finished "git symbolic-ref -d --no-recurse refs/heads/regularref" &&
2053 git update-ref --no-deref refs/heads/regularref $a &&
2054 format_command $type "symref-update refs/heads/regularref" "$a" >stdin &&
2055 git update-ref $type --stdin <stdin &&
2057 git symbolic-ref --no-recurse refs/heads/regularref >actual &&
2058 test_cmp expect actual &&
2059 test-tool ref-store main for-each-reflog-ent refs/heads/regularref >actual &&
2060 grep "$(git rev-parse $a) $(git rev-parse $a)" actual
2063 test_expect_success
"stdin $type batch-updates" '
2065 test_when_finished "rm -fr repo" &&
2068 test_commit commit &&
2069 head=$(git rev-parse HEAD) &&
2071 format_command $type "update refs/heads/ref1" "$head" "$Z" >stdin &&
2072 format_command $type "update refs/heads/ref2" "$head" "$Z" >>stdin &&
2073 git update-ref $type --stdin --batch-updates <stdin &&
2074 echo $head >expect &&
2075 git rev-parse refs/heads/ref1 >actual &&
2076 test_cmp expect actual &&
2077 git rev-parse refs/heads/ref2 >actual &&
2078 test_cmp expect actual
2082 test_expect_success
"stdin $type batch-updates with invalid new_oid" '
2084 test_when_finished "rm -fr repo" &&
2088 old_head=$(git rev-parse HEAD) &&
2090 head=$(git rev-parse HEAD) &&
2091 git update-ref refs/heads/ref1 $head &&
2092 git update-ref refs/heads/ref2 $head &&
2094 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2095 format_command $type "update refs/heads/ref2" "$(test_oid 001)" "$head" >>stdin &&
2096 git update-ref $type --stdin --batch-updates <stdin >stdout &&
2097 echo $old_head >expect &&
2098 git rev-parse refs/heads/ref1 >actual &&
2099 test_cmp expect actual &&
2100 echo $head >expect &&
2101 git rev-parse refs/heads/ref2 >actual &&
2102 test_cmp expect actual &&
2103 test_grep -q "invalid new value provided" stdout
2107 test_expect_success
"stdin $type batch-updates with non-commit new_oid" '
2109 test_when_finished "rm -fr repo" &&
2113 old_head=$(git rev-parse HEAD) &&
2115 head=$(git rev-parse HEAD) &&
2116 head_tree=$(git rev-parse HEAD^{tree}) &&
2117 git update-ref refs/heads/ref1 $head &&
2118 git update-ref refs/heads/ref2 $head &&
2120 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2121 format_command $type "update refs/heads/ref2" "$head_tree" "$head" >>stdin &&
2122 git update-ref $type --stdin --batch-updates <stdin >stdout &&
2123 echo $old_head >expect &&
2124 git rev-parse refs/heads/ref1 >actual &&
2125 test_cmp expect actual &&
2126 echo $head >expect &&
2127 git rev-parse refs/heads/ref2 >actual &&
2128 test_cmp expect actual &&
2129 test_grep -q "invalid new value provided" stdout
2133 test_expect_success
"stdin $type batch-updates with non-existent ref" '
2135 test_when_finished "rm -fr repo" &&
2139 old_head=$(git rev-parse HEAD) &&
2141 head=$(git rev-parse HEAD) &&
2142 git update-ref refs/heads/ref1 $head &&
2144 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2145 format_command $type "update refs/heads/ref2" "$old_head" "$head" >>stdin &&
2146 git update-ref $type --stdin --batch-updates <stdin >stdout &&
2147 echo $old_head >expect &&
2148 git rev-parse refs/heads/ref1 >actual &&
2149 test_cmp expect actual &&
2150 test_must_fail git rev-parse refs/heads/ref2 &&
2151 test_grep -q "reference does not exist" stdout
2155 test_expect_success
"stdin $type batch-updates with dangling symref" '
2157 test_when_finished "rm -fr repo" &&
2161 old_head=$(git rev-parse HEAD) &&
2163 head=$(git rev-parse HEAD) &&
2164 git update-ref refs/heads/ref1 $head &&
2165 git symbolic-ref refs/heads/ref2 refs/heads/nonexistent &&
2167 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2168 format_command $type "update refs/heads/ref2" "$old_head" "$head" >>stdin &&
2169 git update-ref $type --no-deref --stdin --batch-updates <stdin >stdout &&
2170 echo $old_head >expect &&
2171 git rev-parse refs/heads/ref1 >actual &&
2172 test_cmp expect actual &&
2173 echo $head >expect &&
2174 test_must_fail git rev-parse refs/heads/ref2 &&
2175 test_grep -q "reference does not exist" stdout
2179 test_expect_success
"stdin $type batch-updates with regular ref as symref" '
2181 test_when_finished "rm -fr repo" &&
2185 old_head=$(git rev-parse HEAD) &&
2187 head=$(git rev-parse HEAD) &&
2188 git update-ref refs/heads/ref1 $head &&
2189 git update-ref refs/heads/ref2 $head &&
2191 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2192 format_command $type "symref-update refs/heads/ref2" "$old_head" "ref" "refs/heads/nonexistent" >>stdin &&
2193 git update-ref $type --no-deref --stdin --batch-updates <stdin >stdout &&
2194 echo $old_head >expect &&
2195 git rev-parse refs/heads/ref1 >actual &&
2196 test_cmp expect actual &&
2197 echo $head >expect &&
2198 echo $head >expect &&
2199 git rev-parse refs/heads/ref2 >actual &&
2200 test_cmp expect actual &&
2201 test_grep -q "expected symref but found regular ref" stdout
2205 test_expect_success
"stdin $type batch-updates with invalid old_oid" '
2207 test_when_finished "rm -fr repo" &&
2211 old_head=$(git rev-parse HEAD) &&
2213 head=$(git rev-parse HEAD) &&
2214 git update-ref refs/heads/ref1 $head &&
2215 git update-ref refs/heads/ref2 $head &&
2217 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2218 format_command $type "update refs/heads/ref2" "$old_head" "$Z" >>stdin &&
2219 git update-ref $type --stdin --batch-updates <stdin >stdout &&
2220 echo $old_head >expect &&
2221 git rev-parse refs/heads/ref1 >actual &&
2222 test_cmp expect actual &&
2223 echo $head >expect &&
2224 git rev-parse refs/heads/ref2 >actual &&
2225 test_cmp expect actual &&
2226 test_grep -q "reference already exists" stdout
2230 test_expect_success
"stdin $type batch-updates with incorrect old oid" '
2232 test_when_finished "rm -fr repo" &&
2236 old_head=$(git rev-parse HEAD) &&
2238 head=$(git rev-parse HEAD) &&
2239 git update-ref refs/heads/ref1 $head &&
2240 git update-ref refs/heads/ref2 $head &&
2242 format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2243 format_command $type "update refs/heads/ref2" "$head" "$old_head" >>stdin &&
2244 git update-ref $type --stdin --batch-updates <stdin >stdout &&
2245 echo $old_head >expect &&
2246 git rev-parse refs/heads/ref1 >actual &&
2247 test_cmp expect actual &&
2248 echo $head >expect &&
2249 git rev-parse refs/heads/ref2 >actual &&
2250 test_cmp expect actual &&
2251 test_grep -q "incorrect old value provided" stdout
2255 test_expect_success
"stdin $type batch-updates refname conflict" '
2257 test_when_finished "rm -fr repo" &&
2261 old_head=$(git rev-parse HEAD) &&
2263 head=$(git rev-parse HEAD) &&
2264 git update-ref refs/heads/ref/foo $head &&
2266 format_command $type "update refs/heads/ref/foo" "$old_head" "$head" >stdin &&
2267 format_command $type "update refs/heads/ref" "$old_head" "" >>stdin &&
2268 git update-ref $type --stdin --batch-updates <stdin >stdout &&
2269 echo $old_head >expect &&
2270 git rev-parse refs/heads/ref/foo >actual &&
2271 test_cmp expect actual &&
2272 test_grep -q "refname conflict" stdout
2276 test_expect_success
"stdin $type batch-updates refname conflict new ref" '
2278 test_when_finished "rm -fr repo" &&
2282 old_head=$(git rev-parse HEAD) &&
2284 head=$(git rev-parse HEAD) &&
2285 git update-ref refs/heads/ref/foo $head &&
2287 format_command $type "update refs/heads/foo" "$old_head" "" >stdin &&
2288 format_command $type "update refs/heads/ref" "$old_head" "" >>stdin &&
2289 git update-ref $type --stdin --batch-updates <stdin >stdout &&
2290 echo $old_head >expect &&
2291 git rev-parse refs/heads/foo >actual &&
2292 test_cmp expect actual &&
2293 test_grep -q "refname conflict" stdout
2297 test_expect_success
"stdin $type batch-updates delete incorrect symbolic ref" '
2299 test_when_finished "rm -fr repo" &&
2303 head=$(git rev-parse HEAD) &&
2304 git symbolic-ref refs/heads/symbolic refs/heads/non-existent &&
2306 format_command $type "delete refs/heads/symbolic" "$head" >stdin &&
2307 git update-ref $type --stdin --batch-updates <stdin >stdout &&
2308 test_grep "reference does not exist" stdout
2312 test_expect_success
"stdin $type batch-updates delete with incorrect old_oid" '
2314 test_when_finished "rm -fr repo" &&
2318 git branch new-branch &&
2320 head=$(git rev-parse HEAD) &&
2322 format_command $type "delete refs/heads/new-branch" "$head" >stdin &&
2323 git update-ref $type --stdin --batch-updates <stdin >stdout &&
2324 test_grep "incorrect old value provided" stdout
2328 test_expect_success
"stdin $type batch-updates delete non-existent ref" '
2330 test_when_finished "rm -fr repo" &&
2333 test_commit commit &&
2334 head=$(git rev-parse HEAD) &&
2336 format_command $type "delete refs/heads/non-existent" "$head" >stdin &&
2337 git update-ref $type --stdin --batch-updates <stdin >stdout &&
2338 test_grep "reference does not exist" stdout
2343 test_expect_success
'update-ref should also create reflog for HEAD' '
2344 test_commit to-rewind &&
2345 git rev-parse HEAD >expect &&
2346 head=$(git symbolic-ref HEAD) &&
2347 git update-ref --create-reflog "$head" HEAD~ &&
2348 git rev-parse HEAD@{1} >actual &&
2349 test_cmp expect actual
2352 test_expect_success REFFILES
'empty directories are pruned when aborting a transaction' '
2353 test_path_is_missing .git/refs/heads/nested &&
2354 git update-ref --stdin <<-EOF &&
2355 create refs/heads/nested/something HEAD
2359 test_path_is_missing .git/refs/heads/nested
2362 test_expect_success REFFILES
'empty directories are pruned when not committing' '
2363 test_path_is_missing .git/refs/heads/nested &&
2364 git update-ref --stdin <<-EOF &&
2365 create refs/heads/nested/something HEAD
2368 test_path_is_missing .git/refs/heads/nested