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 $m $D &&
361 cat >.git/logs/$m <<-EOF
362 $Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
363 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
364 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
365 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
366 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
370 ed
="Thu, 26 May 2005 18:32:00 -0500"
371 gd
="Thu, 26 May 2005 18:33:00 -0500"
372 ld
="Thu, 26 May 2005 18:43:00 -0500"
373 test_expect_success
'Query "main@{May 25 2005}" (before history)' '
374 test_when_finished "rm -f o e" &&
375 git rev-parse --verify "main@{May 25 2005}" >o 2>e &&
378 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
381 test_expect_success
'Query main@{2005-05-25} (before history)' '
382 test_when_finished "rm -f o e" &&
383 git rev-parse --verify main@{2005-05-25} >o 2>e &&
386 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
389 test_expect_success
'Query "main@{May 26 2005 23:31:59}" (1 second before history)' '
390 test_when_finished "rm -f o e" &&
391 git rev-parse --verify "main@{May 26 2005 23:31:59}" >o 2>e &&
394 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
397 test_expect_success
'Query "main@{May 26 2005 23:32:00}" (exactly history start)' '
398 test_when_finished "rm -f o e" &&
399 git rev-parse --verify "main@{May 26 2005 23:32:00}" >o 2>e &&
404 test_expect_success
'Query "main@{May 26 2005 23:32:30}" (first non-creation change)' '
405 test_when_finished "rm -f o e" &&
406 git rev-parse --verify "main@{May 26 2005 23:32:30}" >o 2>e &&
411 test_expect_success
'Query "main@{2005-05-26 23:33:01}" (middle of history with gap)' '
412 test_when_finished "rm -f o e" &&
413 git rev-parse --verify "main@{2005-05-26 23:33:01}" >o 2>e &&
416 test_grep -F "warning: log for ref $m has gap after $gd" e
418 test_expect_success
'Query "main@{2005-05-26 23:38:00}" (middle of history)' '
419 test_when_finished "rm -f o e" &&
420 git rev-parse --verify "main@{2005-05-26 23:38:00}" >o 2>e &&
425 test_expect_success
'Query "main@{2005-05-26 23:43:00}" (exact end of history)' '
426 test_when_finished "rm -f o e" &&
427 git rev-parse --verify "main@{2005-05-26 23:43:00}" >o 2>e &&
432 test_expect_success
'Query "main@{2005-05-28}" (past end of history)' '
433 test_when_finished "rm -f o e" &&
434 git rev-parse --verify "main@{2005-05-28}" >o 2>e &&
437 test_grep -F "warning: log for ref $m unexpectedly ended on $ld" e
443 test_expect_success
'creating initial files' '
444 test_when_finished rm -f M &&
447 GIT_AUTHOR_DATE="2005-05-26 23:30" \
448 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
449 h_TEST=$(git rev-parse --verify HEAD) &&
450 echo The other day this did not work. >M &&
451 echo And then Bob told me how to fix it. >>M &&
453 GIT_AUTHOR_DATE="2005-05-26 23:41" \
454 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
455 h_OTHER=$(git rev-parse --verify HEAD) &&
456 GIT_AUTHOR_DATE="2005-05-26 23:44" \
457 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
458 h_FIXED=$(git rev-parse --verify HEAD) &&
459 echo Merged initial commit and a later commit. >M &&
460 echo $h_TEST >.git/MERGE_HEAD &&
461 GIT_AUTHOR_DATE="2005-05-26 23:45" \
462 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
463 h_MERGED=$(git rev-parse --verify HEAD)
467 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
468 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
469 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
470 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
472 test_expect_success
'git commit logged updates' '
473 test-tool ref-store main for-each-reflog-ent $m >actual &&
474 test_cmp expect actual
476 unset h_TEST h_OTHER h_FIXED h_MERGED
478 test_expect_success
'git cat-file blob main:F (expect OTHER)' '
479 test OTHER = $(git cat-file blob main:F)
481 test_expect_success
'git cat-file blob main@{2005-05-26 23:30}:F (expect TEST)' '
482 test TEST = $(git cat-file blob "main@{2005-05-26 23:30}:F")
484 test_expect_success
'git cat-file blob main@{2005-05-26 23:42}:F (expect OTHER)' '
485 test OTHER = $(git cat-file blob "main@{2005-05-26 23:42}:F")
488 # Test adding and deleting pseudorefs
490 test_expect_success
'given old value for missing pseudoref, do not create' '
491 test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
492 test_must_fail git rev-parse PSEUDOREF &&
493 test_grep "unable to resolve reference" err
496 test_expect_success
'create pseudoref' '
497 git update-ref PSEUDOREF $A &&
498 test $A = $(git rev-parse PSEUDOREF)
501 test_expect_success
'overwrite pseudoref with no old value given' '
502 git update-ref PSEUDOREF $B &&
503 test $B = $(git rev-parse PSEUDOREF)
506 test_expect_success
'overwrite pseudoref with correct old value' '
507 git update-ref PSEUDOREF $C $B &&
508 test $C = $(git rev-parse PSEUDOREF)
511 test_expect_success
'do not overwrite pseudoref with wrong old value' '
512 test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
513 test $C = $(git rev-parse PSEUDOREF) &&
514 test_grep "cannot lock ref.*expected" err
517 test_expect_success
'delete pseudoref' '
518 git update-ref -d PSEUDOREF &&
519 test_must_fail git rev-parse PSEUDOREF
522 test_expect_success
'do not delete pseudoref with wrong old value' '
523 git update-ref PSEUDOREF $A &&
524 test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
525 test $A = $(git rev-parse PSEUDOREF) &&
526 test_grep "cannot lock ref.*expected" err
529 test_expect_success
'delete pseudoref with correct old value' '
530 git update-ref -d PSEUDOREF $A &&
531 test_must_fail git rev-parse PSEUDOREF
534 test_expect_success
'create pseudoref with old OID zero' '
535 git update-ref PSEUDOREF $A $Z &&
536 test $A = $(git rev-parse PSEUDOREF)
539 test_expect_success
'do not overwrite pseudoref with old OID zero' '
540 test_when_finished git update-ref -d PSEUDOREF &&
541 test_must_fail git update-ref PSEUDOREF $B $Z 2>err &&
542 test $A = $(git rev-parse PSEUDOREF) &&
543 test_grep "already exists" err
553 pws
='path with space'
555 test_expect_success
'stdin test setup' '
556 echo "$pws" >"$pws" &&
561 test_expect_success
'-z fails without --stdin' '
562 test_must_fail git update-ref -z $m $m $m 2>err &&
563 test_grep "usage: git update-ref" err
566 test_expect_success
'stdin works with no input' '
568 git update-ref --stdin <stdin &&
569 git rev-parse --verify -q $m
572 test_expect_success
'stdin fails on empty line' '
574 test_must_fail git update-ref --stdin <stdin 2>err &&
575 grep "fatal: empty command in input" err
578 test_expect_success
'stdin fails on only whitespace' '
580 test_must_fail git update-ref --stdin <stdin 2>err &&
581 grep "fatal: whitespace before command: " err
584 test_expect_success
'stdin fails on leading whitespace' '
585 echo " create $a $m" >stdin &&
586 test_must_fail git update-ref --stdin <stdin 2>err &&
587 grep "fatal: whitespace before command: create $a $m" err
590 test_expect_success
'stdin fails on unknown command' '
591 echo "unknown $a" >stdin &&
592 test_must_fail git update-ref --stdin <stdin 2>err &&
593 grep "fatal: unknown command: unknown $a" err
596 test_expect_success
'stdin fails on unbalanced quotes' '
597 echo "create $a \"main" >stdin &&
598 test_must_fail git update-ref --stdin <stdin 2>err &&
599 grep "fatal: badly quoted argument: \\\"main" err
602 test_expect_success
'stdin fails on invalid escape' '
603 echo "create $a \"ma\zn\"" >stdin &&
604 test_must_fail git update-ref --stdin <stdin 2>err &&
605 grep "fatal: badly quoted argument: \\\"ma\\\\zn\\\"" err
608 test_expect_success
'stdin fails on junk after quoted argument' '
609 echo "create \"$a\"main" >stdin &&
610 test_must_fail git update-ref --stdin <stdin 2>err &&
611 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"main" err
614 test_expect_success
'stdin fails create with no ref' '
615 echo "create " >stdin &&
616 test_must_fail git update-ref --stdin <stdin 2>err &&
617 grep "fatal: create: missing <ref>" err
620 test_expect_success
'stdin fails create with no new value' '
621 echo "create $a" >stdin &&
622 test_must_fail git update-ref --stdin <stdin 2>err &&
623 grep "fatal: create $a: missing <newvalue>" err
626 test_expect_success
'stdin fails create with too many arguments' '
627 echo "create $a $m $m" >stdin &&
628 test_must_fail git update-ref --stdin <stdin 2>err &&
629 grep "fatal: create $a: extra input: $m" err
632 test_expect_success
'stdin fails update with no ref' '
633 echo "update " >stdin &&
634 test_must_fail git update-ref --stdin <stdin 2>err &&
635 grep "fatal: update: missing <ref>" err
638 test_expect_success
'stdin fails update with no new value' '
639 echo "update $a" >stdin &&
640 test_must_fail git update-ref --stdin <stdin 2>err &&
641 grep "fatal: update $a: missing <newvalue>" err
644 test_expect_success
'stdin fails update with too many arguments' '
645 echo "update $a $m $m $m" >stdin &&
646 test_must_fail git update-ref --stdin <stdin 2>err &&
647 grep "fatal: update $a: extra input: $m" err
650 test_expect_success
'stdin fails delete with no ref' '
651 echo "delete " >stdin &&
652 test_must_fail git update-ref --stdin <stdin 2>err &&
653 grep "fatal: delete: missing <ref>" err
656 test_expect_success
'stdin fails delete with too many arguments' '
657 echo "delete $a $m $m" >stdin &&
658 test_must_fail git update-ref --stdin <stdin 2>err &&
659 grep "fatal: delete $a: extra input: $m" err
662 test_expect_success
'stdin fails verify with too many arguments' '
663 echo "verify $a $m $m" >stdin &&
664 test_must_fail git update-ref --stdin <stdin 2>err &&
665 grep "fatal: verify $a: extra input: $m" err
668 test_expect_success
'stdin fails option with unknown name' '
669 echo "option unknown" >stdin &&
670 test_must_fail git update-ref --stdin <stdin 2>err &&
671 grep "fatal: option unknown: unknown" err
674 test_expect_success
'stdin fails with duplicate refs' '
680 test_must_fail git update-ref --stdin <stdin 2>err &&
681 test_grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
684 test_expect_success
'stdin create ref works' '
685 echo "create $a $m" >stdin &&
686 git update-ref --stdin <stdin &&
687 git rev-parse $m >expect &&
688 git rev-parse $a >actual &&
689 test_cmp expect actual
692 test_expect_success
'stdin does not create reflogs by default' '
693 test_when_finished "git update-ref -d $outside" &&
694 echo "create $outside $m" >stdin &&
695 git update-ref --stdin <stdin &&
696 git rev-parse $m >expect &&
697 git rev-parse $outside >actual &&
698 test_cmp expect actual &&
699 test_must_fail git reflog exists $outside
702 test_expect_success
'stdin creates reflogs with --create-reflog' '
703 test_when_finished "git update-ref -d $outside" &&
704 echo "create $outside $m" >stdin &&
705 git update-ref --create-reflog --stdin <stdin &&
706 git rev-parse $m >expect &&
707 git rev-parse $outside >actual &&
708 test_cmp expect actual &&
709 git reflog exists $outside
712 test_expect_success
'stdin succeeds with quoted argument' '
713 git update-ref -d $a &&
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 succeeds with escaped character' '
722 git update-ref -d $a &&
723 echo "create $a \"ma\\151n\"" >stdin &&
724 git update-ref --stdin <stdin &&
725 git rev-parse $m >expect &&
726 git rev-parse $a >actual &&
727 test_cmp expect actual
730 test_expect_success
'stdin update ref creates with zero old value' '
731 echo "update $b $m $Z" >stdin &&
732 git update-ref --stdin <stdin &&
733 git rev-parse $m >expect &&
734 git rev-parse $b >actual &&
735 test_cmp expect actual &&
739 test_expect_success
'stdin update ref creates with empty old value' '
740 echo "update $b $m $E" >stdin &&
741 git update-ref --stdin <stdin &&
742 git rev-parse $m >expect &&
743 git rev-parse $b >actual &&
744 test_cmp expect actual
747 test_expect_success
'stdin create ref works with path with space to blob' '
748 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
749 git update-ref --stdin <stdin &&
750 git rev-parse "$m:$pws" >expect &&
751 git rev-parse refs/blobs/pws >actual &&
752 test_cmp expect actual &&
753 git update-ref -d refs/blobs/pws
756 test_expect_success
'stdin update ref fails with wrong old value' '
757 echo "update $c $m $m~1" >stdin &&
758 test_must_fail git update-ref --stdin <stdin 2>err &&
759 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
760 test_must_fail git rev-parse --verify -q $c
763 test_expect_success
'stdin update ref fails with bad old value' '
764 echo "update $c $m does-not-exist" >stdin &&
765 test_must_fail git update-ref --stdin <stdin 2>err &&
766 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
767 test_must_fail git rev-parse --verify -q $c
770 test_expect_success
'stdin create ref fails with bad new value' '
771 echo "create $c does-not-exist" >stdin &&
772 test_must_fail git update-ref --stdin <stdin 2>err &&
773 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
774 test_must_fail git rev-parse --verify -q $c
777 test_expect_success
'stdin create ref fails with zero new value' '
778 echo "create $c " >stdin &&
779 test_must_fail git update-ref --stdin <stdin 2>err &&
780 grep "fatal: create $c: zero <newvalue>" err &&
781 test_must_fail git rev-parse --verify -q $c
784 test_expect_success
'stdin update ref works with right old value' '
785 echo "update $b $m~1 $m" >stdin &&
786 git update-ref --stdin <stdin &&
787 git rev-parse $m~1 >expect &&
788 git rev-parse $b >actual &&
789 test_cmp expect actual
792 test_expect_success
'stdin delete ref fails with wrong old value' '
793 echo "delete $a $m~1" >stdin &&
794 test_must_fail git update-ref --stdin <stdin 2>err &&
795 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
796 git rev-parse $m >expect &&
797 git rev-parse $a >actual &&
798 test_cmp expect actual
801 test_expect_success
'stdin delete ref fails with zero old value' '
802 echo "delete $a " >stdin &&
803 test_must_fail git update-ref --stdin <stdin 2>err &&
804 grep "fatal: delete $a: zero <oldvalue>" err &&
805 git rev-parse $m >expect &&
806 git rev-parse $a >actual &&
807 test_cmp expect actual
810 test_expect_success
'stdin update symref works option no-deref' '
811 git symbolic-ref TESTSYMREF $b &&
814 update TESTSYMREF $a $b
816 git update-ref --stdin <stdin &&
817 git rev-parse TESTSYMREF >expect &&
818 git rev-parse $a >actual &&
819 test_cmp expect actual &&
820 git rev-parse $m~1 >expect &&
821 git rev-parse $b >actual &&
822 test_cmp expect actual
825 test_expect_success
'stdin delete symref works option no-deref' '
826 git symbolic-ref TESTSYMREF $b &&
831 git update-ref --stdin <stdin &&
832 test_must_fail git rev-parse --verify -q TESTSYMREF &&
833 git rev-parse $m~1 >expect &&
834 git rev-parse $b >actual &&
835 test_cmp expect actual
838 test_expect_success
'stdin update symref works flag --no-deref' '
839 git symbolic-ref TESTSYMREFONE $b &&
840 git symbolic-ref TESTSYMREFTWO $b &&
842 update TESTSYMREFONE $a $b
843 update TESTSYMREFTWO $a $b
845 git update-ref --no-deref --stdin <stdin &&
846 git rev-parse TESTSYMREFONE TESTSYMREFTWO >expect &&
847 git rev-parse $a $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 flag --no-deref' '
855 git symbolic-ref TESTSYMREFONE $b &&
856 git symbolic-ref TESTSYMREFTWO $b &&
858 delete TESTSYMREFONE $b
859 delete TESTSYMREFTWO $b
861 git update-ref --no-deref --stdin <stdin &&
862 test_must_fail git rev-parse --verify -q TESTSYMREFONE &&
863 test_must_fail git rev-parse --verify -q TESTSYMREFTWO &&
864 git rev-parse $m~1 >expect &&
865 git rev-parse $b >actual &&
866 test_cmp expect actual
869 test_expect_success
'stdin delete ref works with right old value' '
870 echo "delete $b $m~1" >stdin &&
871 git update-ref --stdin <stdin &&
872 test_must_fail git rev-parse --verify -q $b
875 test_expect_success
'stdin update/create/verify combination works' '
881 git update-ref --stdin <stdin &&
882 git rev-parse $m >expect &&
883 git rev-parse $a >actual &&
884 test_cmp expect actual &&
885 git rev-parse $b >actual &&
886 test_cmp expect actual &&
887 test_must_fail git rev-parse --verify -q $c
890 test_expect_success
'stdin verify succeeds for correct value' '
891 git rev-parse $m >expect &&
892 echo "verify $m $m" >stdin &&
893 git update-ref --stdin <stdin &&
894 git rev-parse $m >actual &&
895 test_cmp expect actual
898 test_expect_success
'stdin verify succeeds for missing reference' '
899 echo "verify refs/heads/missing $Z" >stdin &&
900 git update-ref --stdin <stdin &&
901 test_must_fail git rev-parse --verify -q refs/heads/missing
904 test_expect_success
'stdin verify treats no value as missing' '
905 echo "verify refs/heads/missing" >stdin &&
906 git update-ref --stdin <stdin &&
907 test_must_fail git rev-parse --verify -q refs/heads/missing
910 test_expect_success
'stdin verify fails for wrong value' '
911 git rev-parse $m >expect &&
912 echo "verify $m $m~1" >stdin &&
913 test_must_fail git update-ref --stdin <stdin &&
914 git rev-parse $m >actual &&
915 test_cmp expect actual
918 test_expect_success
'stdin verify fails for mistaken null value' '
919 git rev-parse $m >expect &&
920 echo "verify $m $Z" >stdin &&
921 test_must_fail git update-ref --stdin <stdin &&
922 git rev-parse $m >actual &&
923 test_cmp expect actual
926 test_expect_success
'stdin verify fails for mistaken empty value' '
927 M=$(git rev-parse $m) &&
928 test_when_finished "git update-ref $m $M" &&
929 git rev-parse $m >expect &&
930 echo "verify $m" >stdin &&
931 test_must_fail git update-ref --stdin <stdin &&
932 git rev-parse $m >actual &&
933 test_cmp expect actual
936 test_expect_success
'stdin update refs works with identity updates' '
942 git update-ref --stdin <stdin &&
943 git rev-parse $m >expect &&
944 git rev-parse $a >actual &&
945 test_cmp expect actual &&
946 git rev-parse $b >actual &&
947 test_cmp expect actual &&
948 test_must_fail git rev-parse --verify -q $c
951 test_expect_success
'stdin update refs fails with wrong old value' '
952 git update-ref $c $m &&
958 test_must_fail git update-ref --stdin <stdin 2>err &&
959 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
960 git rev-parse $m >expect &&
961 git rev-parse $a >actual &&
962 test_cmp expect actual &&
963 git rev-parse $b >actual &&
964 test_cmp expect actual &&
965 git rev-parse $c >actual &&
966 test_cmp expect actual
969 test_expect_success
'stdin delete refs works with packed and loose refs' '
970 git pack-refs --all &&
971 git update-ref $c $m~1 &&
977 git update-ref --stdin <stdin &&
978 test_must_fail git rev-parse --verify -q $a &&
979 test_must_fail git rev-parse --verify -q $b &&
980 test_must_fail git rev-parse --verify -q $c
983 test_expect_success
'stdin -z works on empty input' '
985 git update-ref -z --stdin <stdin &&
986 git rev-parse --verify -q $m
989 test_expect_success
'stdin -z fails on empty line' '
991 test_must_fail git update-ref -z --stdin <stdin 2>err &&
992 grep "fatal: whitespace before command: " err
995 test_expect_success
'stdin -z fails on empty command' '
996 printf $F "" >stdin &&
997 test_must_fail git update-ref -z --stdin <stdin 2>err &&
998 grep "fatal: empty command in input" err
1001 test_expect_success
'stdin -z fails on only whitespace' '
1002 printf $F " " >stdin &&
1003 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1004 grep "fatal: whitespace before command: " err
1007 test_expect_success
'stdin -z fails on leading whitespace' '
1008 printf $F " create $a" "$m" >stdin &&
1009 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1010 grep "fatal: whitespace before command: create $a" err
1013 test_expect_success
'stdin -z fails on unknown command' '
1014 printf $F "unknown $a" >stdin &&
1015 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1016 grep "fatal: unknown command: unknown $a" err
1019 test_expect_success
'stdin -z fails create with no ref' '
1020 printf $F "create " >stdin &&
1021 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1022 grep "fatal: create: missing <ref>" err
1025 test_expect_success
'stdin -z fails create with no new value' '
1026 printf $F "create $a" >stdin &&
1027 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1028 grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
1031 test_expect_success
'stdin -z fails create with too many arguments' '
1032 printf $F "create $a" "$m" "$m" >stdin &&
1033 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1034 grep "fatal: unknown command: $m" err
1037 test_expect_success
'stdin -z fails update with no ref' '
1038 printf $F "update " >stdin &&
1039 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1040 grep "fatal: update: missing <ref>" err
1043 test_expect_success
'stdin -z fails update with too few args' '
1044 printf $F "update $a" "$m" >stdin &&
1045 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1046 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
1049 test_expect_success
'stdin -z emits warning with empty new value' '
1050 git update-ref $a $m &&
1051 printf $F "update $a" "" "" >stdin &&
1052 git update-ref -z --stdin <stdin 2>err &&
1053 grep "warning: update $a: missing <newvalue>, treating as zero" err &&
1054 test_must_fail git rev-parse --verify -q $a
1057 test_expect_success
'stdin -z fails update with no new value' '
1058 printf $F "update $a" >stdin &&
1059 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1060 grep "fatal: update $a: unexpected end of input when reading <newvalue>" err
1063 test_expect_success
'stdin -z fails update with no old value' '
1064 printf $F "update $a" "$m" >stdin &&
1065 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1066 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
1069 test_expect_success
'stdin -z fails update with too many arguments' '
1070 printf $F "update $a" "$m" "$m" "$m" >stdin &&
1071 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1072 grep "fatal: unknown command: $m" err
1075 test_expect_success
'stdin -z fails delete with no ref' '
1076 printf $F "delete " >stdin &&
1077 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1078 grep "fatal: delete: missing <ref>" err
1081 test_expect_success
'stdin -z fails delete with no old value' '
1082 printf $F "delete $a" >stdin &&
1083 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1084 grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
1087 test_expect_success
'stdin -z fails delete with too many arguments' '
1088 printf $F "delete $a" "$m" "$m" >stdin &&
1089 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1090 grep "fatal: unknown command: $m" err
1093 test_expect_success
'stdin -z fails verify with too many arguments' '
1094 printf $F "verify $a" "$m" "$m" >stdin &&
1095 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1096 grep "fatal: unknown command: $m" err
1099 test_expect_success
'stdin -z fails verify with no old value' '
1100 printf $F "verify $a" >stdin &&
1101 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1102 grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err
1105 test_expect_success
'stdin -z fails option with unknown name' '
1106 printf $F "option unknown" >stdin &&
1107 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1108 grep "fatal: option unknown: unknown" err
1111 test_expect_success
'stdin -z fails with duplicate refs' '
1112 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
1113 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1114 test_grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
1117 test_expect_success
'stdin -z create ref works' '
1118 printf $F "create $a" "$m" >stdin &&
1119 git update-ref -z --stdin <stdin &&
1120 git rev-parse $m >expect &&
1121 git rev-parse $a >actual &&
1122 test_cmp expect actual
1125 test_expect_success
'stdin -z update ref creates with zero old value' '
1126 printf $F "update $b" "$m" "$Z" >stdin &&
1127 git update-ref -z --stdin <stdin &&
1128 git rev-parse $m >expect &&
1129 git rev-parse $b >actual &&
1130 test_cmp expect actual &&
1131 git update-ref -d $b
1134 test_expect_success
'stdin -z update ref creates with empty old value' '
1135 printf $F "update $b" "$m" "" >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
1142 test_expect_success
'stdin -z create ref works with path with space to blob' '
1143 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
1144 git update-ref -z --stdin <stdin &&
1145 git rev-parse "$m:$pws" >expect &&
1146 git rev-parse refs/blobs/pws >actual &&
1147 test_cmp expect actual &&
1148 git update-ref -d refs/blobs/pws
1151 test_expect_success
'stdin -z update ref fails with wrong old value' '
1152 printf $F "update $c" "$m" "$m~1" >stdin &&
1153 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1154 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1155 test_must_fail git rev-parse --verify -q $c
1158 test_expect_success
'stdin -z update ref fails with bad old value' '
1159 printf $F "update $c" "$m" "does-not-exist" >stdin &&
1160 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1161 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
1162 test_must_fail git rev-parse --verify -q $c
1165 test_expect_success
'stdin -z create ref fails when ref exists' '
1166 git update-ref $c $m &&
1167 git rev-parse "$c" >expect &&
1168 printf $F "create $c" "$m~1" >stdin &&
1169 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1170 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1171 git rev-parse "$c" >actual &&
1172 test_cmp expect actual
1175 test_expect_success
'stdin -z create ref fails with bad new value' '
1176 git update-ref -d "$c" &&
1177 printf $F "create $c" "does-not-exist" >stdin &&
1178 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1179 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
1180 test_must_fail git rev-parse --verify -q $c
1183 test_expect_success
'stdin -z create ref fails with empty new value' '
1184 printf $F "create $c" "" >stdin &&
1185 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1186 grep "fatal: create $c: missing <newvalue>" err &&
1187 test_must_fail git rev-parse --verify -q $c
1190 test_expect_success
'stdin -z update ref works with right old value' '
1191 printf $F "update $b" "$m~1" "$m" >stdin &&
1192 git update-ref -z --stdin <stdin &&
1193 git rev-parse $m~1 >expect &&
1194 git rev-parse $b >actual &&
1195 test_cmp expect actual
1198 test_expect_success
'stdin -z delete ref fails with wrong old value' '
1199 printf $F "delete $a" "$m~1" >stdin &&
1200 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1201 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
1202 git rev-parse $m >expect &&
1203 git rev-parse $a >actual &&
1204 test_cmp expect actual
1207 test_expect_success
'stdin -z delete ref fails with zero old value' '
1208 printf $F "delete $a" "$Z" >stdin &&
1209 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1210 grep "fatal: delete $a: zero <oldvalue>" err &&
1211 git rev-parse $m >expect &&
1212 git rev-parse $a >actual &&
1213 test_cmp expect actual
1216 test_expect_success
'stdin -z update symref works option no-deref' '
1217 git symbolic-ref TESTSYMREF $b &&
1218 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
1219 git update-ref -z --stdin <stdin &&
1220 git rev-parse TESTSYMREF >expect &&
1221 git rev-parse $a >actual &&
1222 test_cmp expect actual &&
1223 git rev-parse $m~1 >expect &&
1224 git rev-parse $b >actual &&
1225 test_cmp expect actual
1228 test_expect_success
'stdin -z delete symref works option no-deref' '
1229 git symbolic-ref TESTSYMREF $b &&
1230 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
1231 git update-ref -z --stdin <stdin &&
1232 test_must_fail git rev-parse --verify -q TESTSYMREF &&
1233 git rev-parse $m~1 >expect &&
1234 git rev-parse $b >actual &&
1235 test_cmp expect actual
1238 test_expect_success
'stdin -z delete ref works with right old value' '
1239 printf $F "delete $b" "$m~1" >stdin &&
1240 git update-ref -z --stdin <stdin &&
1241 test_must_fail git rev-parse --verify -q $b
1244 test_expect_success
'stdin -z update/create/verify combination works' '
1245 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
1246 git update-ref -z --stdin <stdin &&
1247 git rev-parse $m >expect &&
1248 git rev-parse $a >actual &&
1249 test_cmp expect actual &&
1250 git rev-parse $b >actual &&
1251 test_cmp expect actual &&
1252 test_must_fail git rev-parse --verify -q $c
1255 test_expect_success
'stdin -z verify succeeds for correct value' '
1256 git rev-parse $m >expect &&
1257 printf $F "verify $m" "$m" >stdin &&
1258 git update-ref -z --stdin <stdin &&
1259 git rev-parse $m >actual &&
1260 test_cmp expect actual
1263 test_expect_success
'stdin -z verify succeeds for missing reference' '
1264 printf $F "verify refs/heads/missing" "$Z" >stdin &&
1265 git update-ref -z --stdin <stdin &&
1266 test_must_fail git rev-parse --verify -q refs/heads/missing
1269 test_expect_success
'stdin -z verify treats no value as missing' '
1270 printf $F "verify refs/heads/missing" "" >stdin &&
1271 git update-ref -z --stdin <stdin &&
1272 test_must_fail git rev-parse --verify -q refs/heads/missing
1275 test_expect_success
'stdin -z verify fails for wrong value' '
1276 git rev-parse $m >expect &&
1277 printf $F "verify $m" "$m~1" >stdin &&
1278 test_must_fail git update-ref -z --stdin <stdin &&
1279 git rev-parse $m >actual &&
1280 test_cmp expect actual
1283 test_expect_success
'stdin -z verify fails for mistaken null value' '
1284 git rev-parse $m >expect &&
1285 printf $F "verify $m" "$Z" >stdin &&
1286 test_must_fail git update-ref -z --stdin <stdin &&
1287 git rev-parse $m >actual &&
1288 test_cmp expect actual
1291 test_expect_success
'stdin -z verify fails for mistaken empty value' '
1292 M=$(git rev-parse $m) &&
1293 test_when_finished "git update-ref $m $M" &&
1294 git rev-parse $m >expect &&
1295 printf $F "verify $m" "" >stdin &&
1296 test_must_fail git update-ref -z --stdin <stdin &&
1297 git rev-parse $m >actual &&
1298 test_cmp expect actual
1301 test_expect_success
'stdin -z update refs works with identity updates' '
1302 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
1303 git update-ref -z --stdin <stdin &&
1304 git rev-parse $m >expect &&
1305 git rev-parse $a >actual &&
1306 test_cmp expect actual &&
1307 git rev-parse $b >actual &&
1308 test_cmp expect actual &&
1309 test_must_fail git rev-parse --verify -q $c
1312 test_expect_success
'stdin -z update refs fails with wrong old value' '
1313 git update-ref $c $m &&
1314 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
1315 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1316 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1317 git rev-parse $m >expect &&
1318 git rev-parse $a >actual &&
1319 test_cmp expect actual &&
1320 git rev-parse $b >actual &&
1321 test_cmp expect actual &&
1322 git rev-parse $c >actual &&
1323 test_cmp expect actual
1326 test_expect_success
'stdin -z delete refs works with packed and loose refs' '
1327 git pack-refs --all &&
1328 git update-ref $c $m~1 &&
1329 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
1330 git update-ref -z --stdin <stdin &&
1331 test_must_fail git rev-parse --verify -q $a &&
1332 test_must_fail git rev-parse --verify -q $b &&
1333 test_must_fail git rev-parse --verify -q $c
1336 test_expect_success
'fails with duplicate HEAD update' '
1337 git branch target1 $A &&
1338 git checkout target1 &&
1339 cat >stdin <<-EOF &&
1340 update refs/heads/target1 $C
1344 test_must_fail git update-ref --stdin <stdin 2>err &&
1345 test_grep "fatal: multiple updates for '\''HEAD'\'' (including one via its referent .refs/heads/target1.) are not allowed" err &&
1346 echo "refs/heads/target1" >expect &&
1347 git symbolic-ref HEAD >actual &&
1348 test_cmp expect actual &&
1349 echo "$A" >expect &&
1350 git rev-parse refs/heads/target1 >actual &&
1351 test_cmp expect actual
1354 test_expect_success
'fails with duplicate ref update via symref' '
1355 git branch target2 $A &&
1356 git symbolic-ref refs/heads/symref2 refs/heads/target2 &&
1357 cat >stdin <<-EOF &&
1358 update refs/heads/target2 $C
1359 update refs/heads/symref2 $B
1361 test_must_fail git update-ref --stdin <stdin 2>err &&
1362 test_grep "fatal: multiple updates for '\''refs/heads/target2'\'' (including one via symref .refs/heads/symref2.) are not allowed" err &&
1363 echo "refs/heads/target2" >expect &&
1364 git symbolic-ref refs/heads/symref2 >actual &&
1365 test_cmp expect actual &&
1366 echo "$A" >expect &&
1367 git rev-parse refs/heads/target2 >actual &&
1368 test_cmp expect actual
1371 test_expect_success ULIMIT_FILE_DESCRIPTORS
'large transaction creating branches does not burst open file limit' '
1373 for i in $(test_seq 33)
1375 echo "create refs/heads/$i HEAD" || exit 1
1376 done >large_input &&
1377 run_with_limited_open_files git update-ref --stdin <large_input &&
1378 git rev-parse --verify -q refs/heads/33
1382 test_expect_success ULIMIT_FILE_DESCRIPTORS
'large transaction deleting branches does not burst open file limit' '
1384 for i in $(test_seq 33)
1386 echo "delete refs/heads/$i HEAD" || exit 1
1387 done >large_input &&
1388 run_with_limited_open_files git update-ref --stdin <large_input &&
1389 test_must_fail git rev-parse --verify -q refs/heads/33
1393 test_expect_success
'handle per-worktree refs in refs/bisect' '
1394 git commit --allow-empty -m "initial commit" &&
1395 git worktree add -b branch worktree &&
1398 git commit --allow-empty -m "test commit" &&
1399 git for-each-ref >for-each-ref.out &&
1400 ! grep refs/bisect for-each-ref.out &&
1401 git update-ref refs/bisect/something HEAD &&
1402 git rev-parse refs/bisect/something >../worktree-head &&
1403 git for-each-ref | grep refs/bisect/something
1405 git show-ref >actual &&
1406 ! grep 'refs
/bisect
' actual &&
1407 test_must_fail git rev-parse refs/bisect/something &&
1408 git update-ref refs/bisect/something HEAD &&
1409 git rev-parse refs/bisect/something >main-head &&
1410 ! test_cmp main-head worktree-head
1413 test_expect_success
'transaction handles empty commit' '
1414 cat >stdin <<-EOF &&
1419 git update-ref --stdin <stdin >actual &&
1420 printf "%s: ok\n" start prepare commit >expect &&
1421 test_cmp expect actual
1424 test_expect_success
'transaction handles empty commit with missing prepare' '
1425 cat >stdin <<-EOF &&
1429 git update-ref --stdin <stdin >actual &&
1430 printf "%s: ok\n" start commit >expect &&
1431 test_cmp expect actual
1434 test_expect_success
'transaction handles sole commit' '
1435 cat >stdin <<-EOF &&
1438 git update-ref --stdin <stdin >actual &&
1439 printf "%s: ok\n" commit >expect &&
1440 test_cmp expect actual
1443 test_expect_success
'transaction handles empty abort' '
1444 cat >stdin <<-EOF &&
1449 git update-ref --stdin <stdin >actual &&
1450 printf "%s: ok\n" start prepare abort >expect &&
1451 test_cmp expect actual
1454 test_expect_success
'transaction exits on multiple aborts' '
1455 cat >stdin <<-EOF &&
1459 test_must_fail git update-ref --stdin <stdin >actual 2>err &&
1460 printf "%s: ok\n" abort >expect &&
1461 test_cmp expect actual &&
1462 grep "fatal: transaction is closed" err
1465 test_expect_success
'transaction exits on start after prepare' '
1466 cat >stdin <<-EOF &&
1470 test_must_fail git update-ref --stdin <stdin 2>err >actual &&
1471 printf "%s: ok\n" prepare >expect &&
1472 test_cmp expect actual &&
1473 grep "fatal: prepared transactions can only be closed" err
1476 test_expect_success
'transaction handles empty abort with missing prepare' '
1477 cat >stdin <<-EOF &&
1481 git update-ref --stdin <stdin >actual &&
1482 printf "%s: ok\n" start abort >expect &&
1483 test_cmp expect actual
1486 test_expect_success
'transaction handles sole abort' '
1487 cat >stdin <<-EOF &&
1490 git update-ref --stdin <stdin >actual &&
1491 printf "%s: ok\n" abort >expect &&
1492 test_cmp expect actual
1495 test_expect_success
'transaction can handle commit' '
1496 cat >stdin <<-EOF &&
1501 git update-ref --stdin <stdin >actual &&
1502 printf "%s: ok\n" start commit >expect &&
1503 test_cmp expect actual &&
1504 git rev-parse HEAD >expect &&
1505 git rev-parse $a >actual &&
1506 test_cmp expect actual
1509 test_expect_success
'transaction can handle abort' '
1510 cat >stdin <<-EOF &&
1515 git update-ref --stdin <stdin >actual &&
1516 printf "%s: ok\n" start abort >expect &&
1517 test_cmp expect actual &&
1518 test_must_fail git show-ref --verify -q $b
1521 test_expect_success
'transaction aborts by default' '
1522 cat >stdin <<-EOF &&
1526 git update-ref --stdin <stdin >actual &&
1527 printf "%s: ok\n" start >expect &&
1528 test_cmp expect actual &&
1529 test_must_fail git show-ref --verify -q $b
1532 test_expect_success
'transaction with prepare aborts by default' '
1533 cat >stdin <<-EOF &&
1538 git update-ref --stdin <stdin >actual &&
1539 printf "%s: ok\n" start prepare >expect &&
1540 test_cmp expect actual &&
1541 test_must_fail git show-ref --verify -q $b
1544 test_expect_success
'transaction can commit multiple times' '
1545 cat >stdin <<-EOF &&
1547 create refs/heads/branch-1 $A
1550 create refs/heads/branch-2 $B
1553 git update-ref --stdin <stdin >actual &&
1554 printf "%s: ok\n" start commit start commit >expect &&
1555 test_cmp expect actual &&
1556 echo "$A" >expect &&
1557 git rev-parse refs/heads/branch-1 >actual &&
1558 test_cmp expect actual &&
1559 echo "$B" >expect &&
1560 git rev-parse refs/heads/branch-2 >actual &&
1561 test_cmp expect actual
1564 test_expect_success
'transaction can create and delete' '
1565 cat >stdin <<-EOF &&
1567 create refs/heads/create-and-delete $A
1570 delete refs/heads/create-and-delete $A
1573 git update-ref --stdin <stdin >actual &&
1574 printf "%s: ok\n" start commit start commit >expect &&
1575 test_cmp expect actual &&
1576 test_must_fail git show-ref --verify refs/heads/create-and-delete
1579 test_expect_success
'transaction can commit after abort' '
1580 cat >stdin <<-EOF &&
1582 create refs/heads/abort $A
1585 create refs/heads/abort $A
1588 git update-ref --stdin <stdin >actual &&
1589 printf "%s: ok\n" start abort start commit >expect &&
1590 echo "$A" >expect &&
1591 git rev-parse refs/heads/abort >actual &&
1592 test_cmp expect actual
1595 test_expect_success
'transaction cannot restart ongoing transaction' '
1596 cat >stdin <<-EOF &&
1598 create refs/heads/restart $A
1602 test_must_fail git update-ref --stdin <stdin >actual &&
1603 printf "%s: ok\n" start >expect &&
1604 test_cmp expect actual &&
1605 test_must_fail git show-ref --verify refs/heads/restart
1608 test_expect_success PIPE
'transaction flushes status updates' '
1610 (git update-ref --stdin <in >out &) &&
1614 test_when_finished "exec 9>&-" &&
1615 test_when_finished "exec 8<&-" &&
1618 echo "start: ok" >expected &&
1620 echo "$line" >actual &&
1621 test_cmp expected actual &&
1623 echo "create refs/heads/flush $A" >&9 &&
1626 echo "prepare: ok" >expected &&
1628 echo "$line" >actual &&
1629 test_cmp expected actual &&
1631 # This must now fail given that we have locked the ref.
1632 test_must_fail git update-ref refs/heads/flush $B 2>stderr &&
1633 grep "fatal: update_ref failed for ref ${SQ}refs/heads/flush${SQ}: cannot lock ref" stderr &&
1636 echo "commit: ok" >expected &&
1638 echo "$line" >actual &&
1639 test_cmp expected actual
1642 test_expect_success REFFILES
'directory not created deleting packed ref' '
1643 git branch d1/d2/r1 HEAD &&
1644 git pack-refs --all &&
1645 test_path_is_missing .git/refs/heads/d1/d2 &&
1646 git update-ref -d refs/heads/d1/d2/r1 &&
1647 test_path_is_missing .git/refs/heads/d1/d2 &&
1648 test_path_is_missing .git/refs/heads/d1