3 # Copyright (c) 2006 Shawn Pearce
6 test_description
='Test git update-ref and basic ref logging'
15 create_test_commits
()
18 for name
in A B C D E F
21 T
=$
(git write-tree
) &&
22 sha1
=$
(echo $name | git commit-tree
$T) &&
27 test_expect_success setup
'
28 git checkout --orphan main &&
29 create_test_commits "" &&
32 git init --bare -b main &&
33 create_test_commits "bare" &&
37 test_expect_success
"create $m" '
38 git update-ref $m $A &&
39 test $A = $(git show-ref -s --verify $m)
41 test_expect_success
"create $m with oldvalue verification" '
42 git update-ref $m $B $A &&
43 test $B = $(git show-ref -s --verify $m)
45 test_expect_success
"fail to delete $m with stale ref" '
46 test_must_fail git update-ref -d $m $A &&
47 test $B = "$(git show-ref -s --verify $m)"
49 test_expect_success
"delete $m" '
50 test_when_finished "git update-ref -d $m" &&
51 git update-ref -d $m $B &&
52 test_must_fail git show-ref --verify -q $m
55 test_expect_success
"delete $m without oldvalue verification" '
56 test_when_finished "git update-ref -d $m" &&
57 git update-ref $m $A &&
58 test $A = $(git show-ref -s --verify $m) &&
59 git update-ref -d $m &&
60 test_must_fail git show-ref --verify -q $m
63 test_expect_success
"fail to create $n due to file/directory conflict" '
64 test_when_finished "git update-ref -d refs/heads/gu" &&
65 git update-ref refs/heads/gu $A &&
66 test_must_fail git update-ref refs/heads/gu/fixes $A
69 test_expect_success
"create $m (by HEAD)" '
70 git update-ref HEAD $A &&
71 test $A = $(git show-ref -s --verify $m)
73 test_expect_success
"create $m (by HEAD) with oldvalue verification" '
74 git update-ref HEAD $B $A &&
75 test $B = $(git show-ref -s --verify $m)
77 test_expect_success
"fail to delete $m (by HEAD) with stale ref" '
78 test_must_fail git update-ref -d HEAD $A &&
79 test $B = $(git show-ref -s --verify $m)
81 test_expect_success
"delete $m (by HEAD)" '
82 test_when_finished "git update-ref -d $m" &&
83 git update-ref -d HEAD $B &&
84 test_must_fail git show-ref --verify -q $m
87 test_expect_success
"deleting current branch adds message to HEAD's log" '
88 test_when_finished "git update-ref -d $m" &&
89 git update-ref $m $A &&
90 git symbolic-ref HEAD $m &&
91 git update-ref -m delete-$m -d $m &&
92 test_must_fail git show-ref --verify -q $m &&
93 test-tool ref-store main for-each-reflog-ent HEAD >actual &&
94 grep "delete-$m$" actual
97 test_expect_success
"deleting by HEAD adds message to HEAD's log" '
98 test_when_finished "git update-ref -d $m" &&
99 git update-ref $m $A &&
100 git symbolic-ref HEAD $m &&
101 git update-ref -m delete-by-head -d HEAD &&
102 test_must_fail git show-ref --verify -q $m &&
103 test-tool ref-store main for-each-reflog-ent HEAD >actual &&
104 grep "delete-by-head$" actual
107 test_expect_success
'update-ref does not create reflogs by default' '
108 test_when_finished "git update-ref -d $outside" &&
109 git update-ref $outside $A &&
110 git rev-parse $A >expect &&
111 git rev-parse $outside >actual &&
112 test_cmp expect actual &&
113 test_must_fail git reflog exists $outside
116 test_expect_success
'update-ref creates reflogs with --create-reflog' '
117 test_when_finished "git update-ref -d $outside" &&
118 git update-ref --create-reflog $outside $A &&
119 git rev-parse $A >expect &&
120 git rev-parse $outside >actual &&
121 test_cmp expect actual &&
122 git reflog exists $outside
125 test_expect_success
'creates no reflog in bare repository' '
126 git -C $bare update-ref $m $bareA &&
127 git -C $bare rev-parse $bareA >expect &&
128 git -C $bare rev-parse $m >actual &&
129 test_cmp expect actual &&
130 test_must_fail git -C $bare reflog exists $m
133 test_expect_success
'core.logAllRefUpdates=true creates reflog in bare repository' '
134 test_when_finished "git -C $bare config --unset core.logAllRefUpdates && \
135 test-tool ref-store main delete-reflog $m" &&
136 git -C $bare config core.logAllRefUpdates true &&
137 git -C $bare update-ref $m $bareB &&
138 git -C $bare rev-parse $bareB >expect &&
139 git -C $bare rev-parse $m >actual &&
140 test_cmp expect actual &&
141 git -C $bare reflog exists $m
144 test_expect_success
'core.logAllRefUpdates=true does not create reflog by default' '
145 test_config core.logAllRefUpdates true &&
146 test_when_finished "git update-ref -d $outside" &&
147 git update-ref $outside $A &&
148 git rev-parse $A >expect &&
149 git rev-parse $outside >actual &&
150 test_cmp expect actual &&
151 test_must_fail git reflog exists $outside
154 test_expect_success
'core.logAllRefUpdates=always creates reflog by default' '
155 test_config core.logAllRefUpdates always &&
156 test_when_finished "git update-ref -d $outside" &&
157 git update-ref $outside $A &&
158 git rev-parse $A >expect &&
159 git rev-parse $outside >actual &&
160 test_cmp expect actual &&
161 git reflog exists $outside
164 test_expect_success
'core.logAllRefUpdates=always creates reflog for ORIG_HEAD' '
165 test_config core.logAllRefUpdates always &&
166 git update-ref ORIG_HEAD $A &&
167 git reflog exists ORIG_HEAD
170 test_expect_success
'--no-create-reflog overrides core.logAllRefUpdates=always' '
171 test_config core.logAllRefUpdates true &&
172 test_when_finished "git update-ref -d $outside" &&
173 git update-ref --no-create-reflog $outside $A &&
174 git rev-parse $A >expect &&
175 git rev-parse $outside >actual &&
176 test_cmp expect actual &&
177 test_must_fail git reflog exists $outside
180 test_expect_success
"create $m (by HEAD)" '
181 git update-ref HEAD $A &&
182 test $A = $(git show-ref -s --verify $m)
184 test_expect_success
'pack refs' '
187 test_expect_success
"move $m (by HEAD)" '
188 git update-ref HEAD $B $A &&
189 test $B = $(git show-ref -s --verify $m)
191 test_expect_success
"delete $m (by HEAD) should remove both packed and loose $m" '
192 test_when_finished "git update-ref -d $m" &&
193 git update-ref -d HEAD $B &&
194 ! grep "$m" .git/packed-refs &&
195 test_must_fail git show-ref --verify -q $m
198 test_expect_success
'delete symref without dereference' '
199 test_when_finished "git update-ref -d $m" &&
203 git symbolic-ref SYMREF $m &&
204 git update-ref --no-deref -d SYMREF &&
205 git show-ref --verify -q $m &&
206 test_must_fail git show-ref --verify -q SYMREF &&
207 test_must_fail git symbolic-ref SYMREF
210 test_expect_success
'delete symref without dereference when the referred ref is packed' '
211 test_when_finished "git update-ref -d $m" &&
215 git symbolic-ref SYMREF $m &&
216 git pack-refs --all &&
217 git update-ref --no-deref -d SYMREF &&
218 git show-ref --verify -q $m &&
219 test_must_fail git show-ref --verify -q SYMREF &&
220 test_must_fail git symbolic-ref SYMREF
223 test_expect_success
'update-ref -d is not confused by self-reference' '
224 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" &&
225 git symbolic-ref refs/heads/self refs/heads/self &&
226 git symbolic-ref --no-recurse refs/heads/self &&
227 test_must_fail git update-ref -d refs/heads/self &&
228 git symbolic-ref --no-recurse refs/heads/self
231 test_expect_success
'update-ref --no-deref -d can delete self-reference' '
232 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" &&
233 git symbolic-ref refs/heads/self refs/heads/self &&
234 git symbolic-ref --no-recurse refs/heads/self &&
235 git update-ref --no-deref -d refs/heads/self &&
236 test_must_fail git show-ref --verify -q refs/heads/self
239 test_expect_success REFFILES
'update-ref --no-deref -d can delete reference to bad ref' '
240 >.git/refs/heads/bad &&
241 test_when_finished "rm -f .git/refs/heads/bad" &&
242 git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
243 test_when_finished "git update-ref -d refs/heads/ref-to-bad" &&
244 git symbolic-ref --no-recurse refs/heads/ref-to-bad &&
245 git update-ref --no-deref -d refs/heads/ref-to-bad &&
246 test_must_fail git show-ref --verify -q refs/heads/ref-to-bad
249 test_expect_success
'(not) create HEAD with old sha1' '
250 test_must_fail git update-ref HEAD $A $B
252 test_expect_success
"(not) prior created .git/$m" '
253 test_when_finished "git update-ref -d $m" &&
254 test_must_fail git show-ref --verify -q $m
257 test_expect_success
'create HEAD' '
258 git update-ref HEAD $A
260 test_expect_success
'(not) change HEAD with wrong SHA1' '
261 test_must_fail git update-ref HEAD $B $Z
263 test_expect_success
"(not) changed .git/$m" '
264 test_when_finished "git update-ref -d $m" &&
265 ! test $B = $(git show-ref -s --verify $m)
268 test_expect_success
"clean up reflog" '
269 test-tool ref-store main delete-reflog $m
272 test_expect_success
"create $m (logged by touch)" '
273 test_config core.logAllRefUpdates false &&
274 GIT_COMMITTER_DATE="2005-05-26 23:30" \
275 git update-ref --create-reflog HEAD $A -m "Initial Creation" &&
276 test $A = $(git show-ref -s --verify $m)
278 test_expect_success
"update $m (logged by touch)" '
279 test_config core.logAllRefUpdates false &&
280 GIT_COMMITTER_DATE="2005-05-26 23:31" \
281 git update-ref HEAD $B $A -m "Switch" &&
282 test $B = $(git show-ref -s --verify $m)
284 test_expect_success
"set $m (logged by touch)" '
285 test_config core.logAllRefUpdates false &&
286 GIT_COMMITTER_DATE="2005-05-26 23:41" \
287 git update-ref HEAD $A &&
288 test $A = $(git show-ref -s --verify $m)
291 test_expect_success REFFILES
'empty directory removal' '
292 git branch d1/d2/r1 HEAD &&
293 git branch d1/r2 HEAD &&
294 test_path_is_file .git/refs/heads/d1/d2/r1 &&
295 test_path_is_file .git/logs/refs/heads/d1/d2/r1 &&
296 git branch -d d1/d2/r1 &&
297 test_must_fail git show-ref --verify -q refs/heads/d1/d2 &&
298 test_must_fail git show-ref --verify -q logs/refs/heads/d1/d2 &&
299 test_path_is_file .git/refs/heads/d1/r2 &&
300 test_path_is_file .git/logs/refs/heads/d1/r2
303 test_expect_success REFFILES
'symref empty directory removal' '
304 git branch e1/e2/r1 HEAD &&
305 git branch e1/r2 HEAD &&
306 git checkout e1/e2/r1 &&
307 test_when_finished "git checkout main" &&
308 test_path_is_file .git/refs/heads/e1/e2/r1 &&
309 test_path_is_file .git/logs/refs/heads/e1/e2/r1 &&
310 git update-ref -d HEAD &&
311 test_must_fail git show-ref --verify -q refs/heads/e1/e2 &&
312 test_must_fail git show-ref --verify -q logs/refs/heads/e1/e2 &&
313 test_path_is_file .git/refs/heads/e1/r2 &&
314 test_path_is_file .git/logs/refs/heads/e1/r2 &&
315 test_path_is_file .git/logs/HEAD
319 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
320 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
321 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
323 test_expect_success
"verifying $m's log (logged by touch)" '
324 test_when_finished "git update-ref -d $m && git reflog expire --expire=all --all && rm -rf actual expect" &&
325 test-tool ref-store main for-each-reflog-ent $m >actual &&
326 test_cmp actual expect
329 test_expect_success
"create $m (logged by config)" '
330 test_config core.logAllRefUpdates true &&
331 GIT_COMMITTER_DATE="2005-05-26 23:32" \
332 git update-ref HEAD $A -m "Initial Creation" &&
333 test $A = $(git show-ref -s --verify $m)
335 test_expect_success
"update $m (logged by config)" '
336 test_config core.logAllRefUpdates true &&
337 GIT_COMMITTER_DATE="2005-05-26 23:33" \
338 git update-ref HEAD $B $A -m "Switch" &&
339 test $B = $(git show-ref -s --verify $m)
341 test_expect_success
"set $m (logged by config)" '
342 test_config core.logAllRefUpdates true &&
343 GIT_COMMITTER_DATE="2005-05-26 23:43" \
344 git update-ref HEAD $A &&
345 test $A = $(git show-ref -s --verify $m)
349 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
350 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
351 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
353 test_expect_success
"verifying $m's log (logged by config)" '
354 test_when_finished "git update-ref -d $m && git reflog expire --expire=all --all && rm -rf actual expect" &&
355 test-tool ref-store main for-each-reflog-ent $m >actual &&
356 test_cmp actual expect
359 test_expect_success
'set up for querying the reflog' '
360 git update-ref -d $m &&
361 test-tool ref-store main delete-reflog $m &&
363 GIT_COMMITTER_DATE="1117150320 -0500" git update-ref $m $C &&
364 GIT_COMMITTER_DATE="1117150350 -0500" git update-ref $m $A &&
365 GIT_COMMITTER_DATE="1117150380 -0500" git update-ref $m $B &&
366 GIT_COMMITTER_DATE="1117150680 -0500" git update-ref $m $F &&
367 GIT_COMMITTER_DATE="1117150980 -0500" git update-ref $m $E &&
368 git update-ref $m $D &&
369 # Delete the last reflog entry so that the tip of m and the reflog for
371 git reflog delete $m@{0} &&
373 cat >expect <<-EOF &&
374 $Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
375 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
376 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
377 $B $F $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
378 $F $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
380 test-tool ref-store main for-each-reflog-ent $m >actual &&
381 test_cmp expect actual
384 ed
="Thu, 26 May 2005 18:32:00 -0500"
385 gd
="Thu, 26 May 2005 18:33:00 -0500"
386 ld
="Thu, 26 May 2005 18:43:00 -0500"
387 test_expect_success
'Query "main@{May 25 2005}" (before history)' '
388 test_when_finished "rm -f o e" &&
389 git rev-parse --verify "main@{May 25 2005}" >o 2>e &&
392 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
395 test_expect_success
'Query main@{2005-05-25} (before history)' '
396 test_when_finished "rm -f o e" &&
397 git rev-parse --verify main@{2005-05-25} >o 2>e &&
400 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
403 test_expect_success
'Query "main@{May 26 2005 23:31:59}" (1 second before history)' '
404 test_when_finished "rm -f o e" &&
405 git rev-parse --verify "main@{May 26 2005 23:31:59}" >o 2>e &&
408 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
411 test_expect_success
'Query "main@{May 26 2005 23:32:00}" (exactly history start)' '
412 test_when_finished "rm -f o e" &&
413 git rev-parse --verify "main@{May 26 2005 23:32:00}" >o 2>e &&
418 test_expect_success
'Query "main@{May 26 2005 23:32:30}" (first non-creation change)' '
419 test_when_finished "rm -f o e" &&
420 git rev-parse --verify "main@{May 26 2005 23:32:30}" >o 2>e &&
425 test_expect_success
'Query "main@{2005-05-26 23:33:01}" (middle of history with gap)' '
426 test_when_finished "rm -f o e" &&
427 git rev-parse --verify "main@{2005-05-26 23:33:01}" >o 2>e &&
431 test_expect_success
'Query "main@{2005-05-26 23:38:00}" (middle of history)' '
432 test_when_finished "rm -f o e" &&
433 git rev-parse --verify "main@{2005-05-26 23:38:00}" >o 2>e &&
438 test_expect_success
'Query "main@{2005-05-26 23:43:00}" (exact end of history)' '
439 test_when_finished "rm -f o e" &&
440 git rev-parse --verify "main@{2005-05-26 23:43:00}" >o 2>e &&
445 test_expect_success
'Query "main@{2005-05-28}" (past end of history)' '
446 test_when_finished "rm -f o e" &&
447 git rev-parse --verify "main@{2005-05-28}" >o 2>e &&
450 test_grep -F "warning: log for ref $m unexpectedly ended on $ld" e
456 test_expect_success REFFILES
'query reflog with gap' '
457 test_when_finished "git update-ref -d $m" &&
459 git update-ref $m $F &&
460 cat >.git/logs/$m <<-EOF &&
461 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
462 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
463 $D $F $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
466 git rev-parse --verify "main@{2005-05-26 23:33:01}" >actual 2>stderr &&
468 test_cmp expect actual &&
469 test_grep -F "warning: log for ref $m has gap after $gd" stderr
472 test_expect_success
'creating initial files' '
473 test_when_finished rm -f M &&
476 GIT_AUTHOR_DATE="2005-05-26 23:30" \
477 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
478 h_TEST=$(git rev-parse --verify HEAD) &&
479 echo The other day this did not work. >M &&
480 echo And then Bob told me how to fix it. >>M &&
482 GIT_AUTHOR_DATE="2005-05-26 23:41" \
483 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
484 h_OTHER=$(git rev-parse --verify HEAD) &&
485 GIT_AUTHOR_DATE="2005-05-26 23:44" \
486 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
487 h_FIXED=$(git rev-parse --verify HEAD) &&
488 echo Merged initial commit and a later commit. >M &&
489 echo $h_TEST >.git/MERGE_HEAD &&
490 GIT_AUTHOR_DATE="2005-05-26 23:45" \
491 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
492 h_MERGED=$(git rev-parse --verify HEAD)
496 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
497 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
498 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
499 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
501 test_expect_success
'git commit logged updates' '
502 test-tool ref-store main for-each-reflog-ent $m >actual &&
503 test_cmp expect actual
505 unset h_TEST h_OTHER h_FIXED h_MERGED
507 test_expect_success
'git cat-file blob main:F (expect OTHER)' '
508 test OTHER = $(git cat-file blob main:F)
510 test_expect_success
'git cat-file blob main@{2005-05-26 23:30}:F (expect TEST)' '
511 test TEST = $(git cat-file blob "main@{2005-05-26 23:30}:F")
513 test_expect_success
'git cat-file blob main@{2005-05-26 23:42}:F (expect OTHER)' '
514 test OTHER = $(git cat-file blob "main@{2005-05-26 23:42}:F")
517 # Test adding and deleting pseudorefs
519 test_expect_success
'given old value for missing pseudoref, do not create' '
520 test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
521 test_must_fail git rev-parse PSEUDOREF &&
522 test_grep "unable to resolve reference" err
525 test_expect_success
'create pseudoref' '
526 git update-ref PSEUDOREF $A &&
527 test $A = $(git rev-parse PSEUDOREF)
530 test_expect_success
'overwrite pseudoref with no old value given' '
531 git update-ref PSEUDOREF $B &&
532 test $B = $(git rev-parse PSEUDOREF)
535 test_expect_success
'overwrite pseudoref with correct old value' '
536 git update-ref PSEUDOREF $C $B &&
537 test $C = $(git rev-parse PSEUDOREF)
540 test_expect_success
'do not overwrite pseudoref with wrong old value' '
541 test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
542 test $C = $(git rev-parse PSEUDOREF) &&
543 test_grep "cannot lock ref.*expected" err
546 test_expect_success
'delete pseudoref' '
547 git update-ref -d PSEUDOREF &&
548 test_must_fail git rev-parse PSEUDOREF
551 test_expect_success
'do not delete pseudoref with wrong old value' '
552 git update-ref PSEUDOREF $A &&
553 test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
554 test $A = $(git rev-parse PSEUDOREF) &&
555 test_grep "cannot lock ref.*expected" err
558 test_expect_success
'delete pseudoref with correct old value' '
559 git update-ref -d PSEUDOREF $A &&
560 test_must_fail git rev-parse PSEUDOREF
563 test_expect_success
'create pseudoref with old OID zero' '
564 git update-ref PSEUDOREF $A $Z &&
565 test $A = $(git rev-parse PSEUDOREF)
568 test_expect_success
'do not overwrite pseudoref with old OID zero' '
569 test_when_finished git update-ref -d PSEUDOREF &&
570 test_must_fail git update-ref PSEUDOREF $B $Z 2>err &&
571 test $A = $(git rev-parse PSEUDOREF) &&
572 test_grep "already exists" err
582 pws
='path with space'
584 test_expect_success
'stdin test setup' '
585 echo "$pws" >"$pws" &&
590 test_expect_success
'-z fails without --stdin' '
591 test_must_fail git update-ref -z $m $m $m 2>err &&
592 test_grep "usage: git update-ref" err
595 test_expect_success
'stdin works with no input' '
597 git update-ref --stdin <stdin &&
598 git rev-parse --verify -q $m
601 test_expect_success
'stdin fails on empty line' '
603 test_must_fail git update-ref --stdin <stdin 2>err &&
604 grep "fatal: empty command in input" err
607 test_expect_success
'stdin fails on only whitespace' '
609 test_must_fail git update-ref --stdin <stdin 2>err &&
610 grep "fatal: whitespace before command: " err
613 test_expect_success
'stdin fails on leading whitespace' '
614 echo " create $a $m" >stdin &&
615 test_must_fail git update-ref --stdin <stdin 2>err &&
616 grep "fatal: whitespace before command: create $a $m" err
619 test_expect_success
'stdin fails on unknown command' '
620 echo "unknown $a" >stdin &&
621 test_must_fail git update-ref --stdin <stdin 2>err &&
622 grep "fatal: unknown command: unknown $a" err
625 test_expect_success
'stdin fails on unbalanced quotes' '
626 echo "create $a \"main" >stdin &&
627 test_must_fail git update-ref --stdin <stdin 2>err &&
628 grep "fatal: badly quoted argument: \\\"main" err
631 test_expect_success
'stdin fails on invalid escape' '
632 echo "create $a \"ma\zn\"" >stdin &&
633 test_must_fail git update-ref --stdin <stdin 2>err &&
634 grep "fatal: badly quoted argument: \\\"ma\\\\zn\\\"" err
637 test_expect_success
'stdin fails on junk after quoted argument' '
638 echo "create \"$a\"main" >stdin &&
639 test_must_fail git update-ref --stdin <stdin 2>err &&
640 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"main" err
643 test_expect_success
'stdin fails create with no ref' '
644 echo "create " >stdin &&
645 test_must_fail git update-ref --stdin <stdin 2>err &&
646 grep "fatal: create: missing <ref>" err
649 test_expect_success
'stdin fails create with no new value' '
650 echo "create $a" >stdin &&
651 test_must_fail git update-ref --stdin <stdin 2>err &&
652 grep "fatal: create $a: missing <newvalue>" err
655 test_expect_success
'stdin fails create with too many arguments' '
656 echo "create $a $m $m" >stdin &&
657 test_must_fail git update-ref --stdin <stdin 2>err &&
658 grep "fatal: create $a: extra input: $m" err
661 test_expect_success
'stdin fails update with no ref' '
662 echo "update " >stdin &&
663 test_must_fail git update-ref --stdin <stdin 2>err &&
664 grep "fatal: update: missing <ref>" err
667 test_expect_success
'stdin fails update with no new value' '
668 echo "update $a" >stdin &&
669 test_must_fail git update-ref --stdin <stdin 2>err &&
670 grep "fatal: update $a: missing <newvalue>" err
673 test_expect_success
'stdin fails update with too many arguments' '
674 echo "update $a $m $m $m" >stdin &&
675 test_must_fail git update-ref --stdin <stdin 2>err &&
676 grep "fatal: update $a: extra input: $m" err
679 test_expect_success
'stdin fails delete with no ref' '
680 echo "delete " >stdin &&
681 test_must_fail git update-ref --stdin <stdin 2>err &&
682 grep "fatal: delete: missing <ref>" err
685 test_expect_success
'stdin fails delete with too many arguments' '
686 echo "delete $a $m $m" >stdin &&
687 test_must_fail git update-ref --stdin <stdin 2>err &&
688 grep "fatal: delete $a: extra input: $m" err
691 test_expect_success
'stdin fails verify with too many arguments' '
692 echo "verify $a $m $m" >stdin &&
693 test_must_fail git update-ref --stdin <stdin 2>err &&
694 grep "fatal: verify $a: extra input: $m" err
697 test_expect_success
'stdin fails option with unknown name' '
698 echo "option unknown" >stdin &&
699 test_must_fail git update-ref --stdin <stdin 2>err &&
700 grep "fatal: option unknown: unknown" err
703 test_expect_success
'stdin fails with duplicate refs' '
709 test_must_fail git update-ref --stdin <stdin 2>err &&
710 test_grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
713 test_expect_success
'stdin create ref works' '
714 echo "create $a $m" >stdin &&
715 git update-ref --stdin <stdin &&
716 git rev-parse $m >expect &&
717 git rev-parse $a >actual &&
718 test_cmp expect actual
721 test_expect_success
'stdin does not create reflogs by default' '
722 test_when_finished "git update-ref -d $outside" &&
723 echo "create $outside $m" >stdin &&
724 git update-ref --stdin <stdin &&
725 git rev-parse $m >expect &&
726 git rev-parse $outside >actual &&
727 test_cmp expect actual &&
728 test_must_fail git reflog exists $outside
731 test_expect_success
'stdin creates reflogs with --create-reflog' '
732 test_when_finished "git update-ref -d $outside" &&
733 echo "create $outside $m" >stdin &&
734 git update-ref --create-reflog --stdin <stdin &&
735 git rev-parse $m >expect &&
736 git rev-parse $outside >actual &&
737 test_cmp expect actual &&
738 git reflog exists $outside
741 test_expect_success
'stdin succeeds with quoted argument' '
742 git update-ref -d $a &&
743 echo "create $a \"$m\"" >stdin &&
744 git update-ref --stdin <stdin &&
745 git rev-parse $m >expect &&
746 git rev-parse $a >actual &&
747 test_cmp expect actual
750 test_expect_success
'stdin succeeds with escaped character' '
751 git update-ref -d $a &&
752 echo "create $a \"ma\\151n\"" >stdin &&
753 git update-ref --stdin <stdin &&
754 git rev-parse $m >expect &&
755 git rev-parse $a >actual &&
756 test_cmp expect actual
759 test_expect_success
'stdin update ref creates with zero old value' '
760 echo "update $b $m $Z" >stdin &&
761 git update-ref --stdin <stdin &&
762 git rev-parse $m >expect &&
763 git rev-parse $b >actual &&
764 test_cmp expect actual &&
768 test_expect_success
'stdin update ref creates with empty old value' '
769 echo "update $b $m $E" >stdin &&
770 git update-ref --stdin <stdin &&
771 git rev-parse $m >expect &&
772 git rev-parse $b >actual &&
773 test_cmp expect actual
776 test_expect_success
'stdin create ref works with path with space to blob' '
777 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
778 git update-ref --stdin <stdin &&
779 git rev-parse "$m:$pws" >expect &&
780 git rev-parse refs/blobs/pws >actual &&
781 test_cmp expect actual &&
782 git update-ref -d refs/blobs/pws
785 test_expect_success
'stdin update ref fails with wrong old value' '
786 echo "update $c $m $m~1" >stdin &&
787 test_must_fail git update-ref --stdin <stdin 2>err &&
788 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
789 test_must_fail git rev-parse --verify -q $c
792 test_expect_success
'stdin update ref fails with bad old value' '
793 echo "update $c $m does-not-exist" >stdin &&
794 test_must_fail git update-ref --stdin <stdin 2>err &&
795 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
796 test_must_fail git rev-parse --verify -q $c
799 test_expect_success
'stdin create ref fails with bad new value' '
800 echo "create $c does-not-exist" >stdin &&
801 test_must_fail git update-ref --stdin <stdin 2>err &&
802 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
803 test_must_fail git rev-parse --verify -q $c
806 test_expect_success
'stdin create ref fails with zero new value' '
807 echo "create $c " >stdin &&
808 test_must_fail git update-ref --stdin <stdin 2>err &&
809 grep "fatal: create $c: zero <newvalue>" err &&
810 test_must_fail git rev-parse --verify -q $c
813 test_expect_success
'stdin update ref works with right old value' '
814 echo "update $b $m~1 $m" >stdin &&
815 git update-ref --stdin <stdin &&
816 git rev-parse $m~1 >expect &&
817 git rev-parse $b >actual &&
818 test_cmp expect actual
821 test_expect_success
'stdin delete ref fails with wrong old value' '
822 echo "delete $a $m~1" >stdin &&
823 test_must_fail git update-ref --stdin <stdin 2>err &&
824 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
825 git rev-parse $m >expect &&
826 git rev-parse $a >actual &&
827 test_cmp expect actual
830 test_expect_success
'stdin delete ref fails with zero old value' '
831 echo "delete $a " >stdin &&
832 test_must_fail git update-ref --stdin <stdin 2>err &&
833 grep "fatal: delete $a: zero <oldvalue>" err &&
834 git rev-parse $m >expect &&
835 git rev-parse $a >actual &&
836 test_cmp expect actual
839 test_expect_success
'stdin update symref works option no-deref' '
840 git symbolic-ref TESTSYMREF $b &&
843 update TESTSYMREF $a $b
845 git update-ref --stdin <stdin &&
846 git rev-parse TESTSYMREF >expect &&
847 git rev-parse $a >actual &&
848 test_cmp expect actual &&
849 git rev-parse $m~1 >expect &&
850 git rev-parse $b >actual &&
851 test_cmp expect actual
854 test_expect_success
'stdin delete symref works option no-deref' '
855 git symbolic-ref TESTSYMREF $b &&
860 git update-ref --stdin <stdin &&
861 test_must_fail git rev-parse --verify -q TESTSYMREF &&
862 git rev-parse $m~1 >expect &&
863 git rev-parse $b >actual &&
864 test_cmp expect actual
867 test_expect_success
'stdin update symref works flag --no-deref' '
868 git symbolic-ref TESTSYMREFONE $b &&
869 git symbolic-ref TESTSYMREFTWO $b &&
871 update TESTSYMREFONE $a $b
872 update TESTSYMREFTWO $a $b
874 git update-ref --no-deref --stdin <stdin &&
875 git rev-parse TESTSYMREFONE TESTSYMREFTWO >expect &&
876 git rev-parse $a $a >actual &&
877 test_cmp expect actual &&
878 git rev-parse $m~1 >expect &&
879 git rev-parse $b >actual &&
880 test_cmp expect actual
883 test_expect_success
'stdin delete symref works flag --no-deref' '
884 git symbolic-ref TESTSYMREFONE $b &&
885 git symbolic-ref TESTSYMREFTWO $b &&
887 delete TESTSYMREFONE $b
888 delete TESTSYMREFTWO $b
890 git update-ref --no-deref --stdin <stdin &&
891 test_must_fail git rev-parse --verify -q TESTSYMREFONE &&
892 test_must_fail git rev-parse --verify -q TESTSYMREFTWO &&
893 git rev-parse $m~1 >expect &&
894 git rev-parse $b >actual &&
895 test_cmp expect actual
898 test_expect_success
'stdin delete ref works with right old value' '
899 echo "delete $b $m~1" >stdin &&
900 git update-ref --stdin <stdin &&
901 test_must_fail git rev-parse --verify -q $b
904 test_expect_success
'stdin update/create/verify combination works' '
910 git update-ref --stdin <stdin &&
911 git rev-parse $m >expect &&
912 git rev-parse $a >actual &&
913 test_cmp expect actual &&
914 git rev-parse $b >actual &&
915 test_cmp expect actual &&
916 test_must_fail git rev-parse --verify -q $c
919 test_expect_success
'stdin verify succeeds for correct value' '
920 git rev-parse $m >expect &&
921 echo "verify $m $m" >stdin &&
922 git update-ref --stdin <stdin &&
923 git rev-parse $m >actual &&
924 test_cmp expect actual
927 test_expect_success
'stdin verify succeeds for missing reference' '
928 echo "verify refs/heads/missing $Z" >stdin &&
929 git update-ref --stdin <stdin &&
930 test_must_fail git rev-parse --verify -q refs/heads/missing
933 test_expect_success
'stdin verify treats no value as missing' '
934 echo "verify refs/heads/missing" >stdin &&
935 git update-ref --stdin <stdin &&
936 test_must_fail git rev-parse --verify -q refs/heads/missing
939 test_expect_success
'stdin verify fails for wrong value' '
940 git rev-parse $m >expect &&
941 echo "verify $m $m~1" >stdin &&
942 test_must_fail git update-ref --stdin <stdin &&
943 git rev-parse $m >actual &&
944 test_cmp expect actual
947 test_expect_success
'stdin verify fails for mistaken null value' '
948 git rev-parse $m >expect &&
949 echo "verify $m $Z" >stdin &&
950 test_must_fail git update-ref --stdin <stdin &&
951 git rev-parse $m >actual &&
952 test_cmp expect actual
955 test_expect_success
'stdin verify fails for mistaken empty value' '
956 M=$(git rev-parse $m) &&
957 test_when_finished "git update-ref $m $M" &&
958 git rev-parse $m >expect &&
959 echo "verify $m" >stdin &&
960 test_must_fail git update-ref --stdin <stdin &&
961 git rev-parse $m >actual &&
962 test_cmp expect actual
965 test_expect_success
'stdin update refs works with identity updates' '
971 git update-ref --stdin <stdin &&
972 git rev-parse $m >expect &&
973 git rev-parse $a >actual &&
974 test_cmp expect actual &&
975 git rev-parse $b >actual &&
976 test_cmp expect actual &&
977 test_must_fail git rev-parse --verify -q $c
980 test_expect_success
'stdin update refs fails with wrong old value' '
981 git update-ref $c $m &&
987 test_must_fail git update-ref --stdin <stdin 2>err &&
988 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
989 git rev-parse $m >expect &&
990 git rev-parse $a >actual &&
991 test_cmp expect actual &&
992 git rev-parse $b >actual &&
993 test_cmp expect actual &&
994 git rev-parse $c >actual &&
995 test_cmp expect actual
998 test_expect_success
'stdin delete refs works with packed and loose refs' '
999 git pack-refs --all &&
1000 git update-ref $c $m~1 &&
1001 cat >stdin <<-EOF &&
1006 git update-ref --stdin <stdin &&
1007 test_must_fail git rev-parse --verify -q $a &&
1008 test_must_fail git rev-parse --verify -q $b &&
1009 test_must_fail git rev-parse --verify -q $c
1012 test_expect_success
'stdin -z works on empty input' '
1014 git update-ref -z --stdin <stdin &&
1015 git rev-parse --verify -q $m
1018 test_expect_success
'stdin -z fails on empty line' '
1020 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1021 grep "fatal: whitespace before command: " err
1024 test_expect_success
'stdin -z fails on empty command' '
1025 printf $F "" >stdin &&
1026 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1027 grep "fatal: empty command in input" err
1030 test_expect_success
'stdin -z fails on only whitespace' '
1031 printf $F " " >stdin &&
1032 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1033 grep "fatal: whitespace before command: " err
1036 test_expect_success
'stdin -z fails on leading whitespace' '
1037 printf $F " create $a" "$m" >stdin &&
1038 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1039 grep "fatal: whitespace before command: create $a" err
1042 test_expect_success
'stdin -z fails on unknown command' '
1043 printf $F "unknown $a" >stdin &&
1044 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1045 grep "fatal: unknown command: unknown $a" err
1048 test_expect_success
'stdin -z fails create with no ref' '
1049 printf $F "create " >stdin &&
1050 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1051 grep "fatal: create: missing <ref>" err
1054 test_expect_success
'stdin -z fails create with no new value' '
1055 printf $F "create $a" >stdin &&
1056 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1057 grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
1060 test_expect_success
'stdin -z fails create with too many arguments' '
1061 printf $F "create $a" "$m" "$m" >stdin &&
1062 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1063 grep "fatal: unknown command: $m" err
1066 test_expect_success
'stdin -z fails update with no ref' '
1067 printf $F "update " >stdin &&
1068 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1069 grep "fatal: update: missing <ref>" err
1072 test_expect_success
'stdin -z fails update with too few args' '
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 <oldvalue>" err
1078 test_expect_success
'stdin -z emits warning with empty new value' '
1079 git update-ref $a $m &&
1080 printf $F "update $a" "" "" >stdin &&
1081 git update-ref -z --stdin <stdin 2>err &&
1082 grep "warning: update $a: missing <newvalue>, treating as zero" err &&
1083 test_must_fail git rev-parse --verify -q $a
1086 test_expect_success
'stdin -z fails update with no new value' '
1087 printf $F "update $a" >stdin &&
1088 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1089 grep "fatal: update $a: unexpected end of input when reading <newvalue>" err
1092 test_expect_success
'stdin -z fails update with no old value' '
1093 printf $F "update $a" "$m" >stdin &&
1094 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1095 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
1098 test_expect_success
'stdin -z fails update with too many arguments' '
1099 printf $F "update $a" "$m" "$m" "$m" >stdin &&
1100 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1101 grep "fatal: unknown command: $m" err
1104 test_expect_success
'stdin -z fails delete with no ref' '
1105 printf $F "delete " >stdin &&
1106 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1107 grep "fatal: delete: missing <ref>" err
1110 test_expect_success
'stdin -z fails delete with no old value' '
1111 printf $F "delete $a" >stdin &&
1112 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1113 grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
1116 test_expect_success
'stdin -z fails delete with too many arguments' '
1117 printf $F "delete $a" "$m" "$m" >stdin &&
1118 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1119 grep "fatal: unknown command: $m" err
1122 test_expect_success
'stdin -z fails verify with too many arguments' '
1123 printf $F "verify $a" "$m" "$m" >stdin &&
1124 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1125 grep "fatal: unknown command: $m" err
1128 test_expect_success
'stdin -z fails verify with no old value' '
1129 printf $F "verify $a" >stdin &&
1130 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1131 grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err
1134 test_expect_success
'stdin -z fails option with unknown name' '
1135 printf $F "option unknown" >stdin &&
1136 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1137 grep "fatal: option unknown: unknown" err
1140 test_expect_success
'stdin -z fails with duplicate refs' '
1141 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
1142 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1143 test_grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
1146 test_expect_success
'stdin -z create ref works' '
1147 printf $F "create $a" "$m" >stdin &&
1148 git update-ref -z --stdin <stdin &&
1149 git rev-parse $m >expect &&
1150 git rev-parse $a >actual &&
1151 test_cmp expect actual
1154 test_expect_success
'stdin -z update ref creates with zero old value' '
1155 printf $F "update $b" "$m" "$Z" >stdin &&
1156 git update-ref -z --stdin <stdin &&
1157 git rev-parse $m >expect &&
1158 git rev-parse $b >actual &&
1159 test_cmp expect actual &&
1160 git update-ref -d $b
1163 test_expect_success
'stdin -z update ref creates with empty old value' '
1164 printf $F "update $b" "$m" "" >stdin &&
1165 git update-ref -z --stdin <stdin &&
1166 git rev-parse $m >expect &&
1167 git rev-parse $b >actual &&
1168 test_cmp expect actual
1171 test_expect_success
'stdin -z create ref works with path with space to blob' '
1172 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
1173 git update-ref -z --stdin <stdin &&
1174 git rev-parse "$m:$pws" >expect &&
1175 git rev-parse refs/blobs/pws >actual &&
1176 test_cmp expect actual &&
1177 git update-ref -d refs/blobs/pws
1180 test_expect_success
'stdin -z update ref fails with wrong old value' '
1181 printf $F "update $c" "$m" "$m~1" >stdin &&
1182 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1183 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1184 test_must_fail git rev-parse --verify -q $c
1187 test_expect_success
'stdin -z update ref fails with bad old value' '
1188 printf $F "update $c" "$m" "does-not-exist" >stdin &&
1189 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1190 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
1191 test_must_fail git rev-parse --verify -q $c
1194 test_expect_success
'stdin -z create ref fails when ref exists' '
1195 git update-ref $c $m &&
1196 git rev-parse "$c" >expect &&
1197 printf $F "create $c" "$m~1" >stdin &&
1198 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1199 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1200 git rev-parse "$c" >actual &&
1201 test_cmp expect actual
1204 test_expect_success
'stdin -z create ref fails with bad new value' '
1205 git update-ref -d "$c" &&
1206 printf $F "create $c" "does-not-exist" >stdin &&
1207 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1208 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
1209 test_must_fail git rev-parse --verify -q $c
1212 test_expect_success
'stdin -z create ref fails with empty new value' '
1213 printf $F "create $c" "" >stdin &&
1214 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1215 grep "fatal: create $c: missing <newvalue>" err &&
1216 test_must_fail git rev-parse --verify -q $c
1219 test_expect_success
'stdin -z update ref works with right old value' '
1220 printf $F "update $b" "$m~1" "$m" >stdin &&
1221 git update-ref -z --stdin <stdin &&
1222 git rev-parse $m~1 >expect &&
1223 git rev-parse $b >actual &&
1224 test_cmp expect actual
1227 test_expect_success
'stdin -z delete ref fails with wrong old value' '
1228 printf $F "delete $a" "$m~1" >stdin &&
1229 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1230 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
1231 git rev-parse $m >expect &&
1232 git rev-parse $a >actual &&
1233 test_cmp expect actual
1236 test_expect_success
'stdin -z delete ref fails with zero old value' '
1237 printf $F "delete $a" "$Z" >stdin &&
1238 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1239 grep "fatal: delete $a: zero <oldvalue>" err &&
1240 git rev-parse $m >expect &&
1241 git rev-parse $a >actual &&
1242 test_cmp expect actual
1245 test_expect_success
'stdin -z update symref works option no-deref' '
1246 git symbolic-ref TESTSYMREF $b &&
1247 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
1248 git update-ref -z --stdin <stdin &&
1249 git rev-parse TESTSYMREF >expect &&
1250 git rev-parse $a >actual &&
1251 test_cmp expect actual &&
1252 git rev-parse $m~1 >expect &&
1253 git rev-parse $b >actual &&
1254 test_cmp expect actual
1257 test_expect_success
'stdin -z delete symref works option no-deref' '
1258 git symbolic-ref TESTSYMREF $b &&
1259 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
1260 git update-ref -z --stdin <stdin &&
1261 test_must_fail git rev-parse --verify -q TESTSYMREF &&
1262 git rev-parse $m~1 >expect &&
1263 git rev-parse $b >actual &&
1264 test_cmp expect actual
1267 test_expect_success
'stdin -z delete ref works with right old value' '
1268 printf $F "delete $b" "$m~1" >stdin &&
1269 git update-ref -z --stdin <stdin &&
1270 test_must_fail git rev-parse --verify -q $b
1273 test_expect_success
'stdin -z update/create/verify combination works' '
1274 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
1275 git update-ref -z --stdin <stdin &&
1276 git rev-parse $m >expect &&
1277 git rev-parse $a >actual &&
1278 test_cmp expect actual &&
1279 git rev-parse $b >actual &&
1280 test_cmp expect actual &&
1281 test_must_fail git rev-parse --verify -q $c
1284 test_expect_success
'stdin -z verify succeeds for correct value' '
1285 git rev-parse $m >expect &&
1286 printf $F "verify $m" "$m" >stdin &&
1287 git update-ref -z --stdin <stdin &&
1288 git rev-parse $m >actual &&
1289 test_cmp expect actual
1292 test_expect_success
'stdin -z verify succeeds for missing reference' '
1293 printf $F "verify refs/heads/missing" "$Z" >stdin &&
1294 git update-ref -z --stdin <stdin &&
1295 test_must_fail git rev-parse --verify -q refs/heads/missing
1298 test_expect_success
'stdin -z verify treats no value as missing' '
1299 printf $F "verify refs/heads/missing" "" >stdin &&
1300 git update-ref -z --stdin <stdin &&
1301 test_must_fail git rev-parse --verify -q refs/heads/missing
1304 test_expect_success
'stdin -z verify fails for wrong value' '
1305 git rev-parse $m >expect &&
1306 printf $F "verify $m" "$m~1" >stdin &&
1307 test_must_fail git update-ref -z --stdin <stdin &&
1308 git rev-parse $m >actual &&
1309 test_cmp expect actual
1312 test_expect_success
'stdin -z verify fails for mistaken null value' '
1313 git rev-parse $m >expect &&
1314 printf $F "verify $m" "$Z" >stdin &&
1315 test_must_fail git update-ref -z --stdin <stdin &&
1316 git rev-parse $m >actual &&
1317 test_cmp expect actual
1320 test_expect_success
'stdin -z verify fails for mistaken empty value' '
1321 M=$(git rev-parse $m) &&
1322 test_when_finished "git update-ref $m $M" &&
1323 git rev-parse $m >expect &&
1324 printf $F "verify $m" "" >stdin &&
1325 test_must_fail git update-ref -z --stdin <stdin &&
1326 git rev-parse $m >actual &&
1327 test_cmp expect actual
1330 test_expect_success
'stdin -z update refs works with identity updates' '
1331 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
1332 git update-ref -z --stdin <stdin &&
1333 git rev-parse $m >expect &&
1334 git rev-parse $a >actual &&
1335 test_cmp expect actual &&
1336 git rev-parse $b >actual &&
1337 test_cmp expect actual &&
1338 test_must_fail git rev-parse --verify -q $c
1341 test_expect_success
'stdin -z update refs fails with wrong old value' '
1342 git update-ref $c $m &&
1343 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
1344 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1345 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1346 git rev-parse $m >expect &&
1347 git rev-parse $a >actual &&
1348 test_cmp expect actual &&
1349 git rev-parse $b >actual &&
1350 test_cmp expect actual &&
1351 git rev-parse $c >actual &&
1352 test_cmp expect actual
1355 test_expect_success
'stdin -z delete refs works with packed and loose refs' '
1356 git pack-refs --all &&
1357 git update-ref $c $m~1 &&
1358 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
1359 git update-ref -z --stdin <stdin &&
1360 test_must_fail git rev-parse --verify -q $a &&
1361 test_must_fail git rev-parse --verify -q $b &&
1362 test_must_fail git rev-parse --verify -q $c
1365 test_expect_success
'fails with duplicate HEAD update' '
1366 git branch target1 $A &&
1367 git checkout target1 &&
1368 cat >stdin <<-EOF &&
1369 update refs/heads/target1 $C
1373 test_must_fail git update-ref --stdin <stdin 2>err &&
1374 test_grep "fatal: multiple updates for '\''HEAD'\'' (including one via its referent .refs/heads/target1.) are not allowed" err &&
1375 echo "refs/heads/target1" >expect &&
1376 git symbolic-ref HEAD >actual &&
1377 test_cmp expect actual &&
1378 echo "$A" >expect &&
1379 git rev-parse refs/heads/target1 >actual &&
1380 test_cmp expect actual
1383 test_expect_success
'fails with duplicate ref update via symref' '
1384 git branch target2 $A &&
1385 git symbolic-ref refs/heads/symref2 refs/heads/target2 &&
1386 cat >stdin <<-EOF &&
1387 update refs/heads/target2 $C
1388 update refs/heads/symref2 $B
1390 test_must_fail git update-ref --stdin <stdin 2>err &&
1391 test_grep "fatal: multiple updates for '\''refs/heads/target2'\'' (including one via symref .refs/heads/symref2.) are not allowed" err &&
1392 echo "refs/heads/target2" >expect &&
1393 git symbolic-ref refs/heads/symref2 >actual &&
1394 test_cmp expect actual &&
1395 echo "$A" >expect &&
1396 git rev-parse refs/heads/target2 >actual &&
1397 test_cmp expect actual
1400 test_expect_success ULIMIT_FILE_DESCRIPTORS
'large transaction creating branches does not burst open file limit' '
1402 for i in $(test_seq 33)
1404 echo "create refs/heads/$i HEAD" || exit 1
1405 done >large_input &&
1406 run_with_limited_open_files git update-ref --stdin <large_input &&
1407 git rev-parse --verify -q refs/heads/33
1411 test_expect_success ULIMIT_FILE_DESCRIPTORS
'large transaction deleting branches does not burst open file limit' '
1413 for i in $(test_seq 33)
1415 echo "delete refs/heads/$i HEAD" || exit 1
1416 done >large_input &&
1417 run_with_limited_open_files git update-ref --stdin <large_input &&
1418 test_must_fail git rev-parse --verify -q refs/heads/33
1422 test_expect_success
'handle per-worktree refs in refs/bisect' '
1423 git commit --allow-empty -m "initial commit" &&
1424 git worktree add -b branch worktree &&
1427 git commit --allow-empty -m "test commit" &&
1428 git for-each-ref >for-each-ref.out &&
1429 ! grep refs/bisect for-each-ref.out &&
1430 git update-ref refs/bisect/something HEAD &&
1431 git rev-parse refs/bisect/something >../worktree-head &&
1432 git for-each-ref | grep refs/bisect/something
1434 git show-ref >actual &&
1435 ! grep 'refs
/bisect
' actual &&
1436 test_must_fail git rev-parse refs/bisect/something &&
1437 git update-ref refs/bisect/something HEAD &&
1438 git rev-parse refs/bisect/something >main-head &&
1439 ! test_cmp main-head worktree-head
1442 test_expect_success
'transaction handles empty commit' '
1443 cat >stdin <<-EOF &&
1448 git update-ref --stdin <stdin >actual &&
1449 printf "%s: ok\n" start prepare commit >expect &&
1450 test_cmp expect actual
1453 test_expect_success
'transaction handles empty commit with missing prepare' '
1454 cat >stdin <<-EOF &&
1458 git update-ref --stdin <stdin >actual &&
1459 printf "%s: ok\n" start commit >expect &&
1460 test_cmp expect actual
1463 test_expect_success
'transaction handles sole commit' '
1464 cat >stdin <<-EOF &&
1467 git update-ref --stdin <stdin >actual &&
1468 printf "%s: ok\n" commit >expect &&
1469 test_cmp expect actual
1472 test_expect_success
'transaction handles empty abort' '
1473 cat >stdin <<-EOF &&
1478 git update-ref --stdin <stdin >actual &&
1479 printf "%s: ok\n" start prepare abort >expect &&
1480 test_cmp expect actual
1483 test_expect_success
'transaction exits on multiple aborts' '
1484 cat >stdin <<-EOF &&
1488 test_must_fail git update-ref --stdin <stdin >actual 2>err &&
1489 printf "%s: ok\n" abort >expect &&
1490 test_cmp expect actual &&
1491 grep "fatal: transaction is closed" err
1494 test_expect_success
'transaction exits on start after prepare' '
1495 cat >stdin <<-EOF &&
1499 test_must_fail git update-ref --stdin <stdin 2>err >actual &&
1500 printf "%s: ok\n" prepare >expect &&
1501 test_cmp expect actual &&
1502 grep "fatal: prepared transactions can only be closed" err
1505 test_expect_success
'transaction handles empty abort with missing prepare' '
1506 cat >stdin <<-EOF &&
1510 git update-ref --stdin <stdin >actual &&
1511 printf "%s: ok\n" start abort >expect &&
1512 test_cmp expect actual
1515 test_expect_success
'transaction handles sole abort' '
1516 cat >stdin <<-EOF &&
1519 git update-ref --stdin <stdin >actual &&
1520 printf "%s: ok\n" abort >expect &&
1521 test_cmp expect actual
1524 test_expect_success
'transaction can handle commit' '
1525 cat >stdin <<-EOF &&
1530 git update-ref --stdin <stdin >actual &&
1531 printf "%s: ok\n" start commit >expect &&
1532 test_cmp expect actual &&
1533 git rev-parse HEAD >expect &&
1534 git rev-parse $a >actual &&
1535 test_cmp expect actual
1538 test_expect_success
'transaction can handle abort' '
1539 cat >stdin <<-EOF &&
1544 git update-ref --stdin <stdin >actual &&
1545 printf "%s: ok\n" start abort >expect &&
1546 test_cmp expect actual &&
1547 test_must_fail git show-ref --verify -q $b
1550 test_expect_success
'transaction aborts by default' '
1551 cat >stdin <<-EOF &&
1555 git update-ref --stdin <stdin >actual &&
1556 printf "%s: ok\n" start >expect &&
1557 test_cmp expect actual &&
1558 test_must_fail git show-ref --verify -q $b
1561 test_expect_success
'transaction with prepare aborts by default' '
1562 cat >stdin <<-EOF &&
1567 git update-ref --stdin <stdin >actual &&
1568 printf "%s: ok\n" start prepare >expect &&
1569 test_cmp expect actual &&
1570 test_must_fail git show-ref --verify -q $b
1573 test_expect_success
'transaction can commit multiple times' '
1574 cat >stdin <<-EOF &&
1576 create refs/heads/branch-1 $A
1579 create refs/heads/branch-2 $B
1582 git update-ref --stdin <stdin >actual &&
1583 printf "%s: ok\n" start commit start commit >expect &&
1584 test_cmp expect actual &&
1585 echo "$A" >expect &&
1586 git rev-parse refs/heads/branch-1 >actual &&
1587 test_cmp expect actual &&
1588 echo "$B" >expect &&
1589 git rev-parse refs/heads/branch-2 >actual &&
1590 test_cmp expect actual
1593 test_expect_success
'transaction can create and delete' '
1594 cat >stdin <<-EOF &&
1596 create refs/heads/create-and-delete $A
1599 delete refs/heads/create-and-delete $A
1602 git update-ref --stdin <stdin >actual &&
1603 printf "%s: ok\n" start commit start commit >expect &&
1604 test_cmp expect actual &&
1605 test_must_fail git show-ref --verify refs/heads/create-and-delete
1608 test_expect_success
'transaction can commit after abort' '
1609 cat >stdin <<-EOF &&
1611 create refs/heads/abort $A
1614 create refs/heads/abort $A
1617 git update-ref --stdin <stdin >actual &&
1618 printf "%s: ok\n" start abort start commit >expect &&
1619 echo "$A" >expect &&
1620 git rev-parse refs/heads/abort >actual &&
1621 test_cmp expect actual
1624 test_expect_success
'transaction cannot restart ongoing transaction' '
1625 cat >stdin <<-EOF &&
1627 create refs/heads/restart $A
1631 test_must_fail git update-ref --stdin <stdin >actual &&
1632 printf "%s: ok\n" start >expect &&
1633 test_cmp expect actual &&
1634 test_must_fail git show-ref --verify refs/heads/restart
1637 test_expect_success PIPE
'transaction flushes status updates' '
1639 (git update-ref --stdin <in >out &) &&
1643 test_when_finished "exec 9>&-" &&
1644 test_when_finished "exec 8<&-" &&
1647 echo "start: ok" >expected &&
1649 echo "$line" >actual &&
1650 test_cmp expected actual &&
1652 echo "create refs/heads/flush $A" >&9 &&
1655 echo "prepare: ok" >expected &&
1657 echo "$line" >actual &&
1658 test_cmp expected actual &&
1660 # This must now fail given that we have locked the ref.
1661 test_must_fail git update-ref refs/heads/flush $B 2>stderr &&
1662 grep "fatal: update_ref failed for ref ${SQ}refs/heads/flush${SQ}: cannot lock ref" stderr &&
1665 echo "commit: ok" >expected &&
1667 echo "$line" >actual &&
1668 test_cmp expected actual
1671 test_expect_success REFFILES
'directory not created deleting packed ref' '
1672 git branch d1/d2/r1 HEAD &&
1673 git pack-refs --all &&
1674 test_path_is_missing .git/refs/heads/d1/d2 &&
1675 git update-ref -d refs/heads/d1/d2/r1 &&
1676 test_path_is_missing .git/refs/heads/d1/d2 &&
1677 test_path_is_missing .git/refs/heads/d1