Git 2.45
[git/gitster.git] / t / t1400-update-ref.sh
blobec3443cc8786d126cbc0085de184b2e9af019566
1 #!/bin/sh
3 # Copyright (c) 2006 Shawn Pearce
6 test_description='Test git update-ref and basic ref logging'
7 . ./test-lib.sh
9 Z=$ZERO_OID
11 m=refs/heads/main
12 outside=refs/foo
13 bare=bare-repo
15 create_test_commits ()
17 prfx="$1"
18 for name in A B C D E F
20 test_tick &&
21 T=$(git write-tree) &&
22 sha1=$(echo $name | git commit-tree $T) &&
23 eval $prfx$name=$sha1
24 done
27 test_expect_success setup '
28 git checkout --orphan main &&
29 create_test_commits "" &&
30 mkdir $bare &&
31 cd $bare &&
32 git init --bare -b main &&
33 create_test_commits "bare" &&
34 cd -
37 test_expect_success "create $m" '
38 git update-ref $m $A &&
39 test $A = $(git show-ref -s --verify $m)
41 test_expect_success "create $m with oldvalue verification" '
42 git update-ref $m $B $A &&
43 test $B = $(git show-ref -s --verify $m)
45 test_expect_success "fail to delete $m with stale ref" '
46 test_must_fail git update-ref -d $m $A &&
47 test $B = "$(git show-ref -s --verify $m)"
49 test_expect_success "delete $m" '
50 test_when_finished "git update-ref -d $m" &&
51 git update-ref -d $m $B &&
52 test_must_fail git show-ref --verify -q $m
55 test_expect_success "delete $m without oldvalue verification" '
56 test_when_finished "git update-ref -d $m" &&
57 git update-ref $m $A &&
58 test $A = $(git show-ref -s --verify $m) &&
59 git update-ref -d $m &&
60 test_must_fail git show-ref --verify -q $m
63 test_expect_success "fail to create $n due to file/directory conflict" '
64 test_when_finished "git update-ref -d refs/heads/gu" &&
65 git update-ref refs/heads/gu $A &&
66 test_must_fail git update-ref refs/heads/gu/fixes $A
69 test_expect_success "create $m (by HEAD)" '
70 git update-ref HEAD $A &&
71 test $A = $(git show-ref -s --verify $m)
73 test_expect_success "create $m (by HEAD) with oldvalue verification" '
74 git update-ref HEAD $B $A &&
75 test $B = $(git show-ref -s --verify $m)
77 test_expect_success "fail to delete $m (by HEAD) with stale ref" '
78 test_must_fail git update-ref -d HEAD $A &&
79 test $B = $(git show-ref -s --verify $m)
81 test_expect_success "delete $m (by HEAD)" '
82 test_when_finished "git update-ref -d $m" &&
83 git update-ref -d HEAD $B &&
84 test_must_fail git show-ref --verify -q $m
87 test_expect_success "deleting current branch adds message to HEAD's log" '
88 test_when_finished "git update-ref -d $m" &&
89 git update-ref $m $A &&
90 git symbolic-ref HEAD $m &&
91 git update-ref -m delete-$m -d $m &&
92 test_must_fail git show-ref --verify -q $m &&
93 test-tool ref-store main for-each-reflog-ent HEAD >actual &&
94 grep "delete-$m$" actual
97 test_expect_success "deleting by HEAD adds message to HEAD's log" '
98 test_when_finished "git update-ref -d $m" &&
99 git update-ref $m $A &&
100 git symbolic-ref HEAD $m &&
101 git update-ref -m delete-by-head -d HEAD &&
102 test_must_fail git show-ref --verify -q $m &&
103 test-tool ref-store main for-each-reflog-ent HEAD >actual &&
104 grep "delete-by-head$" actual
107 test_expect_success 'update-ref does not create reflogs by default' '
108 test_when_finished "git update-ref -d $outside" &&
109 git update-ref $outside $A &&
110 git rev-parse $A >expect &&
111 git rev-parse $outside >actual &&
112 test_cmp expect actual &&
113 test_must_fail git reflog exists $outside
116 test_expect_success 'update-ref creates reflogs with --create-reflog' '
117 test_when_finished "git update-ref -d $outside" &&
118 git update-ref --create-reflog $outside $A &&
119 git rev-parse $A >expect &&
120 git rev-parse $outside >actual &&
121 test_cmp expect actual &&
122 git reflog exists $outside
125 test_expect_success 'creates no reflog in bare repository' '
126 git -C $bare update-ref $m $bareA &&
127 git -C $bare rev-parse $bareA >expect &&
128 git -C $bare rev-parse $m >actual &&
129 test_cmp expect actual &&
130 test_must_fail git -C $bare reflog exists $m
133 test_expect_success 'core.logAllRefUpdates=true creates reflog in bare repository' '
134 test_when_finished "git -C $bare config --unset core.logAllRefUpdates && \
135 test-tool ref-store main delete-reflog $m" &&
136 git -C $bare config core.logAllRefUpdates true &&
137 git -C $bare update-ref $m $bareB &&
138 git -C $bare rev-parse $bareB >expect &&
139 git -C $bare rev-parse $m >actual &&
140 test_cmp expect actual &&
141 git -C $bare reflog exists $m
144 test_expect_success 'core.logAllRefUpdates=true does not create reflog by default' '
145 test_config core.logAllRefUpdates true &&
146 test_when_finished "git update-ref -d $outside" &&
147 git update-ref $outside $A &&
148 git rev-parse $A >expect &&
149 git rev-parse $outside >actual &&
150 test_cmp expect actual &&
151 test_must_fail git reflog exists $outside
154 test_expect_success 'core.logAllRefUpdates=always creates reflog by default' '
155 test_config core.logAllRefUpdates always &&
156 test_when_finished "git update-ref -d $outside" &&
157 git update-ref $outside $A &&
158 git rev-parse $A >expect &&
159 git rev-parse $outside >actual &&
160 test_cmp expect actual &&
161 git reflog exists $outside
164 test_expect_success 'core.logAllRefUpdates=always creates reflog for ORIG_HEAD' '
165 test_config core.logAllRefUpdates always &&
166 git update-ref ORIG_HEAD $A &&
167 git reflog exists ORIG_HEAD
170 test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always' '
171 test_config core.logAllRefUpdates true &&
172 test_when_finished "git update-ref -d $outside" &&
173 git update-ref --no-create-reflog $outside $A &&
174 git rev-parse $A >expect &&
175 git rev-parse $outside >actual &&
176 test_cmp expect actual &&
177 test_must_fail git reflog exists $outside
180 test_expect_success "create $m (by HEAD)" '
181 git update-ref HEAD $A &&
182 test $A = $(git show-ref -s --verify $m)
184 test_expect_success 'pack refs' '
185 git pack-refs --all
187 test_expect_success "move $m (by HEAD)" '
188 git update-ref HEAD $B $A &&
189 test $B = $(git show-ref -s --verify $m)
191 test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" '
192 test_when_finished "git update-ref -d $m" &&
193 git update-ref -d HEAD $B &&
194 ! grep "$m" .git/packed-refs &&
195 test_must_fail git show-ref --verify -q $m
198 test_expect_success 'delete symref without dereference' '
199 test_when_finished "git update-ref -d $m" &&
200 echo foo >foo.c &&
201 git add foo.c &&
202 git commit -m foo &&
203 git symbolic-ref SYMREF $m &&
204 git update-ref --no-deref -d SYMREF &&
205 git show-ref --verify -q $m &&
206 test_must_fail git show-ref --verify -q SYMREF &&
207 test_must_fail git symbolic-ref SYMREF
210 test_expect_success 'delete symref without dereference when the referred ref is packed' '
211 test_when_finished "git update-ref -d $m" &&
212 echo foo >foo.c &&
213 git add foo.c &&
214 git commit -m foo &&
215 git symbolic-ref SYMREF $m &&
216 git pack-refs --all &&
217 git update-ref --no-deref -d SYMREF &&
218 git show-ref --verify -q $m &&
219 test_must_fail git show-ref --verify -q SYMREF &&
220 test_must_fail git symbolic-ref SYMREF
223 test_expect_success 'update-ref -d is not confused by self-reference' '
224 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" &&
225 git symbolic-ref refs/heads/self refs/heads/self &&
226 git symbolic-ref --no-recurse refs/heads/self &&
227 test_must_fail git update-ref -d refs/heads/self &&
228 git symbolic-ref --no-recurse refs/heads/self
231 test_expect_success 'update-ref --no-deref -d can delete self-reference' '
232 test_when_finished "test-tool ref-store main delete-refs REF_NO_DEREF refs/heads/self" &&
233 git symbolic-ref refs/heads/self refs/heads/self &&
234 git symbolic-ref --no-recurse refs/heads/self &&
235 git update-ref --no-deref -d refs/heads/self &&
236 test_must_fail git show-ref --verify -q refs/heads/self
239 test_expect_success REFFILES 'update-ref --no-deref -d can delete reference to bad ref' '
240 >.git/refs/heads/bad &&
241 test_when_finished "rm -f .git/refs/heads/bad" &&
242 git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
243 test_when_finished "git update-ref -d refs/heads/ref-to-bad" &&
244 git symbolic-ref --no-recurse refs/heads/ref-to-bad &&
245 git update-ref --no-deref -d refs/heads/ref-to-bad &&
246 test_must_fail git show-ref --verify -q refs/heads/ref-to-bad
249 test_expect_success '(not) create HEAD with old sha1' '
250 test_must_fail git update-ref HEAD $A $B
252 test_expect_success "(not) prior created .git/$m" '
253 test_when_finished "git update-ref -d $m" &&
254 test_must_fail git show-ref --verify -q $m
257 test_expect_success 'create HEAD' '
258 git update-ref HEAD $A
260 test_expect_success '(not) change HEAD with wrong SHA1' '
261 test_must_fail git update-ref HEAD $B $Z
263 test_expect_success "(not) changed .git/$m" '
264 test_when_finished "git update-ref -d $m" &&
265 ! test $B = $(git show-ref -s --verify $m)
268 test_expect_success "clean up reflog" '
269 test-tool ref-store main delete-reflog $m
272 test_expect_success "create $m (logged by touch)" '
273 test_config core.logAllRefUpdates false &&
274 GIT_COMMITTER_DATE="2005-05-26 23:30" \
275 git update-ref --create-reflog HEAD $A -m "Initial Creation" &&
276 test $A = $(git show-ref -s --verify $m)
278 test_expect_success "update $m (logged by touch)" '
279 test_config core.logAllRefUpdates false &&
280 GIT_COMMITTER_DATE="2005-05-26 23:31" \
281 git update-ref HEAD $B $A -m "Switch" &&
282 test $B = $(git show-ref -s --verify $m)
284 test_expect_success "set $m (logged by touch)" '
285 test_config core.logAllRefUpdates false &&
286 GIT_COMMITTER_DATE="2005-05-26 23:41" \
287 git update-ref HEAD $A &&
288 test $A = $(git show-ref -s --verify $m)
291 cat >expect <<EOF
292 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
293 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
294 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
296 test_expect_success "verifying $m's log (logged by touch)" '
297 test_when_finished "git update-ref -d $m && git reflog expire --expire=all --all && rm -rf actual expect" &&
298 test-tool ref-store main for-each-reflog-ent $m >actual &&
299 test_cmp actual expect
302 test_expect_success "create $m (logged by config)" '
303 test_config core.logAllRefUpdates true &&
304 GIT_COMMITTER_DATE="2005-05-26 23:32" \
305 git update-ref HEAD $A -m "Initial Creation" &&
306 test $A = $(git show-ref -s --verify $m)
308 test_expect_success "update $m (logged by config)" '
309 test_config core.logAllRefUpdates true &&
310 GIT_COMMITTER_DATE="2005-05-26 23:33" \
311 git update-ref HEAD $B $A -m "Switch" &&
312 test $B = $(git show-ref -s --verify $m)
314 test_expect_success "set $m (logged by config)" '
315 test_config core.logAllRefUpdates true &&
316 GIT_COMMITTER_DATE="2005-05-26 23:43" \
317 git update-ref HEAD $A &&
318 test $A = $(git show-ref -s --verify $m)
321 cat >expect <<EOF
322 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
323 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
324 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
326 test_expect_success "verifying $m's log (logged by config)" '
327 test_when_finished "git update-ref -d $m && git reflog expire --expire=all --all && rm -rf actual expect" &&
328 test-tool ref-store main for-each-reflog-ent $m >actual &&
329 test_cmp actual expect
332 test_expect_success 'set up for querying the reflog' '
333 git update-ref -d $m &&
334 test-tool ref-store main delete-reflog $m &&
336 GIT_COMMITTER_DATE="1117150320 -0500" git update-ref $m $C &&
337 GIT_COMMITTER_DATE="1117150350 -0500" git update-ref $m $A &&
338 GIT_COMMITTER_DATE="1117150380 -0500" git update-ref $m $B &&
339 GIT_COMMITTER_DATE="1117150680 -0500" git update-ref $m $F &&
340 GIT_COMMITTER_DATE="1117150980 -0500" git update-ref $m $E &&
341 git update-ref $m $D &&
342 # Delete the last reflog entry so that the tip of m and the reflog for
343 # it disagree.
344 git reflog delete $m@{0} &&
346 cat >expect <<-EOF &&
347 $Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
348 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
349 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
350 $B $F $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
351 $F $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
353 test-tool ref-store main for-each-reflog-ent $m >actual &&
354 test_cmp expect actual
357 ed="Thu, 26 May 2005 18:32:00 -0500"
358 gd="Thu, 26 May 2005 18:33:00 -0500"
359 ld="Thu, 26 May 2005 18:43:00 -0500"
360 test_expect_success 'Query "main@{May 25 2005}" (before history)' '
361 test_when_finished "rm -f o e" &&
362 git rev-parse --verify "main@{May 25 2005}" >o 2>e &&
363 echo "$C" >expect &&
364 test_cmp expect o &&
365 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
366 test_cmp expect e
368 test_expect_success 'Query main@{2005-05-25} (before history)' '
369 test_when_finished "rm -f o e" &&
370 git rev-parse --verify main@{2005-05-25} >o 2>e &&
371 echo "$C" >expect &&
372 test_cmp expect o &&
373 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
374 test_cmp expect e
376 test_expect_success 'Query "main@{May 26 2005 23:31:59}" (1 second before history)' '
377 test_when_finished "rm -f o e" &&
378 git rev-parse --verify "main@{May 26 2005 23:31:59}" >o 2>e &&
379 echo "$C" >expect &&
380 test_cmp expect o &&
381 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
382 test_cmp expect e
384 test_expect_success 'Query "main@{May 26 2005 23:32:00}" (exactly history start)' '
385 test_when_finished "rm -f o e" &&
386 git rev-parse --verify "main@{May 26 2005 23:32:00}" >o 2>e &&
387 echo "$C" >expect &&
388 test_cmp expect o &&
389 test_must_be_empty e
391 test_expect_success 'Query "main@{May 26 2005 23:32:30}" (first non-creation change)' '
392 test_when_finished "rm -f o e" &&
393 git rev-parse --verify "main@{May 26 2005 23:32:30}" >o 2>e &&
394 echo "$A" >expect &&
395 test_cmp expect o &&
396 test_must_be_empty e
398 test_expect_success 'Query "main@{2005-05-26 23:33:01}" (middle of history with gap)' '
399 test_when_finished "rm -f o e" &&
400 git rev-parse --verify "main@{2005-05-26 23:33:01}" >o 2>e &&
401 echo "$B" >expect &&
402 test_cmp expect o
404 test_expect_success 'Query "main@{2005-05-26 23:38:00}" (middle of history)' '
405 test_when_finished "rm -f o e" &&
406 git rev-parse --verify "main@{2005-05-26 23:38:00}" >o 2>e &&
407 echo "$F" >expect &&
408 test_cmp expect o &&
409 test_must_be_empty e
411 test_expect_success 'Query "main@{2005-05-26 23:43:00}" (exact end of history)' '
412 test_when_finished "rm -f o e" &&
413 git rev-parse --verify "main@{2005-05-26 23:43:00}" >o 2>e &&
414 echo "$E" >expect &&
415 test_cmp expect o &&
416 test_must_be_empty e
418 test_expect_success 'Query "main@{2005-05-28}" (past end of history)' '
419 test_when_finished "rm -f o e" &&
420 git rev-parse --verify "main@{2005-05-28}" >o 2>e &&
421 echo "$D" >expect &&
422 test_cmp expect o &&
423 test_grep -F "warning: log for ref $m unexpectedly ended on $ld" e
426 rm -f expect
427 git update-ref -d $m
429 test_expect_success 'query reflog with gap' '
430 test_when_finished "git update-ref -d $m" &&
432 GIT_COMMITTER_DATE="1117150320 -0500" git update-ref $m $A &&
433 GIT_COMMITTER_DATE="1117150380 -0500" git update-ref $m $B &&
434 GIT_COMMITTER_DATE="1117150480 -0500" git update-ref $m $C &&
435 GIT_COMMITTER_DATE="1117150580 -0500" git update-ref $m $D &&
436 GIT_COMMITTER_DATE="1117150680 -0500" git update-ref $m $F &&
437 git reflog delete $m@{2} &&
439 git rev-parse --verify "main@{2005-05-26 23:33:01}" >actual 2>stderr &&
440 echo "$B" >expect &&
441 test_cmp expect actual &&
442 test_grep -F "warning: log for ref $m has gap after $gd" stderr
445 test_expect_success 'creating initial files' '
446 test_when_finished rm -f M &&
447 echo TEST >F &&
448 git add F &&
449 GIT_AUTHOR_DATE="2005-05-26 23:30" \
450 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
451 h_TEST=$(git rev-parse --verify HEAD) &&
452 echo The other day this did not work. >M &&
453 echo And then Bob told me how to fix it. >>M &&
454 echo OTHER >F &&
455 GIT_AUTHOR_DATE="2005-05-26 23:41" \
456 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
457 h_OTHER=$(git rev-parse --verify HEAD) &&
458 GIT_AUTHOR_DATE="2005-05-26 23:44" \
459 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
460 h_FIXED=$(git rev-parse --verify HEAD) &&
461 echo Merged initial commit and a later commit. >M &&
462 echo $h_TEST >.git/MERGE_HEAD &&
463 GIT_AUTHOR_DATE="2005-05-26 23:45" \
464 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
465 h_MERGED=$(git rev-parse --verify HEAD)
468 cat >expect <<EOF
469 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
470 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
471 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
472 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
474 test_expect_success 'git commit logged updates' '
475 test-tool ref-store main for-each-reflog-ent $m >actual &&
476 test_cmp expect actual
478 unset h_TEST h_OTHER h_FIXED h_MERGED
480 test_expect_success 'git cat-file blob main:F (expect OTHER)' '
481 test OTHER = $(git cat-file blob main:F)
483 test_expect_success 'git cat-file blob main@{2005-05-26 23:30}:F (expect TEST)' '
484 test TEST = $(git cat-file blob "main@{2005-05-26 23:30}:F")
486 test_expect_success 'git cat-file blob main@{2005-05-26 23:42}:F (expect OTHER)' '
487 test OTHER = $(git cat-file blob "main@{2005-05-26 23:42}:F")
490 # Test adding and deleting pseudorefs
492 test_expect_success 'given old value for missing pseudoref, do not create' '
493 test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
494 test_must_fail git rev-parse PSEUDOREF &&
495 test_grep "unable to resolve reference" err
498 test_expect_success 'create pseudoref' '
499 git update-ref PSEUDOREF $A &&
500 test $A = $(git show-ref -s --verify PSEUDOREF)
503 test_expect_success 'overwrite pseudoref with no old value given' '
504 git update-ref PSEUDOREF $B &&
505 test $B = $(git show-ref -s --verify PSEUDOREF)
508 test_expect_success 'overwrite pseudoref with correct old value' '
509 git update-ref PSEUDOREF $C $B &&
510 test $C = $(git show-ref -s --verify PSEUDOREF)
513 test_expect_success 'do not overwrite pseudoref with wrong old value' '
514 test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
515 test $C = $(git show-ref -s --verify PSEUDOREF) &&
516 test_grep "cannot lock ref.*expected" err
519 test_expect_success 'delete pseudoref' '
520 git update-ref -d PSEUDOREF &&
521 test_must_fail git show-ref -s --verify PSEUDOREF
524 test_expect_success 'do not delete pseudoref with wrong old value' '
525 git update-ref PSEUDOREF $A &&
526 test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
527 test $A = $(git show-ref -s --verify PSEUDOREF) &&
528 test_grep "cannot lock ref.*expected" err
531 test_expect_success 'delete pseudoref with correct old value' '
532 git update-ref -d PSEUDOREF $A &&
533 test_must_fail git show-ref -s --verify PSEUDOREF
536 test_expect_success 'create pseudoref with old OID zero' '
537 git update-ref PSEUDOREF $A $Z &&
538 test $A = $(git show-ref -s --verify PSEUDOREF)
541 test_expect_success 'do not overwrite pseudoref with old OID zero' '
542 test_when_finished git update-ref -d PSEUDOREF &&
543 test_must_fail git update-ref PSEUDOREF $B $Z 2>err &&
544 test $A = $(git show-ref -s --verify PSEUDOREF) &&
545 test_grep "already exists" err
548 # Test --stdin
550 a=refs/heads/a
551 b=refs/heads/b
552 c=refs/heads/c
553 E='""'
554 F='%s\0'
555 pws='path with space'
557 test_expect_success 'stdin test setup' '
558 echo "$pws" >"$pws" &&
559 git add -- "$pws" &&
560 git commit -m "$pws"
563 test_expect_success '-z fails without --stdin' '
564 test_must_fail git update-ref -z $m $m $m 2>err &&
565 test_grep "usage: git update-ref" err
568 test_expect_success 'stdin works with no input' '
569 >stdin &&
570 git update-ref --stdin <stdin &&
571 git rev-parse --verify -q $m
574 test_expect_success 'stdin fails on empty line' '
575 echo "" >stdin &&
576 test_must_fail git update-ref --stdin <stdin 2>err &&
577 grep "fatal: empty command in input" err
580 test_expect_success 'stdin fails on only whitespace' '
581 echo " " >stdin &&
582 test_must_fail git update-ref --stdin <stdin 2>err &&
583 grep "fatal: whitespace before command: " err
586 test_expect_success 'stdin fails on leading whitespace' '
587 echo " create $a $m" >stdin &&
588 test_must_fail git update-ref --stdin <stdin 2>err &&
589 grep "fatal: whitespace before command: create $a $m" err
592 test_expect_success 'stdin fails on unknown command' '
593 echo "unknown $a" >stdin &&
594 test_must_fail git update-ref --stdin <stdin 2>err &&
595 grep "fatal: unknown command: unknown $a" err
598 test_expect_success 'stdin fails on unbalanced quotes' '
599 echo "create $a \"main" >stdin &&
600 test_must_fail git update-ref --stdin <stdin 2>err &&
601 grep "fatal: badly quoted argument: \\\"main" err
604 test_expect_success 'stdin fails on invalid escape' '
605 echo "create $a \"ma\zn\"" >stdin &&
606 test_must_fail git update-ref --stdin <stdin 2>err &&
607 grep "fatal: badly quoted argument: \\\"ma\\\\zn\\\"" err
610 test_expect_success 'stdin fails on junk after quoted argument' '
611 echo "create \"$a\"main" >stdin &&
612 test_must_fail git update-ref --stdin <stdin 2>err &&
613 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"main" err
616 test_expect_success 'stdin fails create with no ref' '
617 echo "create " >stdin &&
618 test_must_fail git update-ref --stdin <stdin 2>err &&
619 grep "fatal: create: missing <ref>" err
622 test_expect_success 'stdin fails create with no new value' '
623 echo "create $a" >stdin &&
624 test_must_fail git update-ref --stdin <stdin 2>err &&
625 grep "fatal: create $a: missing <new-oid>" err
628 test_expect_success 'stdin fails create with too many arguments' '
629 echo "create $a $m $m" >stdin &&
630 test_must_fail git update-ref --stdin <stdin 2>err &&
631 grep "fatal: create $a: extra input: $m" err
634 test_expect_success 'stdin fails update with no ref' '
635 echo "update " >stdin &&
636 test_must_fail git update-ref --stdin <stdin 2>err &&
637 grep "fatal: update: missing <ref>" err
640 test_expect_success 'stdin fails update with no new value' '
641 echo "update $a" >stdin &&
642 test_must_fail git update-ref --stdin <stdin 2>err &&
643 grep "fatal: update $a: missing <new-oid>" err
646 test_expect_success 'stdin fails update with too many arguments' '
647 echo "update $a $m $m $m" >stdin &&
648 test_must_fail git update-ref --stdin <stdin 2>err &&
649 grep "fatal: update $a: extra input: $m" err
652 test_expect_success 'stdin fails delete with no ref' '
653 echo "delete " >stdin &&
654 test_must_fail git update-ref --stdin <stdin 2>err &&
655 grep "fatal: delete: missing <ref>" err
658 test_expect_success 'stdin fails delete with too many arguments' '
659 echo "delete $a $m $m" >stdin &&
660 test_must_fail git update-ref --stdin <stdin 2>err &&
661 grep "fatal: delete $a: extra input: $m" err
664 test_expect_success 'stdin fails verify with too many arguments' '
665 echo "verify $a $m $m" >stdin &&
666 test_must_fail git update-ref --stdin <stdin 2>err &&
667 grep "fatal: verify $a: extra input: $m" err
670 test_expect_success 'stdin fails option with unknown name' '
671 echo "option unknown" >stdin &&
672 test_must_fail git update-ref --stdin <stdin 2>err &&
673 grep "fatal: option unknown: unknown" err
676 test_expect_success 'stdin fails with duplicate refs' '
677 cat >stdin <<-EOF &&
678 create $a $m
679 create $b $m
680 create $a $m
682 test_must_fail git update-ref --stdin <stdin 2>err &&
683 test_grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
686 test_expect_success 'stdin create ref works' '
687 echo "create $a $m" >stdin &&
688 git update-ref --stdin <stdin &&
689 git rev-parse $m >expect &&
690 git rev-parse $a >actual &&
691 test_cmp expect actual
694 test_expect_success 'stdin does not create reflogs by default' '
695 test_when_finished "git update-ref -d $outside" &&
696 echo "create $outside $m" >stdin &&
697 git update-ref --stdin <stdin &&
698 git rev-parse $m >expect &&
699 git rev-parse $outside >actual &&
700 test_cmp expect actual &&
701 test_must_fail git reflog exists $outside
704 test_expect_success 'stdin creates reflogs with --create-reflog' '
705 test_when_finished "git update-ref -d $outside" &&
706 echo "create $outside $m" >stdin &&
707 git update-ref --create-reflog --stdin <stdin &&
708 git rev-parse $m >expect &&
709 git rev-parse $outside >actual &&
710 test_cmp expect actual &&
711 git reflog exists $outside
714 test_expect_success 'stdin succeeds with quoted argument' '
715 git update-ref -d $a &&
716 echo "create $a \"$m\"" >stdin &&
717 git update-ref --stdin <stdin &&
718 git rev-parse $m >expect &&
719 git rev-parse $a >actual &&
720 test_cmp expect actual
723 test_expect_success 'stdin succeeds with escaped character' '
724 git update-ref -d $a &&
725 echo "create $a \"ma\\151n\"" >stdin &&
726 git update-ref --stdin <stdin &&
727 git rev-parse $m >expect &&
728 git rev-parse $a >actual &&
729 test_cmp expect actual
732 test_expect_success 'stdin update ref creates with zero old value' '
733 echo "update $b $m $Z" >stdin &&
734 git update-ref --stdin <stdin &&
735 git rev-parse $m >expect &&
736 git rev-parse $b >actual &&
737 test_cmp expect actual &&
738 git update-ref -d $b
741 test_expect_success 'stdin update ref creates with empty old value' '
742 echo "update $b $m $E" >stdin &&
743 git update-ref --stdin <stdin &&
744 git rev-parse $m >expect &&
745 git rev-parse $b >actual &&
746 test_cmp expect actual
749 test_expect_success 'stdin create ref works with path with space to blob' '
750 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
751 git update-ref --stdin <stdin &&
752 git rev-parse "$m:$pws" >expect &&
753 git rev-parse refs/blobs/pws >actual &&
754 test_cmp expect actual &&
755 git update-ref -d refs/blobs/pws
758 test_expect_success 'stdin update ref fails with wrong old value' '
759 echo "update $c $m $m~1" >stdin &&
760 test_must_fail git update-ref --stdin <stdin 2>err &&
761 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
762 test_must_fail git rev-parse --verify -q $c
765 test_expect_success 'stdin update ref fails with bad old value' '
766 echo "update $c $m does-not-exist" >stdin &&
767 test_must_fail git update-ref --stdin <stdin 2>err &&
768 grep "fatal: update $c: invalid <old-oid>: does-not-exist" err &&
769 test_must_fail git rev-parse --verify -q $c
772 test_expect_success 'stdin create ref fails with bad new value' '
773 echo "create $c does-not-exist" >stdin &&
774 test_must_fail git update-ref --stdin <stdin 2>err &&
775 grep "fatal: create $c: invalid <new-oid>: does-not-exist" err &&
776 test_must_fail git rev-parse --verify -q $c
779 test_expect_success 'stdin create ref fails with zero new value' '
780 echo "create $c " >stdin &&
781 test_must_fail git update-ref --stdin <stdin 2>err &&
782 grep "fatal: create $c: zero <new-oid>" err &&
783 test_must_fail git rev-parse --verify -q $c
786 test_expect_success 'stdin update ref works with right old value' '
787 echo "update $b $m~1 $m" >stdin &&
788 git update-ref --stdin <stdin &&
789 git rev-parse $m~1 >expect &&
790 git rev-parse $b >actual &&
791 test_cmp expect actual
794 test_expect_success 'stdin delete ref fails with wrong old value' '
795 echo "delete $a $m~1" >stdin &&
796 test_must_fail git update-ref --stdin <stdin 2>err &&
797 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
798 git rev-parse $m >expect &&
799 git rev-parse $a >actual &&
800 test_cmp expect actual
803 test_expect_success 'stdin delete ref fails with zero old value' '
804 echo "delete $a " >stdin &&
805 test_must_fail git update-ref --stdin <stdin 2>err &&
806 grep "fatal: delete $a: zero <old-oid>" err &&
807 git rev-parse $m >expect &&
808 git rev-parse $a >actual &&
809 test_cmp expect actual
812 test_expect_success 'stdin update symref works option no-deref' '
813 git symbolic-ref TESTSYMREF $b &&
814 cat >stdin <<-EOF &&
815 option no-deref
816 update TESTSYMREF $a $b
818 git update-ref --stdin <stdin &&
819 git rev-parse TESTSYMREF >expect &&
820 git rev-parse $a >actual &&
821 test_cmp expect actual &&
822 git rev-parse $m~1 >expect &&
823 git rev-parse $b >actual &&
824 test_cmp expect actual
827 test_expect_success 'stdin delete symref works option no-deref' '
828 git symbolic-ref TESTSYMREF $b &&
829 cat >stdin <<-EOF &&
830 option no-deref
831 delete TESTSYMREF $b
833 git update-ref --stdin <stdin &&
834 test_must_fail git rev-parse --verify -q TESTSYMREF &&
835 git rev-parse $m~1 >expect &&
836 git rev-parse $b >actual &&
837 test_cmp expect actual
840 test_expect_success 'stdin update symref works flag --no-deref' '
841 git symbolic-ref TESTSYMREFONE $b &&
842 git symbolic-ref TESTSYMREFTWO $b &&
843 cat >stdin <<-EOF &&
844 update TESTSYMREFONE $a $b
845 update TESTSYMREFTWO $a $b
847 git update-ref --no-deref --stdin <stdin &&
848 git rev-parse TESTSYMREFONE TESTSYMREFTWO >expect &&
849 git rev-parse $a $a >actual &&
850 test_cmp expect actual &&
851 git rev-parse $m~1 >expect &&
852 git rev-parse $b >actual &&
853 test_cmp expect actual
856 test_expect_success 'stdin delete symref works flag --no-deref' '
857 git symbolic-ref TESTSYMREFONE $b &&
858 git symbolic-ref TESTSYMREFTWO $b &&
859 cat >stdin <<-EOF &&
860 delete TESTSYMREFONE $b
861 delete TESTSYMREFTWO $b
863 git update-ref --no-deref --stdin <stdin &&
864 test_must_fail git rev-parse --verify -q TESTSYMREFONE &&
865 test_must_fail git rev-parse --verify -q TESTSYMREFTWO &&
866 git rev-parse $m~1 >expect &&
867 git rev-parse $b >actual &&
868 test_cmp expect actual
871 test_expect_success 'stdin delete ref works with right old value' '
872 echo "delete $b $m~1" >stdin &&
873 git update-ref --stdin <stdin &&
874 test_must_fail git rev-parse --verify -q $b
877 test_expect_success 'stdin update/create/verify combination works' '
878 cat >stdin <<-EOF &&
879 update $a $m
880 create $b $m
881 verify $c
883 git update-ref --stdin <stdin &&
884 git rev-parse $m >expect &&
885 git rev-parse $a >actual &&
886 test_cmp expect actual &&
887 git rev-parse $b >actual &&
888 test_cmp expect actual &&
889 test_must_fail git rev-parse --verify -q $c
892 test_expect_success 'stdin verify succeeds for correct value' '
893 git rev-parse $m >expect &&
894 echo "verify $m $m" >stdin &&
895 git update-ref --stdin <stdin &&
896 git rev-parse $m >actual &&
897 test_cmp expect actual
900 test_expect_success 'stdin verify succeeds for missing reference' '
901 echo "verify refs/heads/missing $Z" >stdin &&
902 git update-ref --stdin <stdin &&
903 test_must_fail git rev-parse --verify -q refs/heads/missing
906 test_expect_success 'stdin verify treats no value as missing' '
907 echo "verify refs/heads/missing" >stdin &&
908 git update-ref --stdin <stdin &&
909 test_must_fail git rev-parse --verify -q refs/heads/missing
912 test_expect_success 'stdin verify fails for wrong value' '
913 git rev-parse $m >expect &&
914 echo "verify $m $m~1" >stdin &&
915 test_must_fail git update-ref --stdin <stdin &&
916 git rev-parse $m >actual &&
917 test_cmp expect actual
920 test_expect_success 'stdin verify fails for mistaken null value' '
921 git rev-parse $m >expect &&
922 echo "verify $m $Z" >stdin &&
923 test_must_fail git update-ref --stdin <stdin &&
924 git rev-parse $m >actual &&
925 test_cmp expect actual
928 test_expect_success 'stdin verify fails for mistaken empty value' '
929 M=$(git rev-parse $m) &&
930 test_when_finished "git update-ref $m $M" &&
931 git rev-parse $m >expect &&
932 echo "verify $m" >stdin &&
933 test_must_fail git update-ref --stdin <stdin &&
934 git rev-parse $m >actual &&
935 test_cmp expect actual
938 test_expect_success 'stdin update refs works with identity updates' '
939 cat >stdin <<-EOF &&
940 update $a $m $m
941 update $b $m $m
942 update $c $Z $E
944 git update-ref --stdin <stdin &&
945 git rev-parse $m >expect &&
946 git rev-parse $a >actual &&
947 test_cmp expect actual &&
948 git rev-parse $b >actual &&
949 test_cmp expect actual &&
950 test_must_fail git rev-parse --verify -q $c
953 test_expect_success 'stdin update refs fails with wrong old value' '
954 git update-ref $c $m &&
955 cat >stdin <<-EOF &&
956 update $a $m $m
957 update $b $m $m
958 update $c ''
960 test_must_fail git update-ref --stdin <stdin 2>err &&
961 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
962 git rev-parse $m >expect &&
963 git rev-parse $a >actual &&
964 test_cmp expect actual &&
965 git rev-parse $b >actual &&
966 test_cmp expect actual &&
967 git rev-parse $c >actual &&
968 test_cmp expect actual
971 test_expect_success 'stdin delete refs works with packed and loose refs' '
972 git pack-refs --all &&
973 git update-ref $c $m~1 &&
974 cat >stdin <<-EOF &&
975 delete $a $m
976 update $b $Z $m
977 update $c $E $m~1
979 git update-ref --stdin <stdin &&
980 test_must_fail git rev-parse --verify -q $a &&
981 test_must_fail git rev-parse --verify -q $b &&
982 test_must_fail git rev-parse --verify -q $c
985 test_expect_success 'stdin -z works on empty input' '
986 >stdin &&
987 git update-ref -z --stdin <stdin &&
988 git rev-parse --verify -q $m
991 test_expect_success 'stdin -z fails on empty line' '
992 echo "" >stdin &&
993 test_must_fail git update-ref -z --stdin <stdin 2>err &&
994 grep "fatal: whitespace before command: " err
997 test_expect_success 'stdin -z fails on empty command' '
998 printf $F "" >stdin &&
999 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1000 grep "fatal: empty command in input" err
1003 test_expect_success 'stdin -z fails on only whitespace' '
1004 printf $F " " >stdin &&
1005 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1006 grep "fatal: whitespace before command: " err
1009 test_expect_success 'stdin -z fails on leading whitespace' '
1010 printf $F " create $a" "$m" >stdin &&
1011 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1012 grep "fatal: whitespace before command: create $a" err
1015 test_expect_success 'stdin -z fails on unknown command' '
1016 printf $F "unknown $a" >stdin &&
1017 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1018 grep "fatal: unknown command: unknown $a" err
1021 test_expect_success 'stdin -z fails create with no ref' '
1022 printf $F "create " >stdin &&
1023 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1024 grep "fatal: create: missing <ref>" err
1027 test_expect_success 'stdin -z fails create with no new value' '
1028 printf $F "create $a" >stdin &&
1029 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1030 grep "fatal: create $a: unexpected end of input when reading <new-oid>" err
1033 test_expect_success 'stdin -z fails create with too many arguments' '
1034 printf $F "create $a" "$m" "$m" >stdin &&
1035 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1036 grep "fatal: unknown command: $m" err
1039 test_expect_success 'stdin -z fails update with no ref' '
1040 printf $F "update " >stdin &&
1041 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1042 grep "fatal: update: missing <ref>" err
1045 test_expect_success 'stdin -z fails update with too few args' '
1046 printf $F "update $a" "$m" >stdin &&
1047 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1048 grep "fatal: update $a: unexpected end of input when reading <old-oid>" err
1051 test_expect_success 'stdin -z emits warning with empty new value' '
1052 git update-ref $a $m &&
1053 printf $F "update $a" "" "" >stdin &&
1054 git update-ref -z --stdin <stdin 2>err &&
1055 grep "warning: update $a: missing <new-oid>, treating as zero" err &&
1056 test_must_fail git rev-parse --verify -q $a
1059 test_expect_success 'stdin -z fails update with no new value' '
1060 printf $F "update $a" >stdin &&
1061 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1062 grep "fatal: update $a: unexpected end of input when reading <new-oid>" err
1065 test_expect_success 'stdin -z fails update with no old value' '
1066 printf $F "update $a" "$m" >stdin &&
1067 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1068 grep "fatal: update $a: unexpected end of input when reading <old-oid>" err
1071 test_expect_success 'stdin -z fails update with too many arguments' '
1072 printf $F "update $a" "$m" "$m" "$m" >stdin &&
1073 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1074 grep "fatal: unknown command: $m" err
1077 test_expect_success 'stdin -z fails delete with no ref' '
1078 printf $F "delete " >stdin &&
1079 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1080 grep "fatal: delete: missing <ref>" err
1083 test_expect_success 'stdin -z fails delete with no old value' '
1084 printf $F "delete $a" >stdin &&
1085 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1086 grep "fatal: delete $a: unexpected end of input when reading <old-oid>" err
1089 test_expect_success 'stdin -z fails delete with too many arguments' '
1090 printf $F "delete $a" "$m" "$m" >stdin &&
1091 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1092 grep "fatal: unknown command: $m" err
1095 test_expect_success 'stdin -z fails verify with too many arguments' '
1096 printf $F "verify $a" "$m" "$m" >stdin &&
1097 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1098 grep "fatal: unknown command: $m" err
1101 test_expect_success 'stdin -z fails verify with no old value' '
1102 printf $F "verify $a" >stdin &&
1103 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1104 grep "fatal: verify $a: unexpected end of input when reading <old-oid>" err
1107 test_expect_success 'stdin -z fails option with unknown name' '
1108 printf $F "option unknown" >stdin &&
1109 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1110 grep "fatal: option unknown: unknown" err
1113 test_expect_success 'stdin -z fails with duplicate refs' '
1114 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
1115 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1116 test_grep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
1119 test_expect_success 'stdin -z create ref works' '
1120 printf $F "create $a" "$m" >stdin &&
1121 git update-ref -z --stdin <stdin &&
1122 git rev-parse $m >expect &&
1123 git rev-parse $a >actual &&
1124 test_cmp expect actual
1127 test_expect_success 'stdin -z update ref creates with zero old value' '
1128 printf $F "update $b" "$m" "$Z" >stdin &&
1129 git update-ref -z --stdin <stdin &&
1130 git rev-parse $m >expect &&
1131 git rev-parse $b >actual &&
1132 test_cmp expect actual &&
1133 git update-ref -d $b
1136 test_expect_success 'stdin -z update ref creates with empty old value' '
1137 printf $F "update $b" "$m" "" >stdin &&
1138 git update-ref -z --stdin <stdin &&
1139 git rev-parse $m >expect &&
1140 git rev-parse $b >actual &&
1141 test_cmp expect actual
1144 test_expect_success 'stdin -z create ref works with path with space to blob' '
1145 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
1146 git update-ref -z --stdin <stdin &&
1147 git rev-parse "$m:$pws" >expect &&
1148 git rev-parse refs/blobs/pws >actual &&
1149 test_cmp expect actual &&
1150 git update-ref -d refs/blobs/pws
1153 test_expect_success 'stdin -z update ref fails with wrong old value' '
1154 printf $F "update $c" "$m" "$m~1" >stdin &&
1155 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1156 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1157 test_must_fail git rev-parse --verify -q $c
1160 test_expect_success 'stdin -z update ref fails with bad old value' '
1161 printf $F "update $c" "$m" "does-not-exist" >stdin &&
1162 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1163 grep "fatal: update $c: invalid <old-oid>: does-not-exist" err &&
1164 test_must_fail git rev-parse --verify -q $c
1167 test_expect_success 'stdin -z create ref fails when ref exists' '
1168 git update-ref $c $m &&
1169 git rev-parse "$c" >expect &&
1170 printf $F "create $c" "$m~1" >stdin &&
1171 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1172 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1173 git rev-parse "$c" >actual &&
1174 test_cmp expect actual
1177 test_expect_success 'stdin -z create ref fails with bad new value' '
1178 git update-ref -d "$c" &&
1179 printf $F "create $c" "does-not-exist" >stdin &&
1180 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1181 grep "fatal: create $c: invalid <new-oid>: does-not-exist" err &&
1182 test_must_fail git rev-parse --verify -q $c
1185 test_expect_success 'stdin -z create ref fails with empty new value' '
1186 printf $F "create $c" "" >stdin &&
1187 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1188 grep "fatal: create $c: missing <new-oid>" err &&
1189 test_must_fail git rev-parse --verify -q $c
1192 test_expect_success 'stdin -z update ref works with right old value' '
1193 printf $F "update $b" "$m~1" "$m" >stdin &&
1194 git update-ref -z --stdin <stdin &&
1195 git rev-parse $m~1 >expect &&
1196 git rev-parse $b >actual &&
1197 test_cmp expect actual
1200 test_expect_success 'stdin -z delete ref fails with wrong old value' '
1201 printf $F "delete $a" "$m~1" >stdin &&
1202 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1203 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
1204 git rev-parse $m >expect &&
1205 git rev-parse $a >actual &&
1206 test_cmp expect actual
1209 test_expect_success 'stdin -z delete ref fails with zero old value' '
1210 printf $F "delete $a" "$Z" >stdin &&
1211 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1212 grep "fatal: delete $a: zero <old-oid>" err &&
1213 git rev-parse $m >expect &&
1214 git rev-parse $a >actual &&
1215 test_cmp expect actual
1218 test_expect_success 'stdin -z update symref works option no-deref' '
1219 git symbolic-ref TESTSYMREF $b &&
1220 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
1221 git update-ref -z --stdin <stdin &&
1222 git rev-parse TESTSYMREF >expect &&
1223 git rev-parse $a >actual &&
1224 test_cmp expect actual &&
1225 git rev-parse $m~1 >expect &&
1226 git rev-parse $b >actual &&
1227 test_cmp expect actual
1230 test_expect_success 'stdin -z delete symref works option no-deref' '
1231 git symbolic-ref TESTSYMREF $b &&
1232 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
1233 git update-ref -z --stdin <stdin &&
1234 test_must_fail git rev-parse --verify -q TESTSYMREF &&
1235 git rev-parse $m~1 >expect &&
1236 git rev-parse $b >actual &&
1237 test_cmp expect actual
1240 test_expect_success 'stdin -z delete ref works with right old value' '
1241 printf $F "delete $b" "$m~1" >stdin &&
1242 git update-ref -z --stdin <stdin &&
1243 test_must_fail git rev-parse --verify -q $b
1246 test_expect_success 'stdin -z update/create/verify combination works' '
1247 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
1248 git update-ref -z --stdin <stdin &&
1249 git rev-parse $m >expect &&
1250 git rev-parse $a >actual &&
1251 test_cmp expect actual &&
1252 git rev-parse $b >actual &&
1253 test_cmp expect actual &&
1254 test_must_fail git rev-parse --verify -q $c
1257 test_expect_success 'stdin -z verify succeeds for correct value' '
1258 git rev-parse $m >expect &&
1259 printf $F "verify $m" "$m" >stdin &&
1260 git update-ref -z --stdin <stdin &&
1261 git rev-parse $m >actual &&
1262 test_cmp expect actual
1265 test_expect_success 'stdin -z verify succeeds for missing reference' '
1266 printf $F "verify refs/heads/missing" "$Z" >stdin &&
1267 git update-ref -z --stdin <stdin &&
1268 test_must_fail git rev-parse --verify -q refs/heads/missing
1271 test_expect_success 'stdin -z verify treats no value as missing' '
1272 printf $F "verify refs/heads/missing" "" >stdin &&
1273 git update-ref -z --stdin <stdin &&
1274 test_must_fail git rev-parse --verify -q refs/heads/missing
1277 test_expect_success 'stdin -z verify fails for wrong value' '
1278 git rev-parse $m >expect &&
1279 printf $F "verify $m" "$m~1" >stdin &&
1280 test_must_fail git update-ref -z --stdin <stdin &&
1281 git rev-parse $m >actual &&
1282 test_cmp expect actual
1285 test_expect_success 'stdin -z verify fails for mistaken null value' '
1286 git rev-parse $m >expect &&
1287 printf $F "verify $m" "$Z" >stdin &&
1288 test_must_fail git update-ref -z --stdin <stdin &&
1289 git rev-parse $m >actual &&
1290 test_cmp expect actual
1293 test_expect_success 'stdin -z verify fails for mistaken empty value' '
1294 M=$(git rev-parse $m) &&
1295 test_when_finished "git update-ref $m $M" &&
1296 git rev-parse $m >expect &&
1297 printf $F "verify $m" "" >stdin &&
1298 test_must_fail git update-ref -z --stdin <stdin &&
1299 git rev-parse $m >actual &&
1300 test_cmp expect actual
1303 test_expect_success 'stdin -z update refs works with identity updates' '
1304 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
1305 git update-ref -z --stdin <stdin &&
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 test_must_fail git rev-parse --verify -q $c
1314 test_expect_success 'stdin -z update refs fails with wrong old value' '
1315 git update-ref $c $m &&
1316 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
1317 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1318 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1319 git rev-parse $m >expect &&
1320 git rev-parse $a >actual &&
1321 test_cmp expect actual &&
1322 git rev-parse $b >actual &&
1323 test_cmp expect actual &&
1324 git rev-parse $c >actual &&
1325 test_cmp expect actual
1328 test_expect_success 'stdin -z delete refs works with packed and loose refs' '
1329 git pack-refs --all &&
1330 git update-ref $c $m~1 &&
1331 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
1332 git update-ref -z --stdin <stdin &&
1333 test_must_fail git rev-parse --verify -q $a &&
1334 test_must_fail git rev-parse --verify -q $b &&
1335 test_must_fail git rev-parse --verify -q $c
1338 test_expect_success 'fails with duplicate HEAD update' '
1339 git branch target1 $A &&
1340 git checkout target1 &&
1341 cat >stdin <<-EOF &&
1342 update refs/heads/target1 $C
1343 option no-deref
1344 update HEAD $B
1346 test_must_fail git update-ref --stdin <stdin 2>err &&
1347 test_grep "fatal: multiple updates for '\''HEAD'\'' (including one via its referent .refs/heads/target1.) are not allowed" err &&
1348 echo "refs/heads/target1" >expect &&
1349 git symbolic-ref HEAD >actual &&
1350 test_cmp expect actual &&
1351 echo "$A" >expect &&
1352 git rev-parse refs/heads/target1 >actual &&
1353 test_cmp expect actual
1356 test_expect_success 'fails with duplicate ref update via symref' '
1357 git branch target2 $A &&
1358 git symbolic-ref refs/heads/symref2 refs/heads/target2 &&
1359 cat >stdin <<-EOF &&
1360 update refs/heads/target2 $C
1361 update refs/heads/symref2 $B
1363 test_must_fail git update-ref --stdin <stdin 2>err &&
1364 test_grep "fatal: multiple updates for '\''refs/heads/target2'\'' (including one via symref .refs/heads/symref2.) are not allowed" err &&
1365 echo "refs/heads/target2" >expect &&
1366 git symbolic-ref refs/heads/symref2 >actual &&
1367 test_cmp expect actual &&
1368 echo "$A" >expect &&
1369 git rev-parse refs/heads/target2 >actual &&
1370 test_cmp expect actual
1373 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' '
1375 for i in $(test_seq 33)
1377 echo "create refs/heads/$i HEAD" || exit 1
1378 done >large_input &&
1379 run_with_limited_open_files git update-ref --stdin <large_input &&
1380 git rev-parse --verify -q refs/heads/33
1384 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches does not burst open file limit' '
1386 for i in $(test_seq 33)
1388 echo "delete refs/heads/$i HEAD" || exit 1
1389 done >large_input &&
1390 run_with_limited_open_files git update-ref --stdin <large_input &&
1391 test_must_fail git rev-parse --verify -q refs/heads/33
1395 test_expect_success 'handle per-worktree refs in refs/bisect' '
1396 git commit --allow-empty -m "initial commit" &&
1397 git worktree add -b branch worktree &&
1399 cd worktree &&
1400 git commit --allow-empty -m "test commit" &&
1401 git for-each-ref >for-each-ref.out &&
1402 ! grep refs/bisect for-each-ref.out &&
1403 git update-ref refs/bisect/something HEAD &&
1404 git rev-parse refs/bisect/something >../worktree-head &&
1405 git for-each-ref | grep refs/bisect/something
1406 ) &&
1407 git show-ref >actual &&
1408 ! grep 'refs/bisect' actual &&
1409 test_must_fail git rev-parse refs/bisect/something &&
1410 git update-ref refs/bisect/something HEAD &&
1411 git rev-parse refs/bisect/something >main-head &&
1412 ! test_cmp main-head worktree-head
1415 test_expect_success 'transaction handles empty commit' '
1416 cat >stdin <<-EOF &&
1417 start
1418 prepare
1419 commit
1421 git update-ref --stdin <stdin >actual &&
1422 printf "%s: ok\n" start prepare commit >expect &&
1423 test_cmp expect actual
1426 test_expect_success 'transaction handles empty commit with missing prepare' '
1427 cat >stdin <<-EOF &&
1428 start
1429 commit
1431 git update-ref --stdin <stdin >actual &&
1432 printf "%s: ok\n" start commit >expect &&
1433 test_cmp expect actual
1436 test_expect_success 'transaction handles sole commit' '
1437 cat >stdin <<-EOF &&
1438 commit
1440 git update-ref --stdin <stdin >actual &&
1441 printf "%s: ok\n" commit >expect &&
1442 test_cmp expect actual
1445 test_expect_success 'transaction handles empty abort' '
1446 cat >stdin <<-EOF &&
1447 start
1448 prepare
1449 abort
1451 git update-ref --stdin <stdin >actual &&
1452 printf "%s: ok\n" start prepare abort >expect &&
1453 test_cmp expect actual
1456 test_expect_success 'transaction exits on multiple aborts' '
1457 cat >stdin <<-EOF &&
1458 abort
1459 abort
1461 test_must_fail git update-ref --stdin <stdin >actual 2>err &&
1462 printf "%s: ok\n" abort >expect &&
1463 test_cmp expect actual &&
1464 grep "fatal: transaction is closed" err
1467 test_expect_success 'transaction exits on start after prepare' '
1468 cat >stdin <<-EOF &&
1469 prepare
1470 start
1472 test_must_fail git update-ref --stdin <stdin 2>err >actual &&
1473 printf "%s: ok\n" prepare >expect &&
1474 test_cmp expect actual &&
1475 grep "fatal: prepared transactions can only be closed" err
1478 test_expect_success 'transaction handles empty abort with missing prepare' '
1479 cat >stdin <<-EOF &&
1480 start
1481 abort
1483 git update-ref --stdin <stdin >actual &&
1484 printf "%s: ok\n" start abort >expect &&
1485 test_cmp expect actual
1488 test_expect_success 'transaction handles sole abort' '
1489 cat >stdin <<-EOF &&
1490 abort
1492 git update-ref --stdin <stdin >actual &&
1493 printf "%s: ok\n" abort >expect &&
1494 test_cmp expect actual
1497 test_expect_success 'transaction can handle commit' '
1498 cat >stdin <<-EOF &&
1499 start
1500 create $a HEAD
1501 commit
1503 git update-ref --stdin <stdin >actual &&
1504 printf "%s: ok\n" start commit >expect &&
1505 test_cmp expect actual &&
1506 git rev-parse HEAD >expect &&
1507 git rev-parse $a >actual &&
1508 test_cmp expect actual
1511 test_expect_success 'transaction can handle abort' '
1512 cat >stdin <<-EOF &&
1513 start
1514 create $b HEAD
1515 abort
1517 git update-ref --stdin <stdin >actual &&
1518 printf "%s: ok\n" start abort >expect &&
1519 test_cmp expect actual &&
1520 test_must_fail git show-ref --verify -q $b
1523 test_expect_success 'transaction aborts by default' '
1524 cat >stdin <<-EOF &&
1525 start
1526 create $b HEAD
1528 git update-ref --stdin <stdin >actual &&
1529 printf "%s: ok\n" start >expect &&
1530 test_cmp expect actual &&
1531 test_must_fail git show-ref --verify -q $b
1534 test_expect_success 'transaction with prepare aborts by default' '
1535 cat >stdin <<-EOF &&
1536 start
1537 create $b HEAD
1538 prepare
1540 git update-ref --stdin <stdin >actual &&
1541 printf "%s: ok\n" start prepare >expect &&
1542 test_cmp expect actual &&
1543 test_must_fail git show-ref --verify -q $b
1546 test_expect_success 'transaction can commit multiple times' '
1547 cat >stdin <<-EOF &&
1548 start
1549 create refs/heads/branch-1 $A
1550 commit
1551 start
1552 create refs/heads/branch-2 $B
1553 commit
1555 git update-ref --stdin <stdin >actual &&
1556 printf "%s: ok\n" start commit start commit >expect &&
1557 test_cmp expect actual &&
1558 echo "$A" >expect &&
1559 git rev-parse refs/heads/branch-1 >actual &&
1560 test_cmp expect actual &&
1561 echo "$B" >expect &&
1562 git rev-parse refs/heads/branch-2 >actual &&
1563 test_cmp expect actual
1566 test_expect_success 'transaction can create and delete' '
1567 cat >stdin <<-EOF &&
1568 start
1569 create refs/heads/create-and-delete $A
1570 commit
1571 start
1572 delete refs/heads/create-and-delete $A
1573 commit
1575 git update-ref --stdin <stdin >actual &&
1576 printf "%s: ok\n" start commit start commit >expect &&
1577 test_cmp expect actual &&
1578 test_must_fail git show-ref --verify refs/heads/create-and-delete
1581 test_expect_success 'transaction can commit after abort' '
1582 cat >stdin <<-EOF &&
1583 start
1584 create refs/heads/abort $A
1585 abort
1586 start
1587 create refs/heads/abort $A
1588 commit
1590 git update-ref --stdin <stdin >actual &&
1591 printf "%s: ok\n" start abort start commit >expect &&
1592 echo "$A" >expect &&
1593 git rev-parse refs/heads/abort >actual &&
1594 test_cmp expect actual
1597 test_expect_success 'transaction cannot restart ongoing transaction' '
1598 cat >stdin <<-EOF &&
1599 start
1600 create refs/heads/restart $A
1601 start
1602 commit
1604 test_must_fail git update-ref --stdin <stdin >actual &&
1605 printf "%s: ok\n" start >expect &&
1606 test_cmp expect actual &&
1607 test_must_fail git show-ref --verify refs/heads/restart
1610 test_expect_success PIPE 'transaction flushes status updates' '
1611 mkfifo in out &&
1612 (git update-ref --stdin <in >out &) &&
1614 exec 9>in &&
1615 exec 8<out &&
1616 test_when_finished "exec 9>&-" &&
1617 test_when_finished "exec 8<&-" &&
1619 echo "start" >&9 &&
1620 echo "start: ok" >expected &&
1621 read line <&8 &&
1622 echo "$line" >actual &&
1623 test_cmp expected actual &&
1625 echo "create refs/heads/flush $A" >&9 &&
1627 echo prepare >&9 &&
1628 echo "prepare: ok" >expected &&
1629 read line <&8 &&
1630 echo "$line" >actual &&
1631 test_cmp expected actual &&
1633 # This must now fail given that we have locked the ref.
1634 test_must_fail git update-ref refs/heads/flush $B 2>stderr &&
1635 grep "fatal: update_ref failed for ref ${SQ}refs/heads/flush${SQ}: cannot lock ref" stderr &&
1637 echo commit >&9 &&
1638 echo "commit: ok" >expected &&
1639 read line <&8 &&
1640 echo "$line" >actual &&
1641 test_cmp expected actual
1644 test_done