3 # Copyright (c) 2006 Shawn Pearce
6 test_description='Test git update-ref and basic ref logging'
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
20 create_test_commits ()
23 for name in A B C D E F
26 T=$(git write-tree) &&
27 sha1=$(echo $name | git commit-tree $T) &&
32 test_expect_success setup '
33 create_test_commits "" &&
37 create_test_commits "bare" &&
41 test_expect_success "create $m" '
42 git update-ref $m $A &&
43 test $A = $(git show-ref -s --verify $m)
45 test_expect_success "create $m with oldvalue verification" '
46 git update-ref $m $B $A &&
47 test $B = $(git show-ref -s --verify $m)
49 test_expect_success "fail to delete $m with stale ref" '
50 test_must_fail git update-ref -d $m $A &&
51 test $B = "$(git show-ref -s --verify $m)"
53 test_expect_success "delete $m" '
54 test_when_finished "rm -f .git/$m" &&
55 git update-ref -d $m $B &&
56 test_path_is_missing .git/$m
59 test_expect_success "delete $m without oldvalue verification" '
60 test_when_finished "rm -f .git/$m" &&
61 git update-ref $m $A &&
62 test $A = $(git show-ref -s --verify $m) &&
63 git update-ref -d $m &&
64 test_path_is_missing .git/$m
67 test_expect_success "fail to create $n" '
68 test_when_finished "rm -f .git/$n_dir" &&
70 test_must_fail git update-ref $n $A
73 test_expect_success "create $m (by HEAD)" '
74 git update-ref HEAD $A &&
75 test $A = $(git show-ref -s --verify $m)
77 test_expect_success "create $m (by HEAD) with oldvalue verification" '
78 git update-ref HEAD $B $A &&
79 test $B = $(git show-ref -s --verify $m)
81 test_expect_success "fail to delete $m (by HEAD) with stale ref" '
82 test_must_fail git update-ref -d HEAD $A &&
83 test $B = $(git show-ref -s --verify $m)
85 test_expect_success "delete $m (by HEAD)" '
86 test_when_finished "rm -f .git/$m" &&
87 git update-ref -d HEAD $B &&
88 test_path_is_missing .git/$m
91 test_expect_success "deleting current branch adds message to HEAD's log" '
92 test_when_finished "rm -f .git/$m" &&
93 git update-ref $m $A &&
94 git symbolic-ref HEAD $m &&
95 git update-ref -m delete-$m -d $m &&
96 test_path_is_missing .git/$m &&
97 grep "delete-$m$" .git/logs/HEAD
100 test_expect_success "deleting by HEAD adds message to HEAD's log" '
101 test_when_finished "rm -f .git/$m" &&
102 git update-ref $m $A &&
103 git symbolic-ref HEAD $m &&
104 git update-ref -m delete-by-head -d HEAD &&
105 test_path_is_missing .git/$m &&
106 grep "delete-by-head$" .git/logs/HEAD
109 test_expect_success 'update-ref does not create reflogs by default' '
110 test_when_finished "git update-ref -d $outside" &&
111 git update-ref $outside $A &&
112 git rev-parse $A >expect &&
113 git rev-parse $outside >actual &&
114 test_cmp expect actual &&
115 test_must_fail git reflog exists $outside
118 test_expect_success 'update-ref creates reflogs with --create-reflog' '
119 test_when_finished "git update-ref -d $outside" &&
120 git update-ref --create-reflog $outside $A &&
121 git rev-parse $A >expect &&
122 git rev-parse $outside >actual &&
123 test_cmp expect actual &&
124 git reflog exists $outside
127 test_expect_success 'creates no reflog in bare repository' '
128 git -C $bare update-ref $m $bareA &&
129 git -C $bare rev-parse $bareA >expect &&
130 git -C $bare rev-parse $m >actual &&
131 test_cmp expect actual &&
132 test_must_fail git -C $bare reflog exists $m
135 test_expect_success 'core.logAllRefUpdates=true creates reflog in bare repository' '
136 test_when_finished "git -C $bare config --unset core.logAllRefUpdates && \
138 git -C $bare config core.logAllRefUpdates true &&
139 git -C $bare update-ref $m $bareB &&
140 git -C $bare rev-parse $bareB >expect &&
141 git -C $bare rev-parse $m >actual &&
142 test_cmp expect actual &&
143 git -C $bare reflog exists $m
146 test_expect_success 'core.logAllRefUpdates=true does not create reflog by default' '
147 test_config core.logAllRefUpdates true &&
148 test_when_finished "git update-ref -d $outside" &&
149 git update-ref $outside $A &&
150 git rev-parse $A >expect &&
151 git rev-parse $outside >actual &&
152 test_cmp expect actual &&
153 test_must_fail git reflog exists $outside
156 test_expect_success 'core.logAllRefUpdates=always creates reflog by default' '
157 test_config core.logAllRefUpdates always &&
158 test_when_finished "git update-ref -d $outside" &&
159 git update-ref $outside $A &&
160 git rev-parse $A >expect &&
161 git rev-parse $outside >actual &&
162 test_cmp expect actual &&
163 git reflog exists $outside
166 test_expect_success 'core.logAllRefUpdates=always creates reflog for ORIG_HEAD' '
167 test_config core.logAllRefUpdates always &&
168 git update-ref ORIG_HEAD $A &&
169 git reflog exists ORIG_HEAD
172 test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always' '
173 test_config core.logAllRefUpdates true &&
174 test_when_finished "git update-ref -d $outside" &&
175 git update-ref --no-create-reflog $outside $A &&
176 git rev-parse $A >expect &&
177 git rev-parse $outside >actual &&
178 test_cmp expect actual &&
179 test_must_fail git reflog exists $outside
182 test_expect_success "create $m (by HEAD)" '
183 git update-ref HEAD $A &&
184 test $A = $(git show-ref -s --verify $m)
186 test_expect_success 'pack refs' '
189 test_expect_success "move $m (by HEAD)" '
190 git update-ref HEAD $B $A &&
191 test $B = $(git show-ref -s --verify $m)
193 test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" '
194 test_when_finished "rm -f .git/$m" &&
195 git update-ref -d HEAD $B &&
196 ! grep "$m" .git/packed-refs &&
197 test_path_is_missing .git/$m
200 cp -f .git/HEAD .git/HEAD.orig
201 test_expect_success 'delete symref without dereference' '
202 test_when_finished "cp -f .git/HEAD.orig .git/HEAD" &&
203 git update-ref --no-deref -d HEAD &&
204 test_path_is_missing .git/HEAD
207 test_expect_success 'delete symref without dereference when the referred ref is packed' '
208 test_when_finished "cp -f .git/HEAD.orig .git/HEAD" &&
212 git pack-refs --all &&
213 git update-ref --no-deref -d HEAD &&
214 test_path_is_missing .git/HEAD
219 test_expect_success 'update-ref -d is not confused by self-reference' '
220 git symbolic-ref refs/heads/self refs/heads/self &&
221 test_when_finished "rm -f .git/refs/heads/self" &&
222 test_path_is_file .git/refs/heads/self &&
223 test_must_fail git update-ref -d refs/heads/self &&
224 test_path_is_file .git/refs/heads/self
227 test_expect_success 'update-ref --no-deref -d can delete self-reference' '
228 git symbolic-ref refs/heads/self refs/heads/self &&
229 test_when_finished "rm -f .git/refs/heads/self" &&
230 test_path_is_file .git/refs/heads/self &&
231 git update-ref --no-deref -d refs/heads/self &&
232 test_path_is_missing .git/refs/heads/self
235 test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
236 >.git/refs/heads/bad &&
237 test_when_finished "rm -f .git/refs/heads/bad" &&
238 git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
239 test_when_finished "rm -f .git/refs/heads/ref-to-bad" &&
240 test_path_is_file .git/refs/heads/ref-to-bad &&
241 git update-ref --no-deref -d refs/heads/ref-to-bad &&
242 test_path_is_missing .git/refs/heads/ref-to-bad
245 test_expect_success '(not) create HEAD with old sha1' '
246 test_must_fail git update-ref HEAD $A $B
248 test_expect_success "(not) prior created .git/$m" '
249 test_when_finished "rm -f .git/$m" &&
250 test_path_is_missing .git/$m
253 test_expect_success 'create HEAD' '
254 git update-ref HEAD $A
256 test_expect_success '(not) change HEAD with wrong SHA1' '
257 test_must_fail git update-ref HEAD $B $Z
259 test_expect_success "(not) changed .git/$m" '
260 test_when_finished "rm -f .git/$m" &&
261 ! test $B = $(git show-ref -s --verify $m)
264 rm -f .git/logs/refs/heads/main
265 test_expect_success "create $m (logged by touch)" '
266 test_config core.logAllRefUpdates false &&
267 GIT_COMMITTER_DATE="2005-05-26 23:30" \
268 git update-ref --create-reflog HEAD $A -m "Initial Creation" &&
269 test $A = $(git show-ref -s --verify $m)
271 test_expect_success "update $m (logged by touch)" '
272 test_config core.logAllRefUpdates false &&
273 GIT_COMMITTER_DATE="2005-05-26 23:31" \
274 git update-ref HEAD $B $A -m "Switch" &&
275 test $B = $(git show-ref -s --verify $m)
277 test_expect_success "set $m (logged by touch)" '
278 test_config core.logAllRefUpdates false &&
279 GIT_COMMITTER_DATE="2005-05-26 23:41" \
280 git update-ref HEAD $A &&
281 test $A = $(git show-ref -s --verify $m)
284 test_expect_success 'empty directory removal' '
285 git branch d1/d2/r1 HEAD &&
286 git branch d1/r2 HEAD &&
287 test_path_is_file .git/refs/heads/d1/d2/r1 &&
288 test_path_is_file .git/logs/refs/heads/d1/d2/r1 &&
289 git branch -d d1/d2/r1 &&
290 test_path_is_missing .git/refs/heads/d1/d2 &&
291 test_path_is_missing .git/logs/refs/heads/d1/d2 &&
292 test_path_is_file .git/refs/heads/d1/r2 &&
293 test_path_is_file .git/logs/refs/heads/d1/r2
296 test_expect_success 'symref empty directory removal' '
297 git branch e1/e2/r1 HEAD &&
298 git branch e1/r2 HEAD &&
299 git checkout e1/e2/r1 &&
300 test_when_finished "git checkout main" &&
301 test_path_is_file .git/refs/heads/e1/e2/r1 &&
302 test_path_is_file .git/logs/refs/heads/e1/e2/r1 &&
303 git update-ref -d HEAD &&
304 test_path_is_missing .git/refs/heads/e1/e2 &&
305 test_path_is_missing .git/logs/refs/heads/e1/e2 &&
306 test_path_is_file .git/refs/heads/e1/r2 &&
307 test_path_is_file .git/logs/refs/heads/e1/r2 &&
308 test_path_is_file .git/logs/HEAD
312 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
313 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
314 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
316 test_expect_success "verifying $m's log (logged by touch)" '
317 test_when_finished "rm -rf .git/$m .git/logs expect" &&
318 test_cmp expect .git/logs/$m
321 test_expect_success "create $m (logged by config)" '
322 test_config core.logAllRefUpdates true &&
323 GIT_COMMITTER_DATE="2005-05-26 23:32" \
324 git update-ref HEAD $A -m "Initial Creation" &&
325 test $A = $(git show-ref -s --verify $m)
327 test_expect_success "update $m (logged by config)" '
328 test_config core.logAllRefUpdates true &&
329 GIT_COMMITTER_DATE="2005-05-26 23:33" \
330 git update-ref HEAD $B $A -m "Switch" &&
331 test $B = $(git show-ref -s --verify $m)
333 test_expect_success "set $m (logged by config)" '
334 test_config core.logAllRefUpdates true &&
335 GIT_COMMITTER_DATE="2005-05-26 23:43" \
336 git update-ref HEAD $A &&
337 test $A = $(git show-ref -s --verify $m)
341 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
342 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
343 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
345 test_expect_success "verifying $m's log (logged by config)" '
346 test_when_finished "rm -f .git/$m .git/logs/$m expect" &&
347 test_cmp expect .git/logs/$m
350 test_expect_success 'set up for querying the reflog' '
351 git update-ref $m $D &&
352 cat >.git/logs/$m <<-EOF
353 $Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
354 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
355 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
356 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
357 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
361 ed="Thu, 26 May 2005 18:32:00 -0500"
362 gd="Thu, 26 May 2005 18:33:00 -0500"
363 ld="Thu, 26 May 2005 18:43:00 -0500"
364 test_expect_success 'Query "main@{May 25 2005}" (before history)' '
365 test_when_finished "rm -f o e" &&
366 git rev-parse --verify "main@{May 25 2005}" >o 2>e &&
369 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
370 test_i18ncmp expect e
372 test_expect_success 'Query main@{2005-05-25} (before history)' '
373 test_when_finished "rm -f o e" &&
374 git rev-parse --verify main@{2005-05-25} >o 2>e &&
377 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
378 test_i18ncmp expect e
380 test_expect_success 'Query "main@{May 26 2005 23:31:59}" (1 second before history)' '
381 test_when_finished "rm -f o e" &&
382 git rev-parse --verify "main@{May 26 2005 23:31:59}" >o 2>e &&
385 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
386 test_i18ncmp expect e
388 test_expect_success 'Query "main@{May 26 2005 23:32:00}" (exactly history start)' '
389 test_when_finished "rm -f o e" &&
390 git rev-parse --verify "main@{May 26 2005 23:32:00}" >o 2>e &&
395 test_expect_success 'Query "main@{May 26 2005 23:32:30}" (first non-creation change)' '
396 test_when_finished "rm -f o e" &&
397 git rev-parse --verify "main@{May 26 2005 23:32:30}" >o 2>e &&
402 test_expect_success 'Query "main@{2005-05-26 23:33:01}" (middle of history with gap)' '
403 test_when_finished "rm -f o e" &&
404 git rev-parse --verify "main@{2005-05-26 23:33:01}" >o 2>e &&
407 test_i18ngrep -F "warning: log for ref $m has gap after $gd" e
409 test_expect_success 'Query "main@{2005-05-26 23:38:00}" (middle of history)' '
410 test_when_finished "rm -f o e" &&
411 git rev-parse --verify "main@{2005-05-26 23:38:00}" >o 2>e &&
416 test_expect_success 'Query "main@{2005-05-26 23:43:00}" (exact end of history)' '
417 test_when_finished "rm -f o e" &&
418 git rev-parse --verify "main@{2005-05-26 23:43:00}" >o 2>e &&
423 test_expect_success 'Query "main@{2005-05-28}" (past end of history)' '
424 test_when_finished "rm -f o e" &&
425 git rev-parse --verify "main@{2005-05-28}" >o 2>e &&
428 test_i18ngrep -F "warning: log for ref $m unexpectedly ended on $ld" e
431 rm -f .git/$m .git/logs/$m expect
433 test_expect_success 'creating initial files' '
434 test_when_finished rm -f M &&
437 GIT_AUTHOR_DATE="2005-05-26 23:30" \
438 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
439 h_TEST=$(git rev-parse --verify HEAD) &&
440 echo The other day this did not work. >M &&
441 echo And then Bob told me how to fix it. >>M &&
443 GIT_AUTHOR_DATE="2005-05-26 23:41" \
444 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
445 h_OTHER=$(git rev-parse --verify HEAD) &&
446 GIT_AUTHOR_DATE="2005-05-26 23:44" \
447 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
448 h_FIXED=$(git rev-parse --verify HEAD) &&
449 echo Merged initial commit and a later commit. >M &&
450 echo $h_TEST >.git/MERGE_HEAD &&
451 GIT_AUTHOR_DATE="2005-05-26 23:45" \
452 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
453 h_MERGED=$(git rev-parse --verify HEAD)
457 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
458 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
459 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
460 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
462 test_expect_success 'git commit logged updates' '
463 test_cmp expect .git/logs/$m
465 unset h_TEST h_OTHER h_FIXED h_MERGED
467 test_expect_success 'git cat-file blob main:F (expect OTHER)' '
468 test OTHER = $(git cat-file blob main:F)
470 test_expect_success 'git cat-file blob main@{2005-05-26 23:30}:F (expect TEST)' '
471 test TEST = $(git cat-file blob "main@{2005-05-26 23:30}:F")
473 test_expect_success 'git cat-file blob main@{2005-05-26 23:42}:F (expect OTHER)' '
474 test OTHER = $(git cat-file blob "main@{2005-05-26 23:42}:F")
477 # Test adding and deleting pseudorefs
479 test_expect_success 'given old value for missing pseudoref, do not create' '
480 test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
481 test_must_fail git rev-parse PSEUDOREF &&
482 test_i18ngrep "unable to resolve reference" err
485 test_expect_success 'create pseudoref' '
486 git update-ref PSEUDOREF $A &&
487 test $A = $(git rev-parse PSEUDOREF)
490 test_expect_success 'overwrite pseudoref with no old value given' '
491 git update-ref PSEUDOREF $B &&
492 test $B = $(git rev-parse PSEUDOREF)
495 test_expect_success 'overwrite pseudoref with correct old value' '
496 git update-ref PSEUDOREF $C $B &&
497 test $C = $(git rev-parse PSEUDOREF)
500 test_expect_success 'do not overwrite pseudoref with wrong old value' '
501 test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
502 test $C = $(git rev-parse PSEUDOREF) &&
503 test_i18ngrep "cannot lock ref.*expected" err
506 test_expect_success 'delete pseudoref' '
507 git update-ref -d PSEUDOREF &&
508 test_must_fail git rev-parse PSEUDOREF
511 test_expect_success 'do not delete pseudoref with wrong old value' '
512 git update-ref PSEUDOREF $A &&
513 test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
514 test $A = $(git rev-parse PSEUDOREF) &&
515 test_i18ngrep "cannot lock ref.*expected" err
518 test_expect_success 'delete pseudoref with correct old value' '
519 git update-ref -d PSEUDOREF $A &&
520 test_must_fail git rev-parse PSEUDOREF
523 test_expect_success 'create pseudoref with old OID zero' '
524 git update-ref PSEUDOREF $A $Z &&
525 test $A = $(git rev-parse PSEUDOREF)
528 test_expect_success 'do not overwrite pseudoref with old OID zero' '
529 test_when_finished git update-ref -d PSEUDOREF &&
530 test_must_fail git update-ref PSEUDOREF $B $Z 2>err &&
531 test $A = $(git rev-parse PSEUDOREF) &&
532 test_i18ngrep "already exists" err
542 pws='path with space'
544 test_expect_success 'stdin test setup' '
545 echo "$pws" >"$pws" &&
550 test_expect_success '-z fails without --stdin' '
551 test_must_fail git update-ref -z $m $m $m 2>err &&
552 test_i18ngrep "usage: git update-ref" err
555 test_expect_success 'stdin works with no input' '
557 git update-ref --stdin <stdin &&
558 git rev-parse --verify -q $m
561 test_expect_success 'stdin fails on empty line' '
563 test_must_fail git update-ref --stdin <stdin 2>err &&
564 grep "fatal: empty command in input" err
567 test_expect_success 'stdin fails on only whitespace' '
569 test_must_fail git update-ref --stdin <stdin 2>err &&
570 grep "fatal: whitespace before command: " err
573 test_expect_success 'stdin fails on leading whitespace' '
574 echo " create $a $m" >stdin &&
575 test_must_fail git update-ref --stdin <stdin 2>err &&
576 grep "fatal: whitespace before command: create $a $m" err
579 test_expect_success 'stdin fails on unknown command' '
580 echo "unknown $a" >stdin &&
581 test_must_fail git update-ref --stdin <stdin 2>err &&
582 grep "fatal: unknown command: unknown $a" err
585 test_expect_success 'stdin fails on unbalanced quotes' '
586 echo "create $a \"main" >stdin &&
587 test_must_fail git update-ref --stdin <stdin 2>err &&
588 grep "fatal: badly quoted argument: \\\"main" err
591 test_expect_success PREPARE_FOR_MAIN_BRANCH 'stdin fails on invalid escape' '
592 echo "create $a \"ma\zn\"" >stdin &&
593 test_must_fail git update-ref --stdin <stdin 2>err &&
594 grep "fatal: badly quoted argument: \\\"ma\\\\zn\\\"" err
597 test_expect_success 'stdin fails on junk after quoted argument' '
598 echo "create \"$a\"main" >stdin &&
599 test_must_fail git update-ref --stdin <stdin 2>err &&
600 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"main" err
603 test_expect_success 'stdin fails create with no ref' '
604 echo "create " >stdin &&
605 test_must_fail git update-ref --stdin <stdin 2>err &&
606 grep "fatal: create: missing <ref>" err
609 test_expect_success 'stdin fails create with no new value' '
610 echo "create $a" >stdin &&
611 test_must_fail git update-ref --stdin <stdin 2>err &&
612 grep "fatal: create $a: missing <newvalue>" err
615 test_expect_success 'stdin fails create with too many arguments' '
616 echo "create $a $m $m" >stdin &&
617 test_must_fail git update-ref --stdin <stdin 2>err &&
618 grep "fatal: create $a: extra input: $m" err
621 test_expect_success 'stdin fails update with no ref' '
622 echo "update " >stdin &&
623 test_must_fail git update-ref --stdin <stdin 2>err &&
624 grep "fatal: update: missing <ref>" err
627 test_expect_success 'stdin fails update with no new value' '
628 echo "update $a" >stdin &&
629 test_must_fail git update-ref --stdin <stdin 2>err &&
630 grep "fatal: update $a: missing <newvalue>" err
633 test_expect_success 'stdin fails update with too many arguments' '
634 echo "update $a $m $m $m" >stdin &&
635 test_must_fail git update-ref --stdin <stdin 2>err &&
636 grep "fatal: update $a: extra input: $m" err
639 test_expect_success 'stdin fails delete with no ref' '
640 echo "delete " >stdin &&
641 test_must_fail git update-ref --stdin <stdin 2>err &&
642 grep "fatal: delete: missing <ref>" err
645 test_expect_success 'stdin fails delete with too many arguments' '
646 echo "delete $a $m $m" >stdin &&
647 test_must_fail git update-ref --stdin <stdin 2>err &&
648 grep "fatal: delete $a: extra input: $m" err
651 test_expect_success 'stdin fails verify with too many arguments' '
652 echo "verify $a $m $m" >stdin &&
653 test_must_fail git update-ref --stdin <stdin 2>err &&
654 grep "fatal: verify $a: extra input: $m" err
657 test_expect_success 'stdin fails option with unknown name' '
658 echo "option unknown" >stdin &&
659 test_must_fail git update-ref --stdin <stdin 2>err &&
660 grep "fatal: option unknown: unknown" err
663 test_expect_success 'stdin fails with duplicate refs' '
669 test_must_fail git update-ref --stdin <stdin 2>err &&
670 test_i18ngrep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
673 test_expect_success 'stdin create ref works' '
674 echo "create $a $m" >stdin &&
675 git update-ref --stdin <stdin &&
676 git rev-parse $m >expect &&
677 git rev-parse $a >actual &&
678 test_cmp expect actual
681 test_expect_success 'stdin does not create reflogs by default' '
682 test_when_finished "git update-ref -d $outside" &&
683 echo "create $outside $m" >stdin &&
684 git update-ref --stdin <stdin &&
685 git rev-parse $m >expect &&
686 git rev-parse $outside >actual &&
687 test_cmp expect actual &&
688 test_must_fail git reflog exists $outside
691 test_expect_success 'stdin creates reflogs with --create-reflog' '
692 test_when_finished "git update-ref -d $outside" &&
693 echo "create $outside $m" >stdin &&
694 git update-ref --create-reflog --stdin <stdin &&
695 git rev-parse $m >expect &&
696 git rev-parse $outside >actual &&
697 test_cmp expect actual &&
698 git reflog exists $outside
701 test_expect_success 'stdin succeeds with quoted argument' '
702 git update-ref -d $a &&
703 echo "create $a \"$m\"" >stdin &&
704 git update-ref --stdin <stdin &&
705 git rev-parse $m >expect &&
706 git rev-parse $a >actual &&
707 test_cmp expect actual
710 test_expect_success PREPARE_FOR_MAIN_BRANCH 'stdin succeeds with escaped character' '
711 git update-ref -d $a &&
712 echo "create $a \"ma\\151n\"" >stdin &&
713 git update-ref --stdin <stdin &&
714 git rev-parse $m >expect &&
715 git rev-parse $a >actual &&
716 test_cmp expect actual
719 test_expect_success 'stdin update ref creates with zero old value' '
720 echo "update $b $m $Z" >stdin &&
721 git update-ref --stdin <stdin &&
722 git rev-parse $m >expect &&
723 git rev-parse $b >actual &&
724 test_cmp expect actual &&
728 test_expect_success 'stdin update ref creates with empty old value' '
729 echo "update $b $m $E" >stdin &&
730 git update-ref --stdin <stdin &&
731 git rev-parse $m >expect &&
732 git rev-parse $b >actual &&
733 test_cmp expect actual
736 test_expect_success 'stdin create ref works with path with space to blob' '
737 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
738 git update-ref --stdin <stdin &&
739 git rev-parse "$m:$pws" >expect &&
740 git rev-parse refs/blobs/pws >actual &&
741 test_cmp expect actual &&
742 git update-ref -d refs/blobs/pws
745 test_expect_success 'stdin update ref fails with wrong old value' '
746 echo "update $c $m $m~1" >stdin &&
747 test_must_fail git update-ref --stdin <stdin 2>err &&
748 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
749 test_must_fail git rev-parse --verify -q $c
752 test_expect_success 'stdin update ref fails with bad old value' '
753 echo "update $c $m does-not-exist" >stdin &&
754 test_must_fail git update-ref --stdin <stdin 2>err &&
755 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
756 test_must_fail git rev-parse --verify -q $c
759 test_expect_success 'stdin create ref fails with bad new value' '
760 echo "create $c does-not-exist" >stdin &&
761 test_must_fail git update-ref --stdin <stdin 2>err &&
762 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
763 test_must_fail git rev-parse --verify -q $c
766 test_expect_success 'stdin create ref fails with zero new value' '
767 echo "create $c " >stdin &&
768 test_must_fail git update-ref --stdin <stdin 2>err &&
769 grep "fatal: create $c: zero <newvalue>" err &&
770 test_must_fail git rev-parse --verify -q $c
773 test_expect_success 'stdin update ref works with right old value' '
774 echo "update $b $m~1 $m" >stdin &&
775 git update-ref --stdin <stdin &&
776 git rev-parse $m~1 >expect &&
777 git rev-parse $b >actual &&
778 test_cmp expect actual
781 test_expect_success 'stdin delete ref fails with wrong old value' '
782 echo "delete $a $m~1" >stdin &&
783 test_must_fail git update-ref --stdin <stdin 2>err &&
784 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
785 git rev-parse $m >expect &&
786 git rev-parse $a >actual &&
787 test_cmp expect actual
790 test_expect_success 'stdin delete ref fails with zero old value' '
791 echo "delete $a " >stdin &&
792 test_must_fail git update-ref --stdin <stdin 2>err &&
793 grep "fatal: delete $a: zero <oldvalue>" err &&
794 git rev-parse $m >expect &&
795 git rev-parse $a >actual &&
796 test_cmp expect actual
799 test_expect_success 'stdin update symref works option no-deref' '
800 git symbolic-ref TESTSYMREF $b &&
803 update TESTSYMREF $a $b
805 git update-ref --stdin <stdin &&
806 git rev-parse TESTSYMREF >expect &&
807 git rev-parse $a >actual &&
808 test_cmp expect actual &&
809 git rev-parse $m~1 >expect &&
810 git rev-parse $b >actual &&
811 test_cmp expect actual
814 test_expect_success 'stdin delete symref works option no-deref' '
815 git symbolic-ref TESTSYMREF $b &&
820 git update-ref --stdin <stdin &&
821 test_must_fail git rev-parse --verify -q TESTSYMREF &&
822 git rev-parse $m~1 >expect &&
823 git rev-parse $b >actual &&
824 test_cmp expect actual
827 test_expect_success 'stdin update symref works flag --no-deref' '
828 git symbolic-ref TESTSYMREFONE $b &&
829 git symbolic-ref TESTSYMREFTWO $b &&
831 update TESTSYMREFONE $a $b
832 update TESTSYMREFTWO $a $b
834 git update-ref --no-deref --stdin <stdin &&
835 git rev-parse TESTSYMREFONE TESTSYMREFTWO >expect &&
836 git rev-parse $a $a >actual &&
837 test_cmp expect actual &&
838 git rev-parse $m~1 >expect &&
839 git rev-parse $b >actual &&
840 test_cmp expect actual
843 test_expect_success 'stdin delete symref works flag --no-deref' '
844 git symbolic-ref TESTSYMREFONE $b &&
845 git symbolic-ref TESTSYMREFTWO $b &&
847 delete TESTSYMREFONE $b
848 delete TESTSYMREFTWO $b
850 git update-ref --no-deref --stdin <stdin &&
851 test_must_fail git rev-parse --verify -q TESTSYMREFONE &&
852 test_must_fail git rev-parse --verify -q TESTSYMREFTWO &&
853 git rev-parse $m~1 >expect &&
854 git rev-parse $b >actual &&
855 test_cmp expect actual
858 test_expect_success 'stdin delete ref works with right old value' '
859 echo "delete $b $m~1" >stdin &&
860 git update-ref --stdin <stdin &&
861 test_must_fail git rev-parse --verify -q $b
864 test_expect_success 'stdin update/create/verify combination works' '
870 git update-ref --stdin <stdin &&
871 git rev-parse $m >expect &&
872 git rev-parse $a >actual &&
873 test_cmp expect actual &&
874 git rev-parse $b >actual &&
875 test_cmp expect actual &&
876 test_must_fail git rev-parse --verify -q $c
879 test_expect_success 'stdin verify succeeds for correct value' '
880 git rev-parse $m >expect &&
881 echo "verify $m $m" >stdin &&
882 git update-ref --stdin <stdin &&
883 git rev-parse $m >actual &&
884 test_cmp expect actual
887 test_expect_success 'stdin verify succeeds for missing reference' '
888 echo "verify refs/heads/missing $Z" >stdin &&
889 git update-ref --stdin <stdin &&
890 test_must_fail git rev-parse --verify -q refs/heads/missing
893 test_expect_success 'stdin verify treats no value as missing' '
894 echo "verify refs/heads/missing" >stdin &&
895 git update-ref --stdin <stdin &&
896 test_must_fail git rev-parse --verify -q refs/heads/missing
899 test_expect_success 'stdin verify fails for wrong value' '
900 git rev-parse $m >expect &&
901 echo "verify $m $m~1" >stdin &&
902 test_must_fail git update-ref --stdin <stdin &&
903 git rev-parse $m >actual &&
904 test_cmp expect actual
907 test_expect_success 'stdin verify fails for mistaken null value' '
908 git rev-parse $m >expect &&
909 echo "verify $m $Z" >stdin &&
910 test_must_fail git update-ref --stdin <stdin &&
911 git rev-parse $m >actual &&
912 test_cmp expect actual
915 test_expect_success 'stdin verify fails for mistaken empty value' '
916 M=$(git rev-parse $m) &&
917 test_when_finished "git update-ref $m $M" &&
918 git rev-parse $m >expect &&
919 echo "verify $m" >stdin &&
920 test_must_fail git update-ref --stdin <stdin &&
921 git rev-parse $m >actual &&
922 test_cmp expect actual
925 test_expect_success 'stdin update refs works with identity updates' '
931 git update-ref --stdin <stdin &&
932 git rev-parse $m >expect &&
933 git rev-parse $a >actual &&
934 test_cmp expect actual &&
935 git rev-parse $b >actual &&
936 test_cmp expect actual &&
937 test_must_fail git rev-parse --verify -q $c
940 test_expect_success 'stdin update refs fails with wrong old value' '
941 git update-ref $c $m &&
947 test_must_fail git update-ref --stdin <stdin 2>err &&
948 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
949 git rev-parse $m >expect &&
950 git rev-parse $a >actual &&
951 test_cmp expect actual &&
952 git rev-parse $b >actual &&
953 test_cmp expect actual &&
954 git rev-parse $c >actual &&
955 test_cmp expect actual
958 test_expect_success 'stdin delete refs works with packed and loose refs' '
959 git pack-refs --all &&
960 git update-ref $c $m~1 &&
966 git update-ref --stdin <stdin &&
967 test_must_fail git rev-parse --verify -q $a &&
968 test_must_fail git rev-parse --verify -q $b &&
969 test_must_fail git rev-parse --verify -q $c
972 test_expect_success 'stdin -z works on empty input' '
974 git update-ref -z --stdin <stdin &&
975 git rev-parse --verify -q $m
978 test_expect_success 'stdin -z fails on empty line' '
980 test_must_fail git update-ref -z --stdin <stdin 2>err &&
981 grep "fatal: whitespace before command: " err
984 test_expect_success 'stdin -z fails on empty command' '
985 printf $F "" >stdin &&
986 test_must_fail git update-ref -z --stdin <stdin 2>err &&
987 grep "fatal: empty command in input" err
990 test_expect_success 'stdin -z fails on only whitespace' '
991 printf $F " " >stdin &&
992 test_must_fail git update-ref -z --stdin <stdin 2>err &&
993 grep "fatal: whitespace before command: " err
996 test_expect_success 'stdin -z fails on leading whitespace' '
997 printf $F " create $a" "$m" >stdin &&
998 test_must_fail git update-ref -z --stdin <stdin 2>err &&
999 grep "fatal: whitespace before command: create $a" err
1002 test_expect_success 'stdin -z fails on unknown command' '
1003 printf $F "unknown $a" >stdin &&
1004 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1005 grep "fatal: unknown command: unknown $a" err
1008 test_expect_success 'stdin -z fails create with no ref' '
1009 printf $F "create " >stdin &&
1010 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1011 grep "fatal: create: missing <ref>" err
1014 test_expect_success 'stdin -z fails create with no new value' '
1015 printf $F "create $a" >stdin &&
1016 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1017 grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
1020 test_expect_success 'stdin -z fails create with too many arguments' '
1021 printf $F "create $a" "$m" "$m" >stdin &&
1022 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1023 grep "fatal: unknown command: $m" err
1026 test_expect_success 'stdin -z fails update with no ref' '
1027 printf $F "update " >stdin &&
1028 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1029 grep "fatal: update: missing <ref>" err
1032 test_expect_success 'stdin -z fails update with too few args' '
1033 printf $F "update $a" "$m" >stdin &&
1034 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1035 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
1038 test_expect_success 'stdin -z emits warning with empty new value' '
1039 git update-ref $a $m &&
1040 printf $F "update $a" "" "" >stdin &&
1041 git update-ref -z --stdin <stdin 2>err &&
1042 grep "warning: update $a: missing <newvalue>, treating as zero" err &&
1043 test_must_fail git rev-parse --verify -q $a
1046 test_expect_success 'stdin -z fails update with no new value' '
1047 printf $F "update $a" >stdin &&
1048 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1049 grep "fatal: update $a: unexpected end of input when reading <newvalue>" err
1052 test_expect_success 'stdin -z fails update with no old value' '
1053 printf $F "update $a" "$m" >stdin &&
1054 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1055 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
1058 test_expect_success 'stdin -z fails update with too many arguments' '
1059 printf $F "update $a" "$m" "$m" "$m" >stdin &&
1060 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1061 grep "fatal: unknown command: $m" err
1064 test_expect_success 'stdin -z fails delete with no ref' '
1065 printf $F "delete " >stdin &&
1066 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1067 grep "fatal: delete: missing <ref>" err
1070 test_expect_success 'stdin -z fails delete with no old value' '
1071 printf $F "delete $a" >stdin &&
1072 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1073 grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
1076 test_expect_success 'stdin -z fails delete with too many arguments' '
1077 printf $F "delete $a" "$m" "$m" >stdin &&
1078 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1079 grep "fatal: unknown command: $m" err
1082 test_expect_success 'stdin -z fails verify with too many arguments' '
1083 printf $F "verify $a" "$m" "$m" >stdin &&
1084 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1085 grep "fatal: unknown command: $m" err
1088 test_expect_success 'stdin -z fails verify with no old value' '
1089 printf $F "verify $a" >stdin &&
1090 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1091 grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err
1094 test_expect_success 'stdin -z fails option with unknown name' '
1095 printf $F "option unknown" >stdin &&
1096 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1097 grep "fatal: option unknown: unknown" err
1100 test_expect_success 'stdin -z fails with duplicate refs' '
1101 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
1102 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1103 test_i18ngrep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
1106 test_expect_success 'stdin -z create ref works' '
1107 printf $F "create $a" "$m" >stdin &&
1108 git update-ref -z --stdin <stdin &&
1109 git rev-parse $m >expect &&
1110 git rev-parse $a >actual &&
1111 test_cmp expect actual
1114 test_expect_success 'stdin -z update ref creates with zero old value' '
1115 printf $F "update $b" "$m" "$Z" >stdin &&
1116 git update-ref -z --stdin <stdin &&
1117 git rev-parse $m >expect &&
1118 git rev-parse $b >actual &&
1119 test_cmp expect actual &&
1120 git update-ref -d $b
1123 test_expect_success 'stdin -z update ref creates with empty old value' '
1124 printf $F "update $b" "$m" "" >stdin &&
1125 git update-ref -z --stdin <stdin &&
1126 git rev-parse $m >expect &&
1127 git rev-parse $b >actual &&
1128 test_cmp expect actual
1131 test_expect_success 'stdin -z create ref works with path with space to blob' '
1132 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
1133 git update-ref -z --stdin <stdin &&
1134 git rev-parse "$m:$pws" >expect &&
1135 git rev-parse refs/blobs/pws >actual &&
1136 test_cmp expect actual &&
1137 git update-ref -d refs/blobs/pws
1140 test_expect_success 'stdin -z update ref fails with wrong old value' '
1141 printf $F "update $c" "$m" "$m~1" >stdin &&
1142 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1143 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1144 test_must_fail git rev-parse --verify -q $c
1147 test_expect_success 'stdin -z update ref fails with bad old value' '
1148 printf $F "update $c" "$m" "does-not-exist" >stdin &&
1149 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1150 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
1151 test_must_fail git rev-parse --verify -q $c
1154 test_expect_success 'stdin -z create ref fails when ref exists' '
1155 git update-ref $c $m &&
1156 git rev-parse "$c" >expect &&
1157 printf $F "create $c" "$m~1" >stdin &&
1158 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1159 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1160 git rev-parse "$c" >actual &&
1161 test_cmp expect actual
1164 test_expect_success 'stdin -z create ref fails with bad new value' '
1165 git update-ref -d "$c" &&
1166 printf $F "create $c" "does-not-exist" >stdin &&
1167 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1168 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
1169 test_must_fail git rev-parse --verify -q $c
1172 test_expect_success 'stdin -z create ref fails with empty new value' '
1173 printf $F "create $c" "" >stdin &&
1174 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1175 grep "fatal: create $c: missing <newvalue>" err &&
1176 test_must_fail git rev-parse --verify -q $c
1179 test_expect_success 'stdin -z update ref works with right old value' '
1180 printf $F "update $b" "$m~1" "$m" >stdin &&
1181 git update-ref -z --stdin <stdin &&
1182 git rev-parse $m~1 >expect &&
1183 git rev-parse $b >actual &&
1184 test_cmp expect actual
1187 test_expect_success 'stdin -z delete ref fails with wrong old value' '
1188 printf $F "delete $a" "$m~1" >stdin &&
1189 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1190 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
1191 git rev-parse $m >expect &&
1192 git rev-parse $a >actual &&
1193 test_cmp expect actual
1196 test_expect_success 'stdin -z delete ref fails with zero old value' '
1197 printf $F "delete $a" "$Z" >stdin &&
1198 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1199 grep "fatal: delete $a: zero <oldvalue>" err &&
1200 git rev-parse $m >expect &&
1201 git rev-parse $a >actual &&
1202 test_cmp expect actual
1205 test_expect_success 'stdin -z update symref works option no-deref' '
1206 git symbolic-ref TESTSYMREF $b &&
1207 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
1208 git update-ref -z --stdin <stdin &&
1209 git rev-parse TESTSYMREF >expect &&
1210 git rev-parse $a >actual &&
1211 test_cmp expect actual &&
1212 git rev-parse $m~1 >expect &&
1213 git rev-parse $b >actual &&
1214 test_cmp expect actual
1217 test_expect_success 'stdin -z delete symref works option no-deref' '
1218 git symbolic-ref TESTSYMREF $b &&
1219 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
1220 git update-ref -z --stdin <stdin &&
1221 test_must_fail git rev-parse --verify -q TESTSYMREF &&
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 works with right old value' '
1228 printf $F "delete $b" "$m~1" >stdin &&
1229 git update-ref -z --stdin <stdin &&
1230 test_must_fail git rev-parse --verify -q $b
1233 test_expect_success 'stdin -z update/create/verify combination works' '
1234 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
1235 git update-ref -z --stdin <stdin &&
1236 git rev-parse $m >expect &&
1237 git rev-parse $a >actual &&
1238 test_cmp expect actual &&
1239 git rev-parse $b >actual &&
1240 test_cmp expect actual &&
1241 test_must_fail git rev-parse --verify -q $c
1244 test_expect_success 'stdin -z verify succeeds for correct value' '
1245 git rev-parse $m >expect &&
1246 printf $F "verify $m" "$m" >stdin &&
1247 git update-ref -z --stdin <stdin &&
1248 git rev-parse $m >actual &&
1249 test_cmp expect actual
1252 test_expect_success 'stdin -z verify succeeds for missing reference' '
1253 printf $F "verify refs/heads/missing" "$Z" >stdin &&
1254 git update-ref -z --stdin <stdin &&
1255 test_must_fail git rev-parse --verify -q refs/heads/missing
1258 test_expect_success 'stdin -z verify treats no value as missing' '
1259 printf $F "verify refs/heads/missing" "" >stdin &&
1260 git update-ref -z --stdin <stdin &&
1261 test_must_fail git rev-parse --verify -q refs/heads/missing
1264 test_expect_success 'stdin -z verify fails for wrong value' '
1265 git rev-parse $m >expect &&
1266 printf $F "verify $m" "$m~1" >stdin &&
1267 test_must_fail git update-ref -z --stdin <stdin &&
1268 git rev-parse $m >actual &&
1269 test_cmp expect actual
1272 test_expect_success 'stdin -z verify fails for mistaken null value' '
1273 git rev-parse $m >expect &&
1274 printf $F "verify $m" "$Z" >stdin &&
1275 test_must_fail git update-ref -z --stdin <stdin &&
1276 git rev-parse $m >actual &&
1277 test_cmp expect actual
1280 test_expect_success 'stdin -z verify fails for mistaken empty value' '
1281 M=$(git rev-parse $m) &&
1282 test_when_finished "git update-ref $m $M" &&
1283 git rev-parse $m >expect &&
1284 printf $F "verify $m" "" >stdin &&
1285 test_must_fail git update-ref -z --stdin <stdin &&
1286 git rev-parse $m >actual &&
1287 test_cmp expect actual
1290 test_expect_success 'stdin -z update refs works with identity updates' '
1291 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
1292 git update-ref -z --stdin <stdin &&
1293 git rev-parse $m >expect &&
1294 git rev-parse $a >actual &&
1295 test_cmp expect actual &&
1296 git rev-parse $b >actual &&
1297 test_cmp expect actual &&
1298 test_must_fail git rev-parse --verify -q $c
1301 test_expect_success 'stdin -z update refs fails with wrong old value' '
1302 git update-ref $c $m &&
1303 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
1304 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1305 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1306 git rev-parse $m >expect &&
1307 git rev-parse $a >actual &&
1308 test_cmp expect actual &&
1309 git rev-parse $b >actual &&
1310 test_cmp expect actual &&
1311 git rev-parse $c >actual &&
1312 test_cmp expect actual
1315 test_expect_success 'stdin -z delete refs works with packed and loose refs' '
1316 git pack-refs --all &&
1317 git update-ref $c $m~1 &&
1318 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
1319 git update-ref -z --stdin <stdin &&
1320 test_must_fail git rev-parse --verify -q $a &&
1321 test_must_fail git rev-parse --verify -q $b &&
1322 test_must_fail git rev-parse --verify -q $c
1325 test_expect_success 'fails with duplicate HEAD update' '
1326 git branch target1 $A &&
1327 git checkout target1 &&
1328 cat >stdin <<-EOF &&
1329 update refs/heads/target1 $C
1333 test_must_fail git update-ref --stdin <stdin 2>err &&
1334 test_i18ngrep "fatal: multiple updates for '\''HEAD'\'' (including one via its referent .refs/heads/target1.) are not allowed" err &&
1335 echo "refs/heads/target1" >expect &&
1336 git symbolic-ref HEAD >actual &&
1337 test_cmp expect actual &&
1338 echo "$A" >expect &&
1339 git rev-parse refs/heads/target1 >actual &&
1340 test_cmp expect actual
1343 test_expect_success 'fails with duplicate ref update via symref' '
1344 git branch target2 $A &&
1345 git symbolic-ref refs/heads/symref2 refs/heads/target2 &&
1346 cat >stdin <<-EOF &&
1347 update refs/heads/target2 $C
1348 update refs/heads/symref2 $B
1350 test_must_fail git update-ref --stdin <stdin 2>err &&
1351 test_i18ngrep "fatal: multiple updates for '\''refs/heads/target2'\'' (including one via symref .refs/heads/symref2.) are not allowed" err &&
1352 echo "refs/heads/target2" >expect &&
1353 git symbolic-ref refs/heads/symref2 >actual &&
1354 test_cmp expect actual &&
1355 echo "$A" >expect &&
1356 git rev-parse refs/heads/target2 >actual &&
1357 test_cmp expect actual
1360 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' '
1362 for i in $(test_seq 33)
1364 echo "create refs/heads/$i HEAD"
1365 done >large_input &&
1366 run_with_limited_open_files git update-ref --stdin <large_input &&
1367 git rev-parse --verify -q refs/heads/33
1371 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches does not burst open file limit' '
1373 for i in $(test_seq 33)
1375 echo "delete refs/heads/$i HEAD"
1376 done >large_input &&
1377 run_with_limited_open_files git update-ref --stdin <large_input &&
1378 test_must_fail git rev-parse --verify -q refs/heads/33
1382 test_expect_success 'handle per-worktree refs in refs/bisect' '
1383 git commit --allow-empty -m "initial commit" &&
1384 git worktree add -b branch worktree &&
1387 git commit --allow-empty -m "test commit" &&
1388 git for-each-ref >for-each-ref.out &&
1389 ! grep refs/bisect for-each-ref.out &&
1390 git update-ref refs/bisect/something HEAD &&
1391 git rev-parse refs/bisect/something >../worktree-head &&
1392 git for-each-ref | grep refs/bisect/something
1394 test_path_is_missing .git/refs/bisect &&
1395 test_must_fail git rev-parse refs/bisect/something &&
1396 git update-ref refs/bisect/something HEAD &&
1397 git rev-parse refs/bisect/something >main-head &&
1398 ! test_cmp main-head worktree-head
1401 test_expect_success 'transaction handles empty commit' '
1402 cat >stdin <<-EOF &&
1407 git update-ref --stdin <stdin >actual &&
1408 printf "%s: ok\n" start prepare commit >expect &&
1409 test_cmp expect actual
1412 test_expect_success 'transaction handles empty commit with missing prepare' '
1413 cat >stdin <<-EOF &&
1417 git update-ref --stdin <stdin >actual &&
1418 printf "%s: ok\n" start commit >expect &&
1419 test_cmp expect actual
1422 test_expect_success 'transaction handles sole commit' '
1423 cat >stdin <<-EOF &&
1426 git update-ref --stdin <stdin >actual &&
1427 printf "%s: ok\n" commit >expect &&
1428 test_cmp expect actual
1431 test_expect_success 'transaction handles empty abort' '
1432 cat >stdin <<-EOF &&
1437 git update-ref --stdin <stdin >actual &&
1438 printf "%s: ok\n" start prepare abort >expect &&
1439 test_cmp expect actual
1442 test_expect_success 'transaction exits on multiple aborts' '
1443 cat >stdin <<-EOF &&
1447 test_must_fail git update-ref --stdin <stdin >actual 2>err &&
1448 printf "%s: ok\n" abort >expect &&
1449 test_cmp expect actual &&
1450 grep "fatal: transaction is closed" err
1453 test_expect_success 'transaction exits on start after prepare' '
1454 cat >stdin <<-EOF &&
1458 test_must_fail git update-ref --stdin <stdin 2>err >actual &&
1459 printf "%s: ok\n" prepare >expect &&
1460 test_cmp expect actual &&
1461 grep "fatal: prepared transactions can only be closed" err
1464 test_expect_success 'transaction handles empty abort with missing prepare' '
1465 cat >stdin <<-EOF &&
1469 git update-ref --stdin <stdin >actual &&
1470 printf "%s: ok\n" start abort >expect &&
1471 test_cmp expect actual
1474 test_expect_success 'transaction handles sole abort' '
1475 cat >stdin <<-EOF &&
1478 git update-ref --stdin <stdin >actual &&
1479 printf "%s: ok\n" abort >expect &&
1480 test_cmp expect actual
1483 test_expect_success 'transaction can handle commit' '
1484 cat >stdin <<-EOF &&
1489 git update-ref --stdin <stdin >actual &&
1490 printf "%s: ok\n" start commit >expect &&
1491 test_cmp expect actual &&
1492 git rev-parse HEAD >expect &&
1493 git rev-parse $a >actual &&
1494 test_cmp expect actual
1497 test_expect_success 'transaction can handle abort' '
1498 cat >stdin <<-EOF &&
1503 git update-ref --stdin <stdin >actual &&
1504 printf "%s: ok\n" start abort >expect &&
1505 test_cmp expect actual &&
1506 test_path_is_missing .git/$b
1509 test_expect_success 'transaction aborts by default' '
1510 cat >stdin <<-EOF &&
1514 git update-ref --stdin <stdin >actual &&
1515 printf "%s: ok\n" start >expect &&
1516 test_cmp expect actual &&
1517 test_path_is_missing .git/$b
1520 test_expect_success 'transaction with prepare aborts by default' '
1521 cat >stdin <<-EOF &&
1526 git update-ref --stdin <stdin >actual &&
1527 printf "%s: ok\n" start prepare >expect &&
1528 test_cmp expect actual &&
1529 test_path_is_missing .git/$b