]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1400-update-ref.sh
files_transaction_commit(): clean up empty directories
[thirdparty/git.git] / t / t1400-update-ref.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Shawn Pearce
4 #
5
6 test_description='Test git update-ref and basic ref logging'
7 . ./test-lib.sh
8
9 Z=$_z40
10
11 test_expect_success setup '
12
13 for name in A B C D E F
14 do
15 test_tick &&
16 T=$(git write-tree) &&
17 sha1=$(echo $name | git commit-tree $T) &&
18 eval $name=$sha1
19 done
20
21 '
22
23 m=refs/heads/master
24 n_dir=refs/heads/gu
25 n=$n_dir/fixes
26 outside=refs/foo
27
28 test_expect_success \
29 "create $m" \
30 "git update-ref $m $A &&
31 test $A"' = $(cat .git/'"$m"')'
32 test_expect_success \
33 "create $m" \
34 "git update-ref $m $B $A &&
35 test $B"' = $(cat .git/'"$m"')'
36 test_expect_success "fail to delete $m with stale ref" '
37 test_must_fail git update-ref -d $m $A &&
38 test $B = "$(cat .git/$m)"
39 '
40 test_expect_success "delete $m" '
41 git update-ref -d $m $B &&
42 ! test -f .git/$m
43 '
44 rm -f .git/$m
45
46 test_expect_success "delete $m without oldvalue verification" "
47 git update-ref $m $A &&
48 test $A = \$(cat .git/$m) &&
49 git update-ref -d $m &&
50 ! test -f .git/$m
51 "
52 rm -f .git/$m
53
54 test_expect_success \
55 "fail to create $n" \
56 "touch .git/$n_dir &&
57 test_must_fail git update-ref $n $A >out 2>err"
58 rm -f .git/$n_dir out err
59
60 test_expect_success \
61 "create $m (by HEAD)" \
62 "git update-ref HEAD $A &&
63 test $A"' = $(cat .git/'"$m"')'
64 test_expect_success \
65 "create $m (by HEAD)" \
66 "git update-ref HEAD $B $A &&
67 test $B"' = $(cat .git/'"$m"')'
68 test_expect_success "fail to delete $m (by HEAD) with stale ref" '
69 test_must_fail git update-ref -d HEAD $A &&
70 test $B = $(cat .git/$m)
71 '
72 test_expect_success "delete $m (by HEAD)" '
73 git update-ref -d HEAD $B &&
74 ! test -f .git/$m
75 '
76 rm -f .git/$m
77
78 test_expect_success 'update-ref does not create reflogs by default' '
79 test_when_finished "git update-ref -d $outside" &&
80 git update-ref $outside $A &&
81 git rev-parse $A >expect &&
82 git rev-parse $outside >actual &&
83 test_cmp expect actual &&
84 test_must_fail git reflog exists $outside
85 '
86
87 test_expect_success 'update-ref creates reflogs with --create-reflog' '
88 test_when_finished "git update-ref -d $outside" &&
89 git update-ref --create-reflog $outside $A &&
90 git rev-parse $A >expect &&
91 git rev-parse $outside >actual &&
92 test_cmp expect actual &&
93 git reflog exists $outside
94 '
95
96 test_expect_success \
97 "create $m (by HEAD)" \
98 "git update-ref HEAD $A &&
99 test $A"' = $(cat .git/'"$m"')'
100 test_expect_success \
101 "pack refs" \
102 "git pack-refs --all"
103 test_expect_success \
104 "move $m (by HEAD)" \
105 "git update-ref HEAD $B $A &&
106 test $B"' = $(cat .git/'"$m"')'
107 test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" '
108 git update-ref -d HEAD $B &&
109 ! grep "$m" .git/packed-refs &&
110 ! test -f .git/$m
111 '
112 rm -f .git/$m
113
114 cp -f .git/HEAD .git/HEAD.orig
115 test_expect_success "delete symref without dereference" '
116 git update-ref --no-deref -d HEAD &&
117 ! test -f .git/HEAD
118 '
119 cp -f .git/HEAD.orig .git/HEAD
120
121 test_expect_success "delete symref without dereference when the referred ref is packed" '
122 echo foo >foo.c &&
123 git add foo.c &&
124 git commit -m foo &&
125 git pack-refs --all &&
126 git update-ref --no-deref -d HEAD &&
127 ! test -f .git/HEAD
128 '
129 cp -f .git/HEAD.orig .git/HEAD
130 git update-ref -d $m
131
132 test_expect_success 'update-ref -d is not confused by self-reference' '
133 git symbolic-ref refs/heads/self refs/heads/self &&
134 test_when_finished "rm -f .git/refs/heads/self" &&
135 test_path_is_file .git/refs/heads/self &&
136 test_must_fail git update-ref -d refs/heads/self &&
137 test_path_is_file .git/refs/heads/self
138 '
139
140 test_expect_success 'update-ref --no-deref -d can delete self-reference' '
141 git symbolic-ref refs/heads/self refs/heads/self &&
142 test_when_finished "rm -f .git/refs/heads/self" &&
143 test_path_is_file .git/refs/heads/self &&
144 git update-ref --no-deref -d refs/heads/self &&
145 test_path_is_missing .git/refs/heads/self
146 '
147
148 test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
149 >.git/refs/heads/bad &&
150 test_when_finished "rm -f .git/refs/heads/bad" &&
151 git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
152 test_when_finished "rm -f .git/refs/heads/ref-to-bad" &&
153 test_path_is_file .git/refs/heads/ref-to-bad &&
154 git update-ref --no-deref -d refs/heads/ref-to-bad &&
155 test_path_is_missing .git/refs/heads/ref-to-bad
156 '
157
158 test_expect_success '(not) create HEAD with old sha1' "
159 test_must_fail git update-ref HEAD $A $B
160 "
161 test_expect_success "(not) prior created .git/$m" "
162 ! test -f .git/$m
163 "
164 rm -f .git/$m
165
166 test_expect_success \
167 "create HEAD" \
168 "git update-ref HEAD $A"
169 test_expect_success '(not) change HEAD with wrong SHA1' "
170 test_must_fail git update-ref HEAD $B $Z
171 "
172 test_expect_success "(not) changed .git/$m" "
173 ! test $B"' = $(cat .git/'"$m"')
174 '
175 rm -f .git/$m
176
177 rm -f .git/logs/refs/heads/master
178 test_expect_success \
179 "create $m (logged by touch)" \
180 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
181 git update-ref --create-reflog HEAD '"$A"' -m "Initial Creation" &&
182 test '"$A"' = $(cat .git/'"$m"')'
183 test_expect_success \
184 "update $m (logged by touch)" \
185 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
186 git update-ref HEAD'" $B $A "'-m "Switch" &&
187 test '"$B"' = $(cat .git/'"$m"')'
188 test_expect_success \
189 "set $m (logged by touch)" \
190 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
191 git update-ref HEAD'" $A &&
192 test $A"' = $(cat .git/'"$m"')'
193
194 test_expect_success "empty directory removal" '
195 git branch d1/d2/r1 HEAD &&
196 git branch d1/r2 HEAD &&
197 test -f .git/refs/heads/d1/d2/r1 &&
198 test -f .git/logs/refs/heads/d1/d2/r1 &&
199 git branch -d d1/d2/r1 &&
200 ! test -e .git/refs/heads/d1/d2 &&
201 ! test -e .git/logs/refs/heads/d1/d2 &&
202 test -f .git/refs/heads/d1/r2 &&
203 test -f .git/logs/refs/heads/d1/r2
204 '
205
206 test_expect_success "symref empty directory removal" '
207 git branch e1/e2/r1 HEAD &&
208 git branch e1/r2 HEAD &&
209 git checkout e1/e2/r1 &&
210 test_when_finished "git checkout master" &&
211 test -f .git/refs/heads/e1/e2/r1 &&
212 test -f .git/logs/refs/heads/e1/e2/r1 &&
213 git update-ref -d HEAD &&
214 ! test -e .git/refs/heads/e1/e2 &&
215 ! test -e .git/logs/refs/heads/e1/e2 &&
216 test -f .git/refs/heads/e1/r2 &&
217 test -f .git/logs/refs/heads/e1/r2 &&
218 test -f .git/logs/HEAD
219 '
220
221 cat >expect <<EOF
222 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
223 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
224 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
225 EOF
226 test_expect_success \
227 "verifying $m's log" \
228 "test_cmp expect .git/logs/$m"
229 rm -rf .git/$m .git/logs expect
230
231 test_expect_success \
232 'enable core.logAllRefUpdates' \
233 'git config core.logAllRefUpdates true &&
234 test true = $(git config --bool --get core.logAllRefUpdates)'
235
236 test_expect_success \
237 "create $m (logged by config)" \
238 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
239 git update-ref HEAD'" $A "'-m "Initial Creation" &&
240 test '"$A"' = $(cat .git/'"$m"')'
241 test_expect_success \
242 "update $m (logged by config)" \
243 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
244 git update-ref HEAD'" $B $A "'-m "Switch" &&
245 test '"$B"' = $(cat .git/'"$m"')'
246 test_expect_success \
247 "set $m (logged by config)" \
248 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
249 git update-ref HEAD '"$A &&
250 test $A"' = $(cat .git/'"$m"')'
251
252 cat >expect <<EOF
253 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
254 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
255 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
256 EOF
257 test_expect_success \
258 "verifying $m's log" \
259 'test_cmp expect .git/logs/$m'
260 rm -f .git/$m .git/logs/$m expect
261
262 git update-ref $m $D
263 cat >.git/logs/$m <<EOF
264 0000000000000000000000000000000000000000 $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
265 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
266 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
267 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
268 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
269 EOF
270
271 ed="Thu, 26 May 2005 18:32:00 -0500"
272 gd="Thu, 26 May 2005 18:33:00 -0500"
273 ld="Thu, 26 May 2005 18:43:00 -0500"
274 test_expect_success \
275 'Query "master@{May 25 2005}" (before history)' \
276 'rm -f o e &&
277 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
278 test '"$C"' = $(cat o) &&
279 test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
280 test_expect_success \
281 "Query master@{2005-05-25} (before history)" \
282 'rm -f o e &&
283 git rev-parse --verify master@{2005-05-25} >o 2>e &&
284 test '"$C"' = $(cat o) &&
285 echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
286 test_expect_success \
287 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
288 'rm -f o e &&
289 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
290 test '"$C"' = $(cat o) &&
291 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
292 test_expect_success \
293 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
294 'rm -f o e &&
295 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
296 test '"$C"' = $(cat o) &&
297 test "" = "$(cat e)"'
298 test_expect_success \
299 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \
300 'rm -f o e &&
301 git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e &&
302 test '"$A"' = $(cat o) &&
303 test "" = "$(cat e)"'
304 test_expect_success \
305 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
306 'rm -f o e &&
307 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
308 test '"$B"' = $(cat o) &&
309 test "warning: Log for ref '"$m has gap after $gd"'." = "$(cat e)"'
310 test_expect_success \
311 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
312 'rm -f o e &&
313 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
314 test '"$Z"' = $(cat o) &&
315 test "" = "$(cat e)"'
316 test_expect_success \
317 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
318 'rm -f o e &&
319 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
320 test '"$E"' = $(cat o) &&
321 test "" = "$(cat e)"'
322 test_expect_success \
323 'Query "master@{2005-05-28}" (past end of history)' \
324 'rm -f o e &&
325 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
326 test '"$D"' = $(cat o) &&
327 test "warning: Log for ref '"$m unexpectedly ended on $ld"'." = "$(cat e)"'
328
329
330 rm -f .git/$m .git/logs/$m expect
331
332 test_expect_success \
333 'creating initial files' \
334 'echo TEST >F &&
335 git add F &&
336 GIT_AUTHOR_DATE="2005-05-26 23:30" \
337 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
338 h_TEST=$(git rev-parse --verify HEAD) &&
339 echo The other day this did not work. >M &&
340 echo And then Bob told me how to fix it. >>M &&
341 echo OTHER >F &&
342 GIT_AUTHOR_DATE="2005-05-26 23:41" \
343 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
344 h_OTHER=$(git rev-parse --verify HEAD) &&
345 GIT_AUTHOR_DATE="2005-05-26 23:44" \
346 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
347 h_FIXED=$(git rev-parse --verify HEAD) &&
348 echo Merged initial commit and a later commit. >M &&
349 echo $h_TEST >.git/MERGE_HEAD &&
350 GIT_AUTHOR_DATE="2005-05-26 23:45" \
351 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
352 h_MERGED=$(git rev-parse --verify HEAD) &&
353 rm -f M'
354
355 cat >expect <<EOF
356 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
357 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
358 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
359 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
360 EOF
361 test_expect_success \
362 'git commit logged updates' \
363 "test_cmp expect .git/logs/$m"
364 unset h_TEST h_OTHER h_FIXED h_MERGED
365
366 test_expect_success \
367 'git cat-file blob master:F (expect OTHER)' \
368 'test OTHER = $(git cat-file blob master:F)'
369 test_expect_success \
370 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
371 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")'
372 test_expect_success \
373 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
374 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'
375
376 a=refs/heads/a
377 b=refs/heads/b
378 c=refs/heads/c
379 E='""'
380 F='%s\0'
381 pws='path with space'
382
383 test_expect_success 'stdin test setup' '
384 echo "$pws" >"$pws" &&
385 git add -- "$pws" &&
386 git commit -m "$pws"
387 '
388
389 test_expect_success '-z fails without --stdin' '
390 test_must_fail git update-ref -z $m $m $m 2>err &&
391 test_i18ngrep "usage: git update-ref" err
392 '
393
394 test_expect_success 'stdin works with no input' '
395 >stdin &&
396 git update-ref --stdin <stdin &&
397 git rev-parse --verify -q $m
398 '
399
400 test_expect_success 'stdin fails on empty line' '
401 echo "" >stdin &&
402 test_must_fail git update-ref --stdin <stdin 2>err &&
403 grep "fatal: empty command in input" err
404 '
405
406 test_expect_success 'stdin fails on only whitespace' '
407 echo " " >stdin &&
408 test_must_fail git update-ref --stdin <stdin 2>err &&
409 grep "fatal: whitespace before command: " err
410 '
411
412 test_expect_success 'stdin fails on leading whitespace' '
413 echo " create $a $m" >stdin &&
414 test_must_fail git update-ref --stdin <stdin 2>err &&
415 grep "fatal: whitespace before command: create $a $m" err
416 '
417
418 test_expect_success 'stdin fails on unknown command' '
419 echo "unknown $a" >stdin &&
420 test_must_fail git update-ref --stdin <stdin 2>err &&
421 grep "fatal: unknown command: unknown $a" err
422 '
423
424 test_expect_success 'stdin fails on unbalanced quotes' '
425 echo "create $a \"master" >stdin &&
426 test_must_fail git update-ref --stdin <stdin 2>err &&
427 grep "fatal: badly quoted argument: \\\"master" err
428 '
429
430 test_expect_success 'stdin fails on invalid escape' '
431 echo "create $a \"ma\zter\"" >stdin &&
432 test_must_fail git update-ref --stdin <stdin 2>err &&
433 grep "fatal: badly quoted argument: \\\"ma\\\\zter\\\"" err
434 '
435
436 test_expect_success 'stdin fails on junk after quoted argument' '
437 echo "create \"$a\"master" >stdin &&
438 test_must_fail git update-ref --stdin <stdin 2>err &&
439 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"master" err
440 '
441
442 test_expect_success 'stdin fails create with no ref' '
443 echo "create " >stdin &&
444 test_must_fail git update-ref --stdin <stdin 2>err &&
445 grep "fatal: create: missing <ref>" err
446 '
447
448 test_expect_success 'stdin fails create with no new value' '
449 echo "create $a" >stdin &&
450 test_must_fail git update-ref --stdin <stdin 2>err &&
451 grep "fatal: create $a: missing <newvalue>" err
452 '
453
454 test_expect_success 'stdin fails create with too many arguments' '
455 echo "create $a $m $m" >stdin &&
456 test_must_fail git update-ref --stdin <stdin 2>err &&
457 grep "fatal: create $a: extra input: $m" err
458 '
459
460 test_expect_success 'stdin fails update with no ref' '
461 echo "update " >stdin &&
462 test_must_fail git update-ref --stdin <stdin 2>err &&
463 grep "fatal: update: missing <ref>" err
464 '
465
466 test_expect_success 'stdin fails update with no new value' '
467 echo "update $a" >stdin &&
468 test_must_fail git update-ref --stdin <stdin 2>err &&
469 grep "fatal: update $a: missing <newvalue>" err
470 '
471
472 test_expect_success 'stdin fails update with too many arguments' '
473 echo "update $a $m $m $m" >stdin &&
474 test_must_fail git update-ref --stdin <stdin 2>err &&
475 grep "fatal: update $a: extra input: $m" err
476 '
477
478 test_expect_success 'stdin fails delete with no ref' '
479 echo "delete " >stdin &&
480 test_must_fail git update-ref --stdin <stdin 2>err &&
481 grep "fatal: delete: missing <ref>" err
482 '
483
484 test_expect_success 'stdin fails delete with too many arguments' '
485 echo "delete $a $m $m" >stdin &&
486 test_must_fail git update-ref --stdin <stdin 2>err &&
487 grep "fatal: delete $a: extra input: $m" err
488 '
489
490 test_expect_success 'stdin fails verify with too many arguments' '
491 echo "verify $a $m $m" >stdin &&
492 test_must_fail git update-ref --stdin <stdin 2>err &&
493 grep "fatal: verify $a: extra input: $m" err
494 '
495
496 test_expect_success 'stdin fails option with unknown name' '
497 echo "option unknown" >stdin &&
498 test_must_fail git update-ref --stdin <stdin 2>err &&
499 grep "fatal: option unknown: unknown" err
500 '
501
502 test_expect_success 'stdin fails with duplicate refs' '
503 cat >stdin <<-EOF &&
504 create $a $m
505 create $b $m
506 create $a $m
507 EOF
508 test_must_fail git update-ref --stdin <stdin 2>err &&
509 grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed." err
510 '
511
512 test_expect_success 'stdin create ref works' '
513 echo "create $a $m" >stdin &&
514 git update-ref --stdin <stdin &&
515 git rev-parse $m >expect &&
516 git rev-parse $a >actual &&
517 test_cmp expect actual
518 '
519
520 test_expect_success 'stdin does not create reflogs by default' '
521 test_when_finished "git update-ref -d $outside" &&
522 echo "create $outside $m" >stdin &&
523 git update-ref --stdin <stdin &&
524 git rev-parse $m >expect &&
525 git rev-parse $outside >actual &&
526 test_cmp expect actual &&
527 test_must_fail git reflog exists $outside
528 '
529
530 test_expect_success 'stdin creates reflogs with --create-reflog' '
531 echo "create $outside $m" >stdin &&
532 git update-ref --create-reflog --stdin <stdin &&
533 git rev-parse $m >expect &&
534 git rev-parse $outside >actual &&
535 test_cmp expect actual &&
536 git reflog exists $outside
537 '
538
539 test_expect_success 'stdin succeeds with quoted argument' '
540 git update-ref -d $a &&
541 echo "create $a \"$m\"" >stdin &&
542 git update-ref --stdin <stdin &&
543 git rev-parse $m >expect &&
544 git rev-parse $a >actual &&
545 test_cmp expect actual
546 '
547
548 test_expect_success 'stdin succeeds with escaped character' '
549 git update-ref -d $a &&
550 echo "create $a \"ma\\163ter\"" >stdin &&
551 git update-ref --stdin <stdin &&
552 git rev-parse $m >expect &&
553 git rev-parse $a >actual &&
554 test_cmp expect actual
555 '
556
557 test_expect_success 'stdin update ref creates with zero old value' '
558 echo "update $b $m $Z" >stdin &&
559 git update-ref --stdin <stdin &&
560 git rev-parse $m >expect &&
561 git rev-parse $b >actual &&
562 test_cmp expect actual &&
563 git update-ref -d $b
564 '
565
566 test_expect_success 'stdin update ref creates with empty old value' '
567 echo "update $b $m $E" >stdin &&
568 git update-ref --stdin <stdin &&
569 git rev-parse $m >expect &&
570 git rev-parse $b >actual &&
571 test_cmp expect actual
572 '
573
574 test_expect_success 'stdin create ref works with path with space to blob' '
575 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
576 git update-ref --stdin <stdin &&
577 git rev-parse "$m:$pws" >expect &&
578 git rev-parse refs/blobs/pws >actual &&
579 test_cmp expect actual &&
580 git update-ref -d refs/blobs/pws
581 '
582
583 test_expect_success 'stdin update ref fails with wrong old value' '
584 echo "update $c $m $m~1" >stdin &&
585 test_must_fail git update-ref --stdin <stdin 2>err &&
586 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
587 test_must_fail git rev-parse --verify -q $c
588 '
589
590 test_expect_success 'stdin update ref fails with bad old value' '
591 echo "update $c $m does-not-exist" >stdin &&
592 test_must_fail git update-ref --stdin <stdin 2>err &&
593 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
594 test_must_fail git rev-parse --verify -q $c
595 '
596
597 test_expect_success 'stdin create ref fails with bad new value' '
598 echo "create $c does-not-exist" >stdin &&
599 test_must_fail git update-ref --stdin <stdin 2>err &&
600 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
601 test_must_fail git rev-parse --verify -q $c
602 '
603
604 test_expect_success 'stdin create ref fails with zero new value' '
605 echo "create $c " >stdin &&
606 test_must_fail git update-ref --stdin <stdin 2>err &&
607 grep "fatal: create $c: zero <newvalue>" err &&
608 test_must_fail git rev-parse --verify -q $c
609 '
610
611 test_expect_success 'stdin update ref works with right old value' '
612 echo "update $b $m~1 $m" >stdin &&
613 git update-ref --stdin <stdin &&
614 git rev-parse $m~1 >expect &&
615 git rev-parse $b >actual &&
616 test_cmp expect actual
617 '
618
619 test_expect_success 'stdin delete ref fails with wrong old value' '
620 echo "delete $a $m~1" >stdin &&
621 test_must_fail git update-ref --stdin <stdin 2>err &&
622 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
623 git rev-parse $m >expect &&
624 git rev-parse $a >actual &&
625 test_cmp expect actual
626 '
627
628 test_expect_success 'stdin delete ref fails with zero old value' '
629 echo "delete $a " >stdin &&
630 test_must_fail git update-ref --stdin <stdin 2>err &&
631 grep "fatal: delete $a: zero <oldvalue>" err &&
632 git rev-parse $m >expect &&
633 git rev-parse $a >actual &&
634 test_cmp expect actual
635 '
636
637 test_expect_success 'stdin update symref works option no-deref' '
638 git symbolic-ref TESTSYMREF $b &&
639 cat >stdin <<-EOF &&
640 option no-deref
641 update TESTSYMREF $a $b
642 EOF
643 git update-ref --stdin <stdin &&
644 git rev-parse TESTSYMREF >expect &&
645 git rev-parse $a >actual &&
646 test_cmp expect actual &&
647 git rev-parse $m~1 >expect &&
648 git rev-parse $b >actual &&
649 test_cmp expect actual
650 '
651
652 test_expect_success 'stdin delete symref works option no-deref' '
653 git symbolic-ref TESTSYMREF $b &&
654 cat >stdin <<-EOF &&
655 option no-deref
656 delete TESTSYMREF $b
657 EOF
658 git update-ref --stdin <stdin &&
659 test_must_fail git rev-parse --verify -q TESTSYMREF &&
660 git rev-parse $m~1 >expect &&
661 git rev-parse $b >actual &&
662 test_cmp expect actual
663 '
664
665 test_expect_success 'stdin delete ref works with right old value' '
666 echo "delete $b $m~1" >stdin &&
667 git update-ref --stdin <stdin &&
668 test_must_fail git rev-parse --verify -q $b
669 '
670
671 test_expect_success 'stdin update/create/verify combination works' '
672 cat >stdin <<-EOF &&
673 update $a $m
674 create $b $m
675 verify $c
676 EOF
677 git update-ref --stdin <stdin &&
678 git rev-parse $m >expect &&
679 git rev-parse $a >actual &&
680 test_cmp expect actual &&
681 git rev-parse $b >actual &&
682 test_cmp expect actual &&
683 test_must_fail git rev-parse --verify -q $c
684 '
685
686 test_expect_success 'stdin verify succeeds for correct value' '
687 git rev-parse $m >expect &&
688 echo "verify $m $m" >stdin &&
689 git update-ref --stdin <stdin &&
690 git rev-parse $m >actual &&
691 test_cmp expect actual
692 '
693
694 test_expect_success 'stdin verify succeeds for missing reference' '
695 echo "verify refs/heads/missing $Z" >stdin &&
696 git update-ref --stdin <stdin &&
697 test_must_fail git rev-parse --verify -q refs/heads/missing
698 '
699
700 test_expect_success 'stdin verify treats no value as missing' '
701 echo "verify refs/heads/missing" >stdin &&
702 git update-ref --stdin <stdin &&
703 test_must_fail git rev-parse --verify -q refs/heads/missing
704 '
705
706 test_expect_success 'stdin verify fails for wrong value' '
707 git rev-parse $m >expect &&
708 echo "verify $m $m~1" >stdin &&
709 test_must_fail git update-ref --stdin <stdin &&
710 git rev-parse $m >actual &&
711 test_cmp expect actual
712 '
713
714 test_expect_success 'stdin verify fails for mistaken null value' '
715 git rev-parse $m >expect &&
716 echo "verify $m $Z" >stdin &&
717 test_must_fail git update-ref --stdin <stdin &&
718 git rev-parse $m >actual &&
719 test_cmp expect actual
720 '
721
722 test_expect_success 'stdin verify fails for mistaken empty value' '
723 M=$(git rev-parse $m) &&
724 test_when_finished "git update-ref $m $M" &&
725 git rev-parse $m >expect &&
726 echo "verify $m" >stdin &&
727 test_must_fail git update-ref --stdin <stdin &&
728 git rev-parse $m >actual &&
729 test_cmp expect actual
730 '
731
732 test_expect_success 'stdin update refs works with identity updates' '
733 cat >stdin <<-EOF &&
734 update $a $m $m
735 update $b $m $m
736 update $c $Z $E
737 EOF
738 git update-ref --stdin <stdin &&
739 git rev-parse $m >expect &&
740 git rev-parse $a >actual &&
741 test_cmp expect actual &&
742 git rev-parse $b >actual &&
743 test_cmp expect actual &&
744 test_must_fail git rev-parse --verify -q $c
745 '
746
747 test_expect_success 'stdin update refs fails with wrong old value' '
748 git update-ref $c $m &&
749 cat >stdin <<-EOF &&
750 update $a $m $m
751 update $b $m $m
752 update $c ''
753 EOF
754 test_must_fail git update-ref --stdin <stdin 2>err &&
755 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
756 git rev-parse $m >expect &&
757 git rev-parse $a >actual &&
758 test_cmp expect actual &&
759 git rev-parse $b >actual &&
760 test_cmp expect actual &&
761 git rev-parse $c >actual &&
762 test_cmp expect actual
763 '
764
765 test_expect_success 'stdin delete refs works with packed and loose refs' '
766 git pack-refs --all &&
767 git update-ref $c $m~1 &&
768 cat >stdin <<-EOF &&
769 delete $a $m
770 update $b $Z $m
771 update $c $E $m~1
772 EOF
773 git update-ref --stdin <stdin &&
774 test_must_fail git rev-parse --verify -q $a &&
775 test_must_fail git rev-parse --verify -q $b &&
776 test_must_fail git rev-parse --verify -q $c
777 '
778
779 test_expect_success 'stdin -z works on empty input' '
780 >stdin &&
781 git update-ref -z --stdin <stdin &&
782 git rev-parse --verify -q $m
783 '
784
785 test_expect_success 'stdin -z fails on empty line' '
786 echo "" >stdin &&
787 test_must_fail git update-ref -z --stdin <stdin 2>err &&
788 grep "fatal: whitespace before command: " err
789 '
790
791 test_expect_success 'stdin -z fails on empty command' '
792 printf $F "" >stdin &&
793 test_must_fail git update-ref -z --stdin <stdin 2>err &&
794 grep "fatal: empty command in input" err
795 '
796
797 test_expect_success 'stdin -z fails on only whitespace' '
798 printf $F " " >stdin &&
799 test_must_fail git update-ref -z --stdin <stdin 2>err &&
800 grep "fatal: whitespace before command: " err
801 '
802
803 test_expect_success 'stdin -z fails on leading whitespace' '
804 printf $F " create $a" "$m" >stdin &&
805 test_must_fail git update-ref -z --stdin <stdin 2>err &&
806 grep "fatal: whitespace before command: create $a" err
807 '
808
809 test_expect_success 'stdin -z fails on unknown command' '
810 printf $F "unknown $a" >stdin &&
811 test_must_fail git update-ref -z --stdin <stdin 2>err &&
812 grep "fatal: unknown command: unknown $a" err
813 '
814
815 test_expect_success 'stdin -z fails create with no ref' '
816 printf $F "create " >stdin &&
817 test_must_fail git update-ref -z --stdin <stdin 2>err &&
818 grep "fatal: create: missing <ref>" err
819 '
820
821 test_expect_success 'stdin -z fails create with no new value' '
822 printf $F "create $a" >stdin &&
823 test_must_fail git update-ref -z --stdin <stdin 2>err &&
824 grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
825 '
826
827 test_expect_success 'stdin -z fails create with too many arguments' '
828 printf $F "create $a" "$m" "$m" >stdin &&
829 test_must_fail git update-ref -z --stdin <stdin 2>err &&
830 grep "fatal: unknown command: $m" err
831 '
832
833 test_expect_success 'stdin -z fails update with no ref' '
834 printf $F "update " >stdin &&
835 test_must_fail git update-ref -z --stdin <stdin 2>err &&
836 grep "fatal: update: missing <ref>" err
837 '
838
839 test_expect_success 'stdin -z fails update with too few args' '
840 printf $F "update $a" "$m" >stdin &&
841 test_must_fail git update-ref -z --stdin <stdin 2>err &&
842 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
843 '
844
845 test_expect_success 'stdin -z emits warning with empty new value' '
846 git update-ref $a $m &&
847 printf $F "update $a" "" "" >stdin &&
848 git update-ref -z --stdin <stdin 2>err &&
849 grep "warning: update $a: missing <newvalue>, treating as zero" err &&
850 test_must_fail git rev-parse --verify -q $a
851 '
852
853 test_expect_success 'stdin -z fails update with no new value' '
854 printf $F "update $a" >stdin &&
855 test_must_fail git update-ref -z --stdin <stdin 2>err &&
856 grep "fatal: update $a: unexpected end of input when reading <newvalue>" err
857 '
858
859 test_expect_success 'stdin -z fails update with no old value' '
860 printf $F "update $a" "$m" >stdin &&
861 test_must_fail git update-ref -z --stdin <stdin 2>err &&
862 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
863 '
864
865 test_expect_success 'stdin -z fails update with too many arguments' '
866 printf $F "update $a" "$m" "$m" "$m" >stdin &&
867 test_must_fail git update-ref -z --stdin <stdin 2>err &&
868 grep "fatal: unknown command: $m" err
869 '
870
871 test_expect_success 'stdin -z fails delete with no ref' '
872 printf $F "delete " >stdin &&
873 test_must_fail git update-ref -z --stdin <stdin 2>err &&
874 grep "fatal: delete: missing <ref>" err
875 '
876
877 test_expect_success 'stdin -z fails delete with no old value' '
878 printf $F "delete $a" >stdin &&
879 test_must_fail git update-ref -z --stdin <stdin 2>err &&
880 grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
881 '
882
883 test_expect_success 'stdin -z fails delete with too many arguments' '
884 printf $F "delete $a" "$m" "$m" >stdin &&
885 test_must_fail git update-ref -z --stdin <stdin 2>err &&
886 grep "fatal: unknown command: $m" err
887 '
888
889 test_expect_success 'stdin -z fails verify with too many arguments' '
890 printf $F "verify $a" "$m" "$m" >stdin &&
891 test_must_fail git update-ref -z --stdin <stdin 2>err &&
892 grep "fatal: unknown command: $m" err
893 '
894
895 test_expect_success 'stdin -z fails verify with no old value' '
896 printf $F "verify $a" >stdin &&
897 test_must_fail git update-ref -z --stdin <stdin 2>err &&
898 grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err
899 '
900
901 test_expect_success 'stdin -z fails option with unknown name' '
902 printf $F "option unknown" >stdin &&
903 test_must_fail git update-ref -z --stdin <stdin 2>err &&
904 grep "fatal: option unknown: unknown" err
905 '
906
907 test_expect_success 'stdin -z fails with duplicate refs' '
908 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
909 test_must_fail git update-ref -z --stdin <stdin 2>err &&
910 grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed." err
911 '
912
913 test_expect_success 'stdin -z create ref works' '
914 printf $F "create $a" "$m" >stdin &&
915 git update-ref -z --stdin <stdin &&
916 git rev-parse $m >expect &&
917 git rev-parse $a >actual &&
918 test_cmp expect actual
919 '
920
921 test_expect_success 'stdin -z update ref creates with zero old value' '
922 printf $F "update $b" "$m" "$Z" >stdin &&
923 git update-ref -z --stdin <stdin &&
924 git rev-parse $m >expect &&
925 git rev-parse $b >actual &&
926 test_cmp expect actual &&
927 git update-ref -d $b
928 '
929
930 test_expect_success 'stdin -z update ref creates with empty old value' '
931 printf $F "update $b" "$m" "" >stdin &&
932 git update-ref -z --stdin <stdin &&
933 git rev-parse $m >expect &&
934 git rev-parse $b >actual &&
935 test_cmp expect actual
936 '
937
938 test_expect_success 'stdin -z create ref works with path with space to blob' '
939 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
940 git update-ref -z --stdin <stdin &&
941 git rev-parse "$m:$pws" >expect &&
942 git rev-parse refs/blobs/pws >actual &&
943 test_cmp expect actual &&
944 git update-ref -d refs/blobs/pws
945 '
946
947 test_expect_success 'stdin -z update ref fails with wrong old value' '
948 printf $F "update $c" "$m" "$m~1" >stdin &&
949 test_must_fail git update-ref -z --stdin <stdin 2>err &&
950 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
951 test_must_fail git rev-parse --verify -q $c
952 '
953
954 test_expect_success 'stdin -z update ref fails with bad old value' '
955 printf $F "update $c" "$m" "does-not-exist" >stdin &&
956 test_must_fail git update-ref -z --stdin <stdin 2>err &&
957 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
958 test_must_fail git rev-parse --verify -q $c
959 '
960
961 test_expect_success 'stdin -z create ref fails when ref exists' '
962 git update-ref $c $m &&
963 git rev-parse "$c" >expect &&
964 printf $F "create $c" "$m~1" >stdin &&
965 test_must_fail git update-ref -z --stdin <stdin 2>err &&
966 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
967 git rev-parse "$c" >actual &&
968 test_cmp expect actual
969 '
970
971 test_expect_success 'stdin -z create ref fails with bad new value' '
972 git update-ref -d "$c" &&
973 printf $F "create $c" "does-not-exist" >stdin &&
974 test_must_fail git update-ref -z --stdin <stdin 2>err &&
975 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
976 test_must_fail git rev-parse --verify -q $c
977 '
978
979 test_expect_success 'stdin -z create ref fails with empty new value' '
980 printf $F "create $c" "" >stdin &&
981 test_must_fail git update-ref -z --stdin <stdin 2>err &&
982 grep "fatal: create $c: missing <newvalue>" err &&
983 test_must_fail git rev-parse --verify -q $c
984 '
985
986 test_expect_success 'stdin -z update ref works with right old value' '
987 printf $F "update $b" "$m~1" "$m" >stdin &&
988 git update-ref -z --stdin <stdin &&
989 git rev-parse $m~1 >expect &&
990 git rev-parse $b >actual &&
991 test_cmp expect actual
992 '
993
994 test_expect_success 'stdin -z delete ref fails with wrong old value' '
995 printf $F "delete $a" "$m~1" >stdin &&
996 test_must_fail git update-ref -z --stdin <stdin 2>err &&
997 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
998 git rev-parse $m >expect &&
999 git rev-parse $a >actual &&
1000 test_cmp expect actual
1001 '
1002
1003 test_expect_success 'stdin -z delete ref fails with zero old value' '
1004 printf $F "delete $a" "$Z" >stdin &&
1005 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1006 grep "fatal: delete $a: zero <oldvalue>" err &&
1007 git rev-parse $m >expect &&
1008 git rev-parse $a >actual &&
1009 test_cmp expect actual
1010 '
1011
1012 test_expect_success 'stdin -z update symref works option no-deref' '
1013 git symbolic-ref TESTSYMREF $b &&
1014 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
1015 git update-ref -z --stdin <stdin &&
1016 git rev-parse TESTSYMREF >expect &&
1017 git rev-parse $a >actual &&
1018 test_cmp expect actual &&
1019 git rev-parse $m~1 >expect &&
1020 git rev-parse $b >actual &&
1021 test_cmp expect actual
1022 '
1023
1024 test_expect_success 'stdin -z delete symref works option no-deref' '
1025 git symbolic-ref TESTSYMREF $b &&
1026 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
1027 git update-ref -z --stdin <stdin &&
1028 test_must_fail git rev-parse --verify -q TESTSYMREF &&
1029 git rev-parse $m~1 >expect &&
1030 git rev-parse $b >actual &&
1031 test_cmp expect actual
1032 '
1033
1034 test_expect_success 'stdin -z delete ref works with right old value' '
1035 printf $F "delete $b" "$m~1" >stdin &&
1036 git update-ref -z --stdin <stdin &&
1037 test_must_fail git rev-parse --verify -q $b
1038 '
1039
1040 test_expect_success 'stdin -z update/create/verify combination works' '
1041 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
1042 git update-ref -z --stdin <stdin &&
1043 git rev-parse $m >expect &&
1044 git rev-parse $a >actual &&
1045 test_cmp expect actual &&
1046 git rev-parse $b >actual &&
1047 test_cmp expect actual &&
1048 test_must_fail git rev-parse --verify -q $c
1049 '
1050
1051 test_expect_success 'stdin -z verify succeeds for correct value' '
1052 git rev-parse $m >expect &&
1053 printf $F "verify $m" "$m" >stdin &&
1054 git update-ref -z --stdin <stdin &&
1055 git rev-parse $m >actual &&
1056 test_cmp expect actual
1057 '
1058
1059 test_expect_success 'stdin -z verify succeeds for missing reference' '
1060 printf $F "verify refs/heads/missing" "$Z" >stdin &&
1061 git update-ref -z --stdin <stdin &&
1062 test_must_fail git rev-parse --verify -q refs/heads/missing
1063 '
1064
1065 test_expect_success 'stdin -z verify treats no value as missing' '
1066 printf $F "verify refs/heads/missing" "" >stdin &&
1067 git update-ref -z --stdin <stdin &&
1068 test_must_fail git rev-parse --verify -q refs/heads/missing
1069 '
1070
1071 test_expect_success 'stdin -z verify fails for wrong value' '
1072 git rev-parse $m >expect &&
1073 printf $F "verify $m" "$m~1" >stdin &&
1074 test_must_fail git update-ref -z --stdin <stdin &&
1075 git rev-parse $m >actual &&
1076 test_cmp expect actual
1077 '
1078
1079 test_expect_success 'stdin -z verify fails for mistaken null value' '
1080 git rev-parse $m >expect &&
1081 printf $F "verify $m" "$Z" >stdin &&
1082 test_must_fail git update-ref -z --stdin <stdin &&
1083 git rev-parse $m >actual &&
1084 test_cmp expect actual
1085 '
1086
1087 test_expect_success 'stdin -z verify fails for mistaken empty value' '
1088 M=$(git rev-parse $m) &&
1089 test_when_finished "git update-ref $m $M" &&
1090 git rev-parse $m >expect &&
1091 printf $F "verify $m" "" >stdin &&
1092 test_must_fail git update-ref -z --stdin <stdin &&
1093 git rev-parse $m >actual &&
1094 test_cmp expect actual
1095 '
1096
1097 test_expect_success 'stdin -z update refs works with identity updates' '
1098 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
1099 git update-ref -z --stdin <stdin &&
1100 git rev-parse $m >expect &&
1101 git rev-parse $a >actual &&
1102 test_cmp expect actual &&
1103 git rev-parse $b >actual &&
1104 test_cmp expect actual &&
1105 test_must_fail git rev-parse --verify -q $c
1106 '
1107
1108 test_expect_success 'stdin -z update refs fails with wrong old value' '
1109 git update-ref $c $m &&
1110 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
1111 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1112 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1113 git rev-parse $m >expect &&
1114 git rev-parse $a >actual &&
1115 test_cmp expect actual &&
1116 git rev-parse $b >actual &&
1117 test_cmp expect actual &&
1118 git rev-parse $c >actual &&
1119 test_cmp expect actual
1120 '
1121
1122 test_expect_success 'stdin -z delete refs works with packed and loose refs' '
1123 git pack-refs --all &&
1124 git update-ref $c $m~1 &&
1125 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
1126 git update-ref -z --stdin <stdin &&
1127 test_must_fail git rev-parse --verify -q $a &&
1128 test_must_fail git rev-parse --verify -q $b &&
1129 test_must_fail git rev-parse --verify -q $c
1130 '
1131
1132 test_expect_success 'fails with duplicate HEAD update' '
1133 git branch target1 $A &&
1134 git checkout target1 &&
1135 cat >stdin <<-EOF &&
1136 update refs/heads/target1 $C
1137 option no-deref
1138 update HEAD $B
1139 EOF
1140 test_must_fail git update-ref --stdin <stdin 2>err &&
1141 grep "fatal: multiple updates for '\''HEAD'\'' (including one via its referent .refs/heads/target1.) are not allowed" err &&
1142 echo "refs/heads/target1" >expect &&
1143 git symbolic-ref HEAD >actual &&
1144 test_cmp expect actual &&
1145 echo "$A" >expect &&
1146 git rev-parse refs/heads/target1 >actual &&
1147 test_cmp expect actual
1148 '
1149
1150 test_expect_success 'fails with duplicate ref update via symref' '
1151 git branch target2 $A &&
1152 git symbolic-ref refs/heads/symref2 refs/heads/target2 &&
1153 cat >stdin <<-EOF &&
1154 update refs/heads/target2 $C
1155 update refs/heads/symref2 $B
1156 EOF
1157 test_must_fail git update-ref --stdin <stdin 2>err &&
1158 grep "fatal: multiple updates for '\''refs/heads/target2'\'' (including one via symref .refs/heads/symref2.) are not allowed" err &&
1159 echo "refs/heads/target2" >expect &&
1160 git symbolic-ref refs/heads/symref2 >actual &&
1161 test_cmp expect actual &&
1162 echo "$A" >expect &&
1163 git rev-parse refs/heads/target2 >actual &&
1164 test_cmp expect actual
1165 '
1166
1167 run_with_limited_open_files () {
1168 (ulimit -n 32 && "$@")
1169 }
1170
1171 test_lazy_prereq ULIMIT_FILE_DESCRIPTORS 'run_with_limited_open_files true'
1172
1173 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' '
1174 (
1175 for i in $(test_seq 33)
1176 do
1177 echo "create refs/heads/$i HEAD"
1178 done >large_input &&
1179 run_with_limited_open_files git update-ref --stdin <large_input &&
1180 git rev-parse --verify -q refs/heads/33
1181 )
1182 '
1183
1184 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches does not burst open file limit' '
1185 (
1186 for i in $(test_seq 33)
1187 do
1188 echo "delete refs/heads/$i HEAD"
1189 done >large_input &&
1190 run_with_limited_open_files git update-ref --stdin <large_input &&
1191 test_must_fail git rev-parse --verify -q refs/heads/33
1192 )
1193 '
1194
1195 test_expect_success 'handle per-worktree refs in refs/bisect' '
1196 git commit --allow-empty -m "initial commit" &&
1197 git worktree add -b branch worktree &&
1198 (
1199 cd worktree &&
1200 git commit --allow-empty -m "test commit" &&
1201 git for-each-ref >for-each-ref.out &&
1202 ! grep refs/bisect for-each-ref.out &&
1203 git update-ref refs/bisect/something HEAD &&
1204 git rev-parse refs/bisect/something >../worktree-head &&
1205 git for-each-ref | grep refs/bisect/something
1206 ) &&
1207 test_path_is_missing .git/refs/bisect &&
1208 test_must_fail git rev-parse refs/bisect/something &&
1209 git update-ref refs/bisect/something HEAD &&
1210 git rev-parse refs/bisect/something >main-head &&
1211 ! test_cmp main-head worktree-head
1212 '
1213
1214 test_done