3 # Copyright (c) 2006 Shawn Pearce
6 test_description='Test git update-ref and basic ref logging'
17 create_test_commits ()
20 for name in A B C D E F
23 T=$(git write-tree) &&
24 sha1=$(echo $name | git commit-tree $T) &&
29 test_expect_success setup '
30 create_test_commits "" &&
34 create_test_commits "bare" &&
38 test_expect_success "create $m" '
39 git update-ref $m $A &&
40 test $A = $(cat .git/$m)
42 test_expect_success "create $m with oldvalue verification" '
43 git update-ref $m $B $A &&
44 test $B = $(cat .git/$m)
46 test_expect_success "fail to delete $m with stale ref" '
47 test_must_fail git update-ref -d $m $A &&
48 test $B = "$(cat .git/$m)"
50 test_expect_success "delete $m" '
51 test_when_finished "rm -f .git/$m" &&
52 git update-ref -d $m $B &&
53 test_path_is_missing .git/$m
56 test_expect_success "delete $m without oldvalue verification" '
57 test_when_finished "rm -f .git/$m" &&
58 git update-ref $m $A &&
59 test $A = $(cat .git/$m) &&
60 git update-ref -d $m &&
61 test_path_is_missing .git/$m
64 test_expect_success "fail to create $n" '
65 test_when_finished "rm -f .git/$n_dir" &&
67 test_must_fail git update-ref $n $A
70 test_expect_success "create $m (by HEAD)" '
71 git update-ref HEAD $A &&
72 test $A = $(cat .git/$m)
74 test_expect_success "create $m (by HEAD) with oldvalue verification" '
75 git update-ref HEAD $B $A &&
76 test $B = $(cat .git/$m)
78 test_expect_success "fail to delete $m (by HEAD) with stale ref" '
79 test_must_fail git update-ref -d HEAD $A &&
80 test $B = $(cat .git/$m)
82 test_expect_success "delete $m (by HEAD)" '
83 test_when_finished "rm -f .git/$m" &&
84 git update-ref -d HEAD $B &&
85 test_path_is_missing .git/$m
88 test_expect_success "deleting current branch adds message to HEAD's log" '
89 test_when_finished "rm -f .git/$m" &&
90 git update-ref $m $A &&
91 git symbolic-ref HEAD $m &&
92 git update-ref -m delete-$m -d $m &&
93 test_path_is_missing .git/$m &&
94 grep "delete-$m$" .git/logs/HEAD
97 test_expect_success "deleting by HEAD adds message to HEAD's log" '
98 test_when_finished "rm -f .git/$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_path_is_missing .git/$m &&
103 grep "delete-by-head$" .git/logs/HEAD
106 test_expect_success 'update-ref does not create reflogs by default' '
107 test_when_finished "git update-ref -d $outside" &&
108 git update-ref $outside $A &&
109 git rev-parse $A >expect &&
110 git rev-parse $outside >actual &&
111 test_cmp expect actual &&
112 test_must_fail git reflog exists $outside
115 test_expect_success 'update-ref creates reflogs with --create-reflog' '
116 test_when_finished "git update-ref -d $outside" &&
117 git update-ref --create-reflog $outside $A &&
118 git rev-parse $A >expect &&
119 git rev-parse $outside >actual &&
120 test_cmp expect actual &&
121 git reflog exists $outside
124 test_expect_success 'creates no reflog in bare repository' '
125 git -C $bare update-ref $m $bareA &&
126 git -C $bare rev-parse $bareA >expect &&
127 git -C $bare rev-parse $m >actual &&
128 test_cmp expect actual &&
129 test_must_fail git -C $bare reflog exists $m
132 test_expect_success 'core.logAllRefUpdates=true creates reflog in bare repository' '
133 test_when_finished "git -C $bare config --unset core.logAllRefUpdates && \
135 git -C $bare config core.logAllRefUpdates true &&
136 git -C $bare update-ref $m $bareB &&
137 git -C $bare rev-parse $bareB >expect &&
138 git -C $bare rev-parse $m >actual &&
139 test_cmp expect actual &&
140 git -C $bare reflog exists $m
143 test_expect_success 'core.logAllRefUpdates=true does not create reflog by default' '
144 test_config core.logAllRefUpdates true &&
145 test_when_finished "git update-ref -d $outside" &&
146 git update-ref $outside $A &&
147 git rev-parse $A >expect &&
148 git rev-parse $outside >actual &&
149 test_cmp expect actual &&
150 test_must_fail git reflog exists $outside
153 test_expect_success 'core.logAllRefUpdates=always creates reflog by default' '
154 test_config core.logAllRefUpdates always &&
155 test_when_finished "git update-ref -d $outside" &&
156 git update-ref $outside $A &&
157 git rev-parse $A >expect &&
158 git rev-parse $outside >actual &&
159 test_cmp expect actual &&
160 git reflog exists $outside
163 test_expect_success 'core.logAllRefUpdates=always creates no reflog for ORIG_HEAD' '
164 test_config core.logAllRefUpdates always &&
165 git update-ref ORIG_HEAD $A &&
166 test_must_fail git reflog exists ORIG_HEAD
169 test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always' '
170 test_config core.logAllRefUpdates true &&
171 test_when_finished "git update-ref -d $outside" &&
172 git update-ref --no-create-reflog $outside $A &&
173 git rev-parse $A >expect &&
174 git rev-parse $outside >actual &&
175 test_cmp expect actual &&
176 test_must_fail git reflog exists $outside
179 test_expect_success "create $m (by HEAD)" '
180 git update-ref HEAD $A &&
181 test $A = $(cat .git/$m)
183 test_expect_success 'pack refs' '
186 test_expect_success "move $m (by HEAD)" '
187 git update-ref HEAD $B $A &&
188 test $B = $(cat .git/$m)
190 test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" '
191 test_when_finished "rm -f .git/$m" &&
192 git update-ref -d HEAD $B &&
193 ! grep "$m" .git/packed-refs &&
194 test_path_is_missing .git/$m
197 cp -f .git/HEAD .git/HEAD.orig
198 test_expect_success 'delete symref without dereference' '
199 test_when_finished "cp -f .git/HEAD.orig .git/HEAD" &&
200 git update-ref --no-deref -d HEAD &&
201 test_path_is_missing .git/HEAD
204 test_expect_success 'delete symref without dereference when the referred ref is packed' '
205 test_when_finished "cp -f .git/HEAD.orig .git/HEAD" &&
209 git pack-refs --all &&
210 git update-ref --no-deref -d HEAD &&
211 test_path_is_missing .git/HEAD
216 test_expect_success 'update-ref -d is not confused by self-reference' '
217 git symbolic-ref refs/heads/self refs/heads/self &&
218 test_when_finished "rm -f .git/refs/heads/self" &&
219 test_path_is_file .git/refs/heads/self &&
220 test_must_fail git update-ref -d refs/heads/self &&
221 test_path_is_file .git/refs/heads/self
224 test_expect_success 'update-ref --no-deref -d can delete self-reference' '
225 git symbolic-ref refs/heads/self refs/heads/self &&
226 test_when_finished "rm -f .git/refs/heads/self" &&
227 test_path_is_file .git/refs/heads/self &&
228 git update-ref --no-deref -d refs/heads/self &&
229 test_path_is_missing .git/refs/heads/self
232 test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
233 >.git/refs/heads/bad &&
234 test_when_finished "rm -f .git/refs/heads/bad" &&
235 git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
236 test_when_finished "rm -f .git/refs/heads/ref-to-bad" &&
237 test_path_is_file .git/refs/heads/ref-to-bad &&
238 git update-ref --no-deref -d refs/heads/ref-to-bad &&
239 test_path_is_missing .git/refs/heads/ref-to-bad
242 test_expect_success '(not) create HEAD with old sha1' '
243 test_must_fail git update-ref HEAD $A $B
245 test_expect_success "(not) prior created .git/$m" '
246 test_when_finished "rm -f .git/$m" &&
247 test_path_is_missing .git/$m
250 test_expect_success 'create HEAD' '
251 git update-ref HEAD $A
253 test_expect_success '(not) change HEAD with wrong SHA1' '
254 test_must_fail git update-ref HEAD $B $Z
256 test_expect_success "(not) changed .git/$m" '
257 test_when_finished "rm -f .git/$m" &&
258 ! test $B = $(cat .git/$m)
261 rm -f .git/logs/refs/heads/master
262 test_expect_success "create $m (logged by touch)" '
263 test_config core.logAllRefUpdates false &&
264 GIT_COMMITTER_DATE="2005-05-26 23:30" \
265 git update-ref --create-reflog HEAD $A -m "Initial Creation" &&
266 test $A = $(cat .git/$m)
268 test_expect_success "update $m (logged by touch)" '
269 test_config core.logAllRefUpdates false &&
270 GIT_COMMITTER_DATE="2005-05-26 23:31" \
271 git update-ref HEAD $B $A -m "Switch" &&
272 test $B = $(cat .git/$m)
274 test_expect_success "set $m (logged by touch)" '
275 test_config core.logAllRefUpdates false &&
276 GIT_COMMITTER_DATE="2005-05-26 23:41" \
277 git update-ref HEAD $A &&
278 test $A = $(cat .git/$m)
281 test_expect_success 'empty directory removal' '
282 git branch d1/d2/r1 HEAD &&
283 git branch d1/r2 HEAD &&
284 test_path_is_file .git/refs/heads/d1/d2/r1 &&
285 test_path_is_file .git/logs/refs/heads/d1/d2/r1 &&
286 git branch -d d1/d2/r1 &&
287 test_path_is_missing .git/refs/heads/d1/d2 &&
288 test_path_is_missing .git/logs/refs/heads/d1/d2 &&
289 test_path_is_file .git/refs/heads/d1/r2 &&
290 test_path_is_file .git/logs/refs/heads/d1/r2
293 test_expect_success 'symref empty directory removal' '
294 git branch e1/e2/r1 HEAD &&
295 git branch e1/r2 HEAD &&
296 git checkout e1/e2/r1 &&
297 test_when_finished "git checkout master" &&
298 test_path_is_file .git/refs/heads/e1/e2/r1 &&
299 test_path_is_file .git/logs/refs/heads/e1/e2/r1 &&
300 git update-ref -d HEAD &&
301 test_path_is_missing .git/refs/heads/e1/e2 &&
302 test_path_is_missing .git/logs/refs/heads/e1/e2 &&
303 test_path_is_file .git/refs/heads/e1/r2 &&
304 test_path_is_file .git/logs/refs/heads/e1/r2 &&
305 test_path_is_file .git/logs/HEAD
309 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
310 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
311 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
313 test_expect_success "verifying $m's log (logged by touch)" '
314 test_when_finished "rm -rf .git/$m .git/logs expect" &&
315 test_cmp expect .git/logs/$m
318 test_expect_success "create $m (logged by config)" '
319 test_config core.logAllRefUpdates true &&
320 GIT_COMMITTER_DATE="2005-05-26 23:32" \
321 git update-ref HEAD $A -m "Initial Creation" &&
322 test $A = $(cat .git/$m)
324 test_expect_success "update $m (logged by config)" '
325 test_config core.logAllRefUpdates true &&
326 GIT_COMMITTER_DATE="2005-05-26 23:33" \
327 git update-ref HEAD'" $B $A "'-m "Switch" &&
328 test $B = $(cat .git/$m)
330 test_expect_success "set $m (logged by config)" '
331 test_config core.logAllRefUpdates true &&
332 GIT_COMMITTER_DATE="2005-05-26 23:43" \
333 git update-ref HEAD $A &&
334 test $A = $(cat .git/$m)
338 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
339 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
340 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
342 test_expect_success "verifying $m's log (logged by config)" '
343 test_when_finished "rm -f .git/$m .git/logs/$m expect" &&
344 test_cmp expect .git/logs/$m
347 test_expect_success 'set up for querying the reflog' '
348 git update-ref $m $D &&
349 cat >.git/logs/$m <<-EOF
350 $Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
351 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
352 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
353 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
354 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
358 ed="Thu, 26 May 2005 18:32:00 -0500"
359 gd="Thu, 26 May 2005 18:33:00 -0500"
360 ld="Thu, 26 May 2005 18:43:00 -0500"
361 test_expect_success 'Query "master@{May 25 2005}" (before history)' '
362 test_when_finished "rm -f o e" &&
363 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
364 test $C = $(cat o) &&
365 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"
367 test_expect_success 'Query master@{2005-05-25} (before history)' '
368 test_when_finished "rm -f o e" &&
369 git rev-parse --verify master@{2005-05-25} >o 2>e &&
370 test $C = $(cat o) &&
371 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"
373 test_expect_success 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' '
374 test_when_finished "rm -f o e" &&
375 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
376 test $C = $(cat o) &&
377 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"
379 test_expect_success 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' '
380 test_when_finished "rm -f o e" &&
381 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
382 test $C = $(cat o) &&
385 test_expect_success 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' '
386 test_when_finished "rm -f o e" &&
387 git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e &&
388 test $A = $(cat o) &&
391 test_expect_success 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' '
392 test_when_finished "rm -f o e" &&
393 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
394 test $B = $(cat o) &&
395 test_i18ngrep -F "warning: log for ref $m has gap after $gd" e
397 test_expect_success 'Query "master@{2005-05-26 23:38:00}" (middle of history)' '
398 test_when_finished "rm -f o e" &&
399 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
400 test $Z = $(cat o) &&
403 test_expect_success 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' '
404 test_when_finished "rm -f o e" &&
405 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
406 test $E = $(cat o) &&
409 test_expect_success 'Query "master@{2005-05-28}" (past end of history)' '
410 test_when_finished "rm -f o e" &&
411 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
412 test $D = $(cat o) &&
413 test_i18ngrep -F "warning: log for ref $m unexpectedly ended on $ld" e
416 rm -f .git/$m .git/logs/$m expect
418 test_expect_success 'creating initial files' '
419 test_when_finished rm -f M &&
422 GIT_AUTHOR_DATE="2005-05-26 23:30" \
423 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
424 h_TEST=$(git rev-parse --verify HEAD) &&
425 echo The other day this did not work. >M &&
426 echo And then Bob told me how to fix it. >>M &&
428 GIT_AUTHOR_DATE="2005-05-26 23:41" \
429 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
430 h_OTHER=$(git rev-parse --verify HEAD) &&
431 GIT_AUTHOR_DATE="2005-05-26 23:44" \
432 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
433 h_FIXED=$(git rev-parse --verify HEAD) &&
434 echo Merged initial commit and a later commit. >M &&
435 echo $h_TEST >.git/MERGE_HEAD &&
436 GIT_AUTHOR_DATE="2005-05-26 23:45" \
437 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
438 h_MERGED=$(git rev-parse --verify HEAD)
442 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
443 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
444 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
445 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
447 test_expect_success 'git commit logged updates' '
448 test_cmp expect .git/logs/$m
450 unset h_TEST h_OTHER h_FIXED h_MERGED
452 test_expect_success 'git cat-file blob master:F (expect OTHER)' '
453 test OTHER = $(git cat-file blob master:F)
455 test_expect_success 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' '
456 test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")
458 test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' '
459 test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")
462 # Test adding and deleting pseudorefs
464 test_expect_success 'given old value for missing pseudoref, do not create' '
465 test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
466 test_path_is_missing .git/PSEUDOREF &&
467 test_i18ngrep "could not read ref" err
470 test_expect_success 'create pseudoref' '
471 git update-ref PSEUDOREF $A &&
472 test $A = $(cat .git/PSEUDOREF)
475 test_expect_success 'overwrite pseudoref with no old value given' '
476 git update-ref PSEUDOREF $B &&
477 test $B = $(cat .git/PSEUDOREF)
480 test_expect_success 'overwrite pseudoref with correct old value' '
481 git update-ref PSEUDOREF $C $B &&
482 test $C = $(cat .git/PSEUDOREF)
485 test_expect_success 'do not overwrite pseudoref with wrong old value' '
486 test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
487 test $C = $(cat .git/PSEUDOREF) &&
488 test_i18ngrep "unexpected object ID" err
491 test_expect_success 'delete pseudoref' '
492 git update-ref -d PSEUDOREF &&
493 test_path_is_missing .git/PSEUDOREF
496 test_expect_success 'do not delete pseudoref with wrong old value' '
497 git update-ref PSEUDOREF $A &&
498 test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
499 test $A = $(cat .git/PSEUDOREF) &&
500 test_i18ngrep "unexpected object ID" err
503 test_expect_success 'delete pseudoref with correct old value' '
504 git update-ref -d PSEUDOREF $A &&
505 test_path_is_missing .git/PSEUDOREF
508 test_expect_success 'create pseudoref with old OID zero' '
509 git update-ref PSEUDOREF $A $Z &&
510 test $A = $(cat .git/PSEUDOREF)
513 test_expect_success 'do not overwrite pseudoref with old OID zero' '
514 test_when_finished git update-ref -d PSEUDOREF &&
515 test_must_fail git update-ref PSEUDOREF $B $Z 2>err &&
516 test $A = $(cat .git/PSEUDOREF) &&
517 test_i18ngrep "already exists" err
527 pws='path with space'
529 test_expect_success 'stdin test setup' '
530 echo "$pws" >"$pws" &&
535 test_expect_success '-z fails without --stdin' '
536 test_must_fail git update-ref -z $m $m $m 2>err &&
537 test_i18ngrep "usage: git update-ref" err
540 test_expect_success 'stdin works with no input' '
542 git update-ref --stdin <stdin &&
543 git rev-parse --verify -q $m
546 test_expect_success 'stdin fails on empty line' '
548 test_must_fail git update-ref --stdin <stdin 2>err &&
549 grep "fatal: empty command in input" err
552 test_expect_success 'stdin fails on only whitespace' '
554 test_must_fail git update-ref --stdin <stdin 2>err &&
555 grep "fatal: whitespace before command: " err
558 test_expect_success 'stdin fails on leading whitespace' '
559 echo " create $a $m" >stdin &&
560 test_must_fail git update-ref --stdin <stdin 2>err &&
561 grep "fatal: whitespace before command: create $a $m" err
564 test_expect_success 'stdin fails on unknown command' '
565 echo "unknown $a" >stdin &&
566 test_must_fail git update-ref --stdin <stdin 2>err &&
567 grep "fatal: unknown command: unknown $a" err
570 test_expect_success 'stdin fails on unbalanced quotes' '
571 echo "create $a \"master" >stdin &&
572 test_must_fail git update-ref --stdin <stdin 2>err &&
573 grep "fatal: badly quoted argument: \\\"master" err
576 test_expect_success 'stdin fails on invalid escape' '
577 echo "create $a \"ma\zter\"" >stdin &&
578 test_must_fail git update-ref --stdin <stdin 2>err &&
579 grep "fatal: badly quoted argument: \\\"ma\\\\zter\\\"" err
582 test_expect_success 'stdin fails on junk after quoted argument' '
583 echo "create \"$a\"master" >stdin &&
584 test_must_fail git update-ref --stdin <stdin 2>err &&
585 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"master" err
588 test_expect_success 'stdin fails create with no ref' '
589 echo "create " >stdin &&
590 test_must_fail git update-ref --stdin <stdin 2>err &&
591 grep "fatal: create: missing <ref>" err
594 test_expect_success 'stdin fails create with no new value' '
595 echo "create $a" >stdin &&
596 test_must_fail git update-ref --stdin <stdin 2>err &&
597 grep "fatal: create $a: missing <newvalue>" err
600 test_expect_success 'stdin fails create with too many arguments' '
601 echo "create $a $m $m" >stdin &&
602 test_must_fail git update-ref --stdin <stdin 2>err &&
603 grep "fatal: create $a: extra input: $m" err
606 test_expect_success 'stdin fails update with no ref' '
607 echo "update " >stdin &&
608 test_must_fail git update-ref --stdin <stdin 2>err &&
609 grep "fatal: update: missing <ref>" err
612 test_expect_success 'stdin fails update with no new value' '
613 echo "update $a" >stdin &&
614 test_must_fail git update-ref --stdin <stdin 2>err &&
615 grep "fatal: update $a: missing <newvalue>" err
618 test_expect_success 'stdin fails update with too many arguments' '
619 echo "update $a $m $m $m" >stdin &&
620 test_must_fail git update-ref --stdin <stdin 2>err &&
621 grep "fatal: update $a: extra input: $m" err
624 test_expect_success 'stdin fails delete with no ref' '
625 echo "delete " >stdin &&
626 test_must_fail git update-ref --stdin <stdin 2>err &&
627 grep "fatal: delete: missing <ref>" err
630 test_expect_success 'stdin fails delete with too many arguments' '
631 echo "delete $a $m $m" >stdin &&
632 test_must_fail git update-ref --stdin <stdin 2>err &&
633 grep "fatal: delete $a: extra input: $m" err
636 test_expect_success 'stdin fails verify with too many arguments' '
637 echo "verify $a $m $m" >stdin &&
638 test_must_fail git update-ref --stdin <stdin 2>err &&
639 grep "fatal: verify $a: extra input: $m" err
642 test_expect_success 'stdin fails option with unknown name' '
643 echo "option unknown" >stdin &&
644 test_must_fail git update-ref --stdin <stdin 2>err &&
645 grep "fatal: option unknown: unknown" err
648 test_expect_success 'stdin fails with duplicate refs' '
654 test_must_fail git update-ref --stdin <stdin 2>err &&
655 test_i18ngrep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
658 test_expect_success 'stdin create ref works' '
659 echo "create $a $m" >stdin &&
660 git update-ref --stdin <stdin &&
661 git rev-parse $m >expect &&
662 git rev-parse $a >actual &&
663 test_cmp expect actual
666 test_expect_success 'stdin does not create reflogs by default' '
667 test_when_finished "git update-ref -d $outside" &&
668 echo "create $outside $m" >stdin &&
669 git update-ref --stdin <stdin &&
670 git rev-parse $m >expect &&
671 git rev-parse $outside >actual &&
672 test_cmp expect actual &&
673 test_must_fail git reflog exists $outside
676 test_expect_success 'stdin creates reflogs with --create-reflog' '
677 test_when_finished "git update-ref -d $outside" &&
678 echo "create $outside $m" >stdin &&
679 git update-ref --create-reflog --stdin <stdin &&
680 git rev-parse $m >expect &&
681 git rev-parse $outside >actual &&
682 test_cmp expect actual &&
683 git reflog exists $outside
686 test_expect_success 'stdin succeeds with quoted argument' '
687 git update-ref -d $a &&
688 echo "create $a \"$m\"" >stdin &&
689 git update-ref --stdin <stdin &&
690 git rev-parse $m >expect &&
691 git rev-parse $a >actual &&
692 test_cmp expect actual
695 test_expect_success 'stdin succeeds with escaped character' '
696 git update-ref -d $a &&
697 echo "create $a \"ma\\163ter\"" >stdin &&
698 git update-ref --stdin <stdin &&
699 git rev-parse $m >expect &&
700 git rev-parse $a >actual &&
701 test_cmp expect actual
704 test_expect_success 'stdin update ref creates with zero old value' '
705 echo "update $b $m $Z" >stdin &&
706 git update-ref --stdin <stdin &&
707 git rev-parse $m >expect &&
708 git rev-parse $b >actual &&
709 test_cmp expect actual &&
713 test_expect_success 'stdin update ref creates with empty old value' '
714 echo "update $b $m $E" >stdin &&
715 git update-ref --stdin <stdin &&
716 git rev-parse $m >expect &&
717 git rev-parse $b >actual &&
718 test_cmp expect actual
721 test_expect_success 'stdin create ref works with path with space to blob' '
722 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
723 git update-ref --stdin <stdin &&
724 git rev-parse "$m:$pws" >expect &&
725 git rev-parse refs/blobs/pws >actual &&
726 test_cmp expect actual &&
727 git update-ref -d refs/blobs/pws
730 test_expect_success 'stdin update ref fails with wrong old value' '
731 echo "update $c $m $m~1" >stdin &&
732 test_must_fail git update-ref --stdin <stdin 2>err &&
733 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
734 test_must_fail git rev-parse --verify -q $c
737 test_expect_success 'stdin update ref fails with bad old value' '
738 echo "update $c $m does-not-exist" >stdin &&
739 test_must_fail git update-ref --stdin <stdin 2>err &&
740 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
741 test_must_fail git rev-parse --verify -q $c
744 test_expect_success 'stdin create ref fails with bad new value' '
745 echo "create $c does-not-exist" >stdin &&
746 test_must_fail git update-ref --stdin <stdin 2>err &&
747 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
748 test_must_fail git rev-parse --verify -q $c
751 test_expect_success 'stdin create ref fails with zero new value' '
752 echo "create $c " >stdin &&
753 test_must_fail git update-ref --stdin <stdin 2>err &&
754 grep "fatal: create $c: zero <newvalue>" err &&
755 test_must_fail git rev-parse --verify -q $c
758 test_expect_success 'stdin update ref works with right old value' '
759 echo "update $b $m~1 $m" >stdin &&
760 git update-ref --stdin <stdin &&
761 git rev-parse $m~1 >expect &&
762 git rev-parse $b >actual &&
763 test_cmp expect actual
766 test_expect_success 'stdin delete ref fails with wrong old value' '
767 echo "delete $a $m~1" >stdin &&
768 test_must_fail git update-ref --stdin <stdin 2>err &&
769 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
770 git rev-parse $m >expect &&
771 git rev-parse $a >actual &&
772 test_cmp expect actual
775 test_expect_success 'stdin delete ref fails with zero old value' '
776 echo "delete $a " >stdin &&
777 test_must_fail git update-ref --stdin <stdin 2>err &&
778 grep "fatal: delete $a: zero <oldvalue>" err &&
779 git rev-parse $m >expect &&
780 git rev-parse $a >actual &&
781 test_cmp expect actual
784 test_expect_success 'stdin update symref works option no-deref' '
785 git symbolic-ref TESTSYMREF $b &&
788 update TESTSYMREF $a $b
790 git update-ref --stdin <stdin &&
791 git rev-parse TESTSYMREF >expect &&
792 git rev-parse $a >actual &&
793 test_cmp expect actual &&
794 git rev-parse $m~1 >expect &&
795 git rev-parse $b >actual &&
796 test_cmp expect actual
799 test_expect_success 'stdin delete symref works option no-deref' '
800 git symbolic-ref TESTSYMREF $b &&
805 git update-ref --stdin <stdin &&
806 test_must_fail git rev-parse --verify -q TESTSYMREF &&
807 git rev-parse $m~1 >expect &&
808 git rev-parse $b >actual &&
809 test_cmp expect actual
812 test_expect_success 'stdin update symref works flag --no-deref' '
813 git symbolic-ref TESTSYMREFONE $b &&
814 git symbolic-ref TESTSYMREFTWO $b &&
816 update TESTSYMREFONE $a $b
817 update TESTSYMREFTWO $a $b
819 git update-ref --no-deref --stdin <stdin &&
820 git rev-parse TESTSYMREFONE TESTSYMREFTWO >expect &&
821 git rev-parse $a $a >actual &&
822 test_cmp expect actual &&
823 git rev-parse $m~1 >expect &&
824 git rev-parse $b >actual &&
825 test_cmp expect actual
828 test_expect_success 'stdin delete symref works flag --no-deref' '
829 git symbolic-ref TESTSYMREFONE $b &&
830 git symbolic-ref TESTSYMREFTWO $b &&
832 delete TESTSYMREFONE $b
833 delete TESTSYMREFTWO $b
835 git update-ref --no-deref --stdin <stdin &&
836 test_must_fail git rev-parse --verify -q TESTSYMREFONE &&
837 test_must_fail git rev-parse --verify -q TESTSYMREFTWO &&
838 git rev-parse $m~1 >expect &&
839 git rev-parse $b >actual &&
840 test_cmp expect actual
843 test_expect_success 'stdin delete ref works with right old value' '
844 echo "delete $b $m~1" >stdin &&
845 git update-ref --stdin <stdin &&
846 test_must_fail git rev-parse --verify -q $b
849 test_expect_success 'stdin update/create/verify combination works' '
855 git update-ref --stdin <stdin &&
856 git rev-parse $m >expect &&
857 git rev-parse $a >actual &&
858 test_cmp expect actual &&
859 git rev-parse $b >actual &&
860 test_cmp expect actual &&
861 test_must_fail git rev-parse --verify -q $c
864 test_expect_success 'stdin verify succeeds for correct value' '
865 git rev-parse $m >expect &&
866 echo "verify $m $m" >stdin &&
867 git update-ref --stdin <stdin &&
868 git rev-parse $m >actual &&
869 test_cmp expect actual
872 test_expect_success 'stdin verify succeeds for missing reference' '
873 echo "verify refs/heads/missing $Z" >stdin &&
874 git update-ref --stdin <stdin &&
875 test_must_fail git rev-parse --verify -q refs/heads/missing
878 test_expect_success 'stdin verify treats no value as missing' '
879 echo "verify refs/heads/missing" >stdin &&
880 git update-ref --stdin <stdin &&
881 test_must_fail git rev-parse --verify -q refs/heads/missing
884 test_expect_success 'stdin verify fails for wrong value' '
885 git rev-parse $m >expect &&
886 echo "verify $m $m~1" >stdin &&
887 test_must_fail git update-ref --stdin <stdin &&
888 git rev-parse $m >actual &&
889 test_cmp expect actual
892 test_expect_success 'stdin verify fails for mistaken null value' '
893 git rev-parse $m >expect &&
894 echo "verify $m $Z" >stdin &&
895 test_must_fail git update-ref --stdin <stdin &&
896 git rev-parse $m >actual &&
897 test_cmp expect actual
900 test_expect_success 'stdin verify fails for mistaken empty value' '
901 M=$(git rev-parse $m) &&
902 test_when_finished "git update-ref $m $M" &&
903 git rev-parse $m >expect &&
904 echo "verify $m" >stdin &&
905 test_must_fail git update-ref --stdin <stdin &&
906 git rev-parse $m >actual &&
907 test_cmp expect actual
910 test_expect_success 'stdin update refs works with identity updates' '
916 git update-ref --stdin <stdin &&
917 git rev-parse $m >expect &&
918 git rev-parse $a >actual &&
919 test_cmp expect actual &&
920 git rev-parse $b >actual &&
921 test_cmp expect actual &&
922 test_must_fail git rev-parse --verify -q $c
925 test_expect_success 'stdin update refs fails with wrong old value' '
926 git update-ref $c $m &&
932 test_must_fail git update-ref --stdin <stdin 2>err &&
933 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
934 git rev-parse $m >expect &&
935 git rev-parse $a >actual &&
936 test_cmp expect actual &&
937 git rev-parse $b >actual &&
938 test_cmp expect actual &&
939 git rev-parse $c >actual &&
940 test_cmp expect actual
943 test_expect_success 'stdin delete refs works with packed and loose refs' '
944 git pack-refs --all &&
945 git update-ref $c $m~1 &&
951 git update-ref --stdin <stdin &&
952 test_must_fail git rev-parse --verify -q $a &&
953 test_must_fail git rev-parse --verify -q $b &&
954 test_must_fail git rev-parse --verify -q $c
957 test_expect_success 'stdin -z works on empty input' '
959 git update-ref -z --stdin <stdin &&
960 git rev-parse --verify -q $m
963 test_expect_success 'stdin -z fails on empty line' '
965 test_must_fail git update-ref -z --stdin <stdin 2>err &&
966 grep "fatal: whitespace before command: " err
969 test_expect_success 'stdin -z fails on empty command' '
970 printf $F "" >stdin &&
971 test_must_fail git update-ref -z --stdin <stdin 2>err &&
972 grep "fatal: empty command in input" err
975 test_expect_success 'stdin -z fails on only whitespace' '
976 printf $F " " >stdin &&
977 test_must_fail git update-ref -z --stdin <stdin 2>err &&
978 grep "fatal: whitespace before command: " err
981 test_expect_success 'stdin -z fails on leading whitespace' '
982 printf $F " create $a" "$m" >stdin &&
983 test_must_fail git update-ref -z --stdin <stdin 2>err &&
984 grep "fatal: whitespace before command: create $a" err
987 test_expect_success 'stdin -z fails on unknown command' '
988 printf $F "unknown $a" >stdin &&
989 test_must_fail git update-ref -z --stdin <stdin 2>err &&
990 grep "fatal: unknown command: unknown $a" err
993 test_expect_success 'stdin -z fails create with no ref' '
994 printf $F "create " >stdin &&
995 test_must_fail git update-ref -z --stdin <stdin 2>err &&
996 grep "fatal: create: missing <ref>" err
999 test_expect_success 'stdin -z fails create with no new value' '
1000 printf $F "create $a" >stdin &&
1001 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1002 grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
1005 test_expect_success 'stdin -z fails create with too many arguments' '
1006 printf $F "create $a" "$m" "$m" >stdin &&
1007 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1008 grep "fatal: unknown command: $m" err
1011 test_expect_success 'stdin -z fails update with no ref' '
1012 printf $F "update " >stdin &&
1013 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1014 grep "fatal: update: missing <ref>" err
1017 test_expect_success 'stdin -z fails update with too few args' '
1018 printf $F "update $a" "$m" >stdin &&
1019 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1020 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
1023 test_expect_success 'stdin -z emits warning with empty new value' '
1024 git update-ref $a $m &&
1025 printf $F "update $a" "" "" >stdin &&
1026 git update-ref -z --stdin <stdin 2>err &&
1027 grep "warning: update $a: missing <newvalue>, treating as zero" err &&
1028 test_must_fail git rev-parse --verify -q $a
1031 test_expect_success 'stdin -z fails update with no new value' '
1032 printf $F "update $a" >stdin &&
1033 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1034 grep "fatal: update $a: unexpected end of input when reading <newvalue>" err
1037 test_expect_success 'stdin -z fails update with no old value' '
1038 printf $F "update $a" "$m" >stdin &&
1039 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1040 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
1043 test_expect_success 'stdin -z fails update with too many arguments' '
1044 printf $F "update $a" "$m" "$m" "$m" >stdin &&
1045 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1046 grep "fatal: unknown command: $m" err
1049 test_expect_success 'stdin -z fails delete with no ref' '
1050 printf $F "delete " >stdin &&
1051 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1052 grep "fatal: delete: missing <ref>" err
1055 test_expect_success 'stdin -z fails delete with no old value' '
1056 printf $F "delete $a" >stdin &&
1057 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1058 grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
1061 test_expect_success 'stdin -z fails delete with too many arguments' '
1062 printf $F "delete $a" "$m" "$m" >stdin &&
1063 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1064 grep "fatal: unknown command: $m" err
1067 test_expect_success 'stdin -z fails verify with too many arguments' '
1068 printf $F "verify $a" "$m" "$m" >stdin &&
1069 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1070 grep "fatal: unknown command: $m" err
1073 test_expect_success 'stdin -z fails verify with no old value' '
1074 printf $F "verify $a" >stdin &&
1075 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1076 grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err
1079 test_expect_success 'stdin -z fails option with unknown name' '
1080 printf $F "option unknown" >stdin &&
1081 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1082 grep "fatal: option unknown: unknown" err
1085 test_expect_success 'stdin -z fails with duplicate refs' '
1086 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
1087 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1088 test_i18ngrep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
1091 test_expect_success 'stdin -z create ref works' '
1092 printf $F "create $a" "$m" >stdin &&
1093 git update-ref -z --stdin <stdin &&
1094 git rev-parse $m >expect &&
1095 git rev-parse $a >actual &&
1096 test_cmp expect actual
1099 test_expect_success 'stdin -z update ref creates with zero old value' '
1100 printf $F "update $b" "$m" "$Z" >stdin &&
1101 git update-ref -z --stdin <stdin &&
1102 git rev-parse $m >expect &&
1103 git rev-parse $b >actual &&
1104 test_cmp expect actual &&
1105 git update-ref -d $b
1108 test_expect_success 'stdin -z update ref creates with empty old value' '
1109 printf $F "update $b" "$m" "" >stdin &&
1110 git update-ref -z --stdin <stdin &&
1111 git rev-parse $m >expect &&
1112 git rev-parse $b >actual &&
1113 test_cmp expect actual
1116 test_expect_success 'stdin -z create ref works with path with space to blob' '
1117 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
1118 git update-ref -z --stdin <stdin &&
1119 git rev-parse "$m:$pws" >expect &&
1120 git rev-parse refs/blobs/pws >actual &&
1121 test_cmp expect actual &&
1122 git update-ref -d refs/blobs/pws
1125 test_expect_success 'stdin -z update ref fails with wrong old value' '
1126 printf $F "update $c" "$m" "$m~1" >stdin &&
1127 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1128 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1129 test_must_fail git rev-parse --verify -q $c
1132 test_expect_success 'stdin -z update ref fails with bad old value' '
1133 printf $F "update $c" "$m" "does-not-exist" >stdin &&
1134 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1135 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
1136 test_must_fail git rev-parse --verify -q $c
1139 test_expect_success 'stdin -z create ref fails when ref exists' '
1140 git update-ref $c $m &&
1141 git rev-parse "$c" >expect &&
1142 printf $F "create $c" "$m~1" >stdin &&
1143 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1144 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1145 git rev-parse "$c" >actual &&
1146 test_cmp expect actual
1149 test_expect_success 'stdin -z create ref fails with bad new value' '
1150 git update-ref -d "$c" &&
1151 printf $F "create $c" "does-not-exist" >stdin &&
1152 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1153 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
1154 test_must_fail git rev-parse --verify -q $c
1157 test_expect_success 'stdin -z create ref fails with empty new value' '
1158 printf $F "create $c" "" >stdin &&
1159 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1160 grep "fatal: create $c: missing <newvalue>" err &&
1161 test_must_fail git rev-parse --verify -q $c
1164 test_expect_success 'stdin -z update ref works with right old value' '
1165 printf $F "update $b" "$m~1" "$m" >stdin &&
1166 git update-ref -z --stdin <stdin &&
1167 git rev-parse $m~1 >expect &&
1168 git rev-parse $b >actual &&
1169 test_cmp expect actual
1172 test_expect_success 'stdin -z delete ref fails with wrong old value' '
1173 printf $F "delete $a" "$m~1" >stdin &&
1174 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1175 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
1176 git rev-parse $m >expect &&
1177 git rev-parse $a >actual &&
1178 test_cmp expect actual
1181 test_expect_success 'stdin -z delete ref fails with zero old value' '
1182 printf $F "delete $a" "$Z" >stdin &&
1183 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1184 grep "fatal: delete $a: zero <oldvalue>" err &&
1185 git rev-parse $m >expect &&
1186 git rev-parse $a >actual &&
1187 test_cmp expect actual
1190 test_expect_success 'stdin -z update symref works option no-deref' '
1191 git symbolic-ref TESTSYMREF $b &&
1192 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
1193 git update-ref -z --stdin <stdin &&
1194 git rev-parse TESTSYMREF >expect &&
1195 git rev-parse $a >actual &&
1196 test_cmp expect actual &&
1197 git rev-parse $m~1 >expect &&
1198 git rev-parse $b >actual &&
1199 test_cmp expect actual
1202 test_expect_success 'stdin -z delete symref works option no-deref' '
1203 git symbolic-ref TESTSYMREF $b &&
1204 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
1205 git update-ref -z --stdin <stdin &&
1206 test_must_fail git rev-parse --verify -q TESTSYMREF &&
1207 git rev-parse $m~1 >expect &&
1208 git rev-parse $b >actual &&
1209 test_cmp expect actual
1212 test_expect_success 'stdin -z delete ref works with right old value' '
1213 printf $F "delete $b" "$m~1" >stdin &&
1214 git update-ref -z --stdin <stdin &&
1215 test_must_fail git rev-parse --verify -q $b
1218 test_expect_success 'stdin -z update/create/verify combination works' '
1219 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
1220 git update-ref -z --stdin <stdin &&
1221 git rev-parse $m >expect &&
1222 git rev-parse $a >actual &&
1223 test_cmp expect actual &&
1224 git rev-parse $b >actual &&
1225 test_cmp expect actual &&
1226 test_must_fail git rev-parse --verify -q $c
1229 test_expect_success 'stdin -z verify succeeds for correct value' '
1230 git rev-parse $m >expect &&
1231 printf $F "verify $m" "$m" >stdin &&
1232 git update-ref -z --stdin <stdin &&
1233 git rev-parse $m >actual &&
1234 test_cmp expect actual
1237 test_expect_success 'stdin -z verify succeeds for missing reference' '
1238 printf $F "verify refs/heads/missing" "$Z" >stdin &&
1239 git update-ref -z --stdin <stdin &&
1240 test_must_fail git rev-parse --verify -q refs/heads/missing
1243 test_expect_success 'stdin -z verify treats no value as missing' '
1244 printf $F "verify refs/heads/missing" "" >stdin &&
1245 git update-ref -z --stdin <stdin &&
1246 test_must_fail git rev-parse --verify -q refs/heads/missing
1249 test_expect_success 'stdin -z verify fails for wrong value' '
1250 git rev-parse $m >expect &&
1251 printf $F "verify $m" "$m~1" >stdin &&
1252 test_must_fail git update-ref -z --stdin <stdin &&
1253 git rev-parse $m >actual &&
1254 test_cmp expect actual
1257 test_expect_success 'stdin -z verify fails for mistaken null value' '
1258 git rev-parse $m >expect &&
1259 printf $F "verify $m" "$Z" >stdin &&
1260 test_must_fail git update-ref -z --stdin <stdin &&
1261 git rev-parse $m >actual &&
1262 test_cmp expect actual
1265 test_expect_success 'stdin -z verify fails for mistaken empty value' '
1266 M=$(git rev-parse $m) &&
1267 test_when_finished "git update-ref $m $M" &&
1268 git rev-parse $m >expect &&
1269 printf $F "verify $m" "" >stdin &&
1270 test_must_fail git update-ref -z --stdin <stdin &&
1271 git rev-parse $m >actual &&
1272 test_cmp expect actual
1275 test_expect_success 'stdin -z update refs works with identity updates' '
1276 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
1277 git update-ref -z --stdin <stdin &&
1278 git rev-parse $m >expect &&
1279 git rev-parse $a >actual &&
1280 test_cmp expect actual &&
1281 git rev-parse $b >actual &&
1282 test_cmp expect actual &&
1283 test_must_fail git rev-parse --verify -q $c
1286 test_expect_success 'stdin -z update refs fails with wrong old value' '
1287 git update-ref $c $m &&
1288 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
1289 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1290 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1291 git rev-parse $m >expect &&
1292 git rev-parse $a >actual &&
1293 test_cmp expect actual &&
1294 git rev-parse $b >actual &&
1295 test_cmp expect actual &&
1296 git rev-parse $c >actual &&
1297 test_cmp expect actual
1300 test_expect_success 'stdin -z delete refs works with packed and loose refs' '
1301 git pack-refs --all &&
1302 git update-ref $c $m~1 &&
1303 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
1304 git update-ref -z --stdin <stdin &&
1305 test_must_fail git rev-parse --verify -q $a &&
1306 test_must_fail git rev-parse --verify -q $b &&
1307 test_must_fail git rev-parse --verify -q $c
1310 test_expect_success 'fails with duplicate HEAD update' '
1311 git branch target1 $A &&
1312 git checkout target1 &&
1313 cat >stdin <<-EOF &&
1314 update refs/heads/target1 $C
1318 test_must_fail git update-ref --stdin <stdin 2>err &&
1319 test_i18ngrep "fatal: multiple updates for '\''HEAD'\'' (including one via its referent .refs/heads/target1.) are not allowed" err &&
1320 echo "refs/heads/target1" >expect &&
1321 git symbolic-ref HEAD >actual &&
1322 test_cmp expect actual &&
1323 echo "$A" >expect &&
1324 git rev-parse refs/heads/target1 >actual &&
1325 test_cmp expect actual
1328 test_expect_success 'fails with duplicate ref update via symref' '
1329 git branch target2 $A &&
1330 git symbolic-ref refs/heads/symref2 refs/heads/target2 &&
1331 cat >stdin <<-EOF &&
1332 update refs/heads/target2 $C
1333 update refs/heads/symref2 $B
1335 test_must_fail git update-ref --stdin <stdin 2>err &&
1336 test_i18ngrep "fatal: multiple updates for '\''refs/heads/target2'\'' (including one via symref .refs/heads/symref2.) are not allowed" err &&
1337 echo "refs/heads/target2" >expect &&
1338 git symbolic-ref refs/heads/symref2 >actual &&
1339 test_cmp expect actual &&
1340 echo "$A" >expect &&
1341 git rev-parse refs/heads/target2 >actual &&
1342 test_cmp expect actual
1345 run_with_limited_open_files () {
1346 (ulimit -n 32 && "$@")
1349 test_lazy_prereq ULIMIT_FILE_DESCRIPTORS '
1350 test_have_prereq !MINGW,!CYGWIN &&
1351 run_with_limited_open_files true
1354 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' '
1356 for i in $(test_seq 33)
1358 echo "create refs/heads/$i HEAD"
1359 done >large_input &&
1360 run_with_limited_open_files git update-ref --stdin <large_input &&
1361 git rev-parse --verify -q refs/heads/33
1365 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches does not burst open file limit' '
1367 for i in $(test_seq 33)
1369 echo "delete refs/heads/$i HEAD"
1370 done >large_input &&
1371 run_with_limited_open_files git update-ref --stdin <large_input &&
1372 test_must_fail git rev-parse --verify -q refs/heads/33
1376 test_expect_success 'handle per-worktree refs in refs/bisect' '
1377 git commit --allow-empty -m "initial commit" &&
1378 git worktree add -b branch worktree &&
1381 git commit --allow-empty -m "test commit" &&
1382 git for-each-ref >for-each-ref.out &&
1383 ! grep refs/bisect for-each-ref.out &&
1384 git update-ref refs/bisect/something HEAD &&
1385 git rev-parse refs/bisect/something >../worktree-head &&
1386 git for-each-ref | grep refs/bisect/something
1388 test_path_is_missing .git/refs/bisect &&
1389 test_must_fail git rev-parse refs/bisect/something &&
1390 git update-ref refs/bisect/something HEAD &&
1391 git rev-parse refs/bisect/something >main-head &&
1392 ! test_cmp main-head worktree-head