3 # Copyright (c) 2006 Shawn Pearce
6 test_description='Test git update-ref and basic ref logging'
17 create_test_commits ()
20 for name in A B C D E F
23 T=$(git write-tree) &&
24 sha1=$(echo $name | git commit-tree $T) &&
29 test_expect_success setup '
30 create_test_commits "" &&
34 create_test_commits "bare" &&
38 test_expect_success "create $m" '
39 git update-ref $m $A &&
40 test $A = $(git show-ref -s --verify $m)
42 test_expect_success "create $m with oldvalue verification" '
43 git update-ref $m $B $A &&
44 test $B = $(git show-ref -s --verify $m)
46 test_expect_success "fail to delete $m with stale ref" '
47 test_must_fail git update-ref -d $m $A &&
48 test $B = "$(git show-ref -s --verify $m)"
50 test_expect_success "delete $m" '
51 test_when_finished "git update-ref -d $m" &&
52 git update-ref -d $m $B &&
53 test_must_fail git show-ref --verify -q $m
56 test_expect_success "delete $m without oldvalue verification" '
57 test_when_finished "git update-ref -d $m" &&
58 git update-ref $m $A &&
59 test $A = $(git show-ref -s --verify $m) &&
60 git update-ref -d $m &&
61 test_must_fail git show-ref --verify -q $m
64 test_expect_success "fail to create $n" '
65 test_when_finished "rm -f .git/$n_dir" &&
67 test_must_fail git update-ref $n $A
70 test_expect_success "create $m (by HEAD)" '
71 git update-ref HEAD $A &&
72 test $A = $(git show-ref -s --verify $m)
74 test_expect_success "create $m (by HEAD) with oldvalue verification" '
75 git update-ref HEAD $B $A &&
76 test $B = $(git show-ref -s --verify $m)
78 test_expect_success "fail to delete $m (by HEAD) with stale ref" '
79 test_must_fail git update-ref -d HEAD $A &&
80 test $B = $(git show-ref -s --verify $m)
82 test_expect_success "delete $m (by HEAD)" '
83 test_when_finished "git update-ref -d $m" &&
84 git update-ref -d HEAD $B &&
85 test_must_fail git show-ref --verify -q $m
88 test_expect_success "deleting current branch adds message to HEAD's log" '
89 test_when_finished "git update-ref -d $m" &&
90 git update-ref $m $A &&
91 git symbolic-ref HEAD $m &&
92 git update-ref -m delete-$m -d $m &&
93 test_must_fail git show-ref --verify -q $m &&
94 grep "delete-$m$" .git/logs/HEAD
97 test_expect_success "deleting by HEAD adds message to HEAD's log" '
98 test_when_finished "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 grep "delete-by-head$" .git/logs/HEAD
106 test_expect_success 'update-ref does not create reflogs by default' '
107 test_when_finished "git update-ref -d $outside" &&
108 git update-ref $outside $A &&
109 git rev-parse $A >expect &&
110 git rev-parse $outside >actual &&
111 test_cmp expect actual &&
112 test_must_fail git reflog exists $outside
115 test_expect_success 'update-ref creates reflogs with --create-reflog' '
116 test_when_finished "git update-ref -d $outside" &&
117 git update-ref --create-reflog $outside $A &&
118 git rev-parse $A >expect &&
119 git rev-parse $outside >actual &&
120 test_cmp expect actual &&
121 git reflog exists $outside
124 test_expect_success 'creates no reflog in bare repository' '
125 git -C $bare update-ref $m $bareA &&
126 git -C $bare rev-parse $bareA >expect &&
127 git -C $bare rev-parse $m >actual &&
128 test_cmp expect actual &&
129 test_must_fail git -C $bare reflog exists $m
132 test_expect_success 'core.logAllRefUpdates=true creates reflog in bare repository' '
133 test_when_finished "git -C $bare config --unset core.logAllRefUpdates && \
135 git -C $bare config core.logAllRefUpdates true &&
136 git -C $bare update-ref $m $bareB &&
137 git -C $bare rev-parse $bareB >expect &&
138 git -C $bare rev-parse $m >actual &&
139 test_cmp expect actual &&
140 git -C $bare reflog exists $m
143 test_expect_success 'core.logAllRefUpdates=true does not create reflog by default' '
144 test_config core.logAllRefUpdates true &&
145 test_when_finished "git update-ref -d $outside" &&
146 git update-ref $outside $A &&
147 git rev-parse $A >expect &&
148 git rev-parse $outside >actual &&
149 test_cmp expect actual &&
150 test_must_fail git reflog exists $outside
153 test_expect_success 'core.logAllRefUpdates=always creates reflog by default' '
154 test_config core.logAllRefUpdates always &&
155 test_when_finished "git update-ref -d $outside" &&
156 git update-ref $outside $A &&
157 git rev-parse $A >expect &&
158 git rev-parse $outside >actual &&
159 test_cmp expect actual &&
160 git reflog exists $outside
163 test_expect_success 'core.logAllRefUpdates=always creates reflog for ORIG_HEAD' '
164 test_config core.logAllRefUpdates always &&
165 git update-ref ORIG_HEAD $A &&
166 git reflog exists ORIG_HEAD
169 test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always' '
170 test_config core.logAllRefUpdates true &&
171 test_when_finished "git update-ref -d $outside" &&
172 git update-ref --no-create-reflog $outside $A &&
173 git rev-parse $A >expect &&
174 git rev-parse $outside >actual &&
175 test_cmp expect actual &&
176 test_must_fail git reflog exists $outside
179 test_expect_success "create $m (by HEAD)" '
180 git update-ref HEAD $A &&
181 test $A = $(git show-ref -s --verify $m)
183 test_expect_success 'pack refs' '
186 test_expect_success "move $m (by HEAD)" '
187 git update-ref HEAD $B $A &&
188 test $B = $(git show-ref -s --verify $m)
190 test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" '
191 test_when_finished "git update-ref -d $m" &&
192 git update-ref -d HEAD $B &&
193 ! grep "$m" .git/packed-refs &&
194 test_must_fail git show-ref --verify -q $m
197 test_expect_success 'delete symref without dereference' '
198 test_when_finished "git update-ref -d $m" &&
202 git symbolic-ref SYMREF $m &&
203 git update-ref --no-deref -d SYMREF &&
204 git show-ref --verify -q $m &&
205 test_must_fail git show-ref --verify -q SYMREF &&
206 test_must_fail git symbolic-ref SYMREF
209 test_expect_success 'delete symref without dereference when the referred ref is packed' '
210 test_when_finished "git update-ref -d $m" &&
214 git symbolic-ref SYMREF $m &&
215 git pack-refs --all &&
216 git update-ref --no-deref -d SYMREF &&
217 git show-ref --verify -q $m &&
218 test_must_fail git show-ref --verify -q SYMREF &&
219 test_must_fail git symbolic-ref SYMREF
222 test_expect_success 'update-ref -d is not confused by self-reference' '
223 git symbolic-ref refs/heads/self refs/heads/self &&
224 test_when_finished "rm -f .git/refs/heads/self" &&
225 test_path_is_file .git/refs/heads/self &&
226 test_must_fail git update-ref -d refs/heads/self &&
227 test_path_is_file .git/refs/heads/self
230 test_expect_success 'update-ref --no-deref -d can delete self-reference' '
231 git symbolic-ref refs/heads/self refs/heads/self &&
232 test_when_finished "rm -f .git/refs/heads/self" &&
233 test_path_is_file .git/refs/heads/self &&
234 git update-ref --no-deref -d refs/heads/self &&
235 test_must_fail git show-ref --verify -q refs/heads/self
238 test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
239 >.git/refs/heads/bad &&
240 test_when_finished "rm -f .git/refs/heads/bad" &&
241 git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
242 test_when_finished "git update-ref -d refs/heads/ref-to-bad" &&
243 test_path_is_file .git/refs/heads/ref-to-bad &&
244 git update-ref --no-deref -d refs/heads/ref-to-bad &&
245 test_must_fail git show-ref --verify -q refs/heads/ref-to-bad
248 test_expect_success '(not) create HEAD with old sha1' '
249 test_must_fail git update-ref HEAD $A $B
251 test_expect_success "(not) prior created .git/$m" '
252 test_when_finished "git update-ref -d $m" &&
253 test_must_fail git show-ref --verify -q $m
256 test_expect_success 'create HEAD' '
257 git update-ref HEAD $A
259 test_expect_success '(not) change HEAD with wrong SHA1' '
260 test_must_fail git update-ref HEAD $B $Z
262 test_expect_success "(not) changed .git/$m" '
263 test_when_finished "git update-ref -d $m" &&
264 ! test $B = $(git show-ref -s --verify $m)
267 rm -f .git/logs/refs/heads/master
268 test_expect_success "create $m (logged by touch)" '
269 test_config core.logAllRefUpdates false &&
270 GIT_COMMITTER_DATE="2005-05-26 23:30" \
271 git update-ref --create-reflog HEAD $A -m "Initial Creation" &&
272 test $A = $(git show-ref -s --verify $m)
274 test_expect_success "update $m (logged by touch)" '
275 test_config core.logAllRefUpdates false &&
276 GIT_COMMITTER_DATE="2005-05-26 23:31" \
277 git update-ref HEAD $B $A -m "Switch" &&
278 test $B = $(git show-ref -s --verify $m)
280 test_expect_success "set $m (logged by touch)" '
281 test_config core.logAllRefUpdates false &&
282 GIT_COMMITTER_DATE="2005-05-26 23:41" \
283 git update-ref HEAD $A &&
284 test $A = $(git show-ref -s --verify $m)
287 test_expect_success 'empty directory removal' '
288 git branch d1/d2/r1 HEAD &&
289 git branch d1/r2 HEAD &&
290 test_path_is_file .git/refs/heads/d1/d2/r1 &&
291 test_path_is_file .git/logs/refs/heads/d1/d2/r1 &&
292 git branch -d d1/d2/r1 &&
293 test_must_fail git show-ref --verify -q refs/heads/d1/d2 &&
294 test_must_fail git show-ref --verify -q logs/refs/heads/d1/d2 &&
295 test_path_is_file .git/refs/heads/d1/r2 &&
296 test_path_is_file .git/logs/refs/heads/d1/r2
299 test_expect_success 'symref empty directory removal' '
300 git branch e1/e2/r1 HEAD &&
301 git branch e1/r2 HEAD &&
302 git checkout e1/e2/r1 &&
303 test_when_finished "git checkout master" &&
304 test_path_is_file .git/refs/heads/e1/e2/r1 &&
305 test_path_is_file .git/logs/refs/heads/e1/e2/r1 &&
306 git update-ref -d HEAD &&
307 test_must_fail git show-ref --verify -q refs/heads/e1/e2 &&
308 test_must_fail git show-ref --verify -q logs/refs/heads/e1/e2 &&
309 test_path_is_file .git/refs/heads/e1/r2 &&
310 test_path_is_file .git/logs/refs/heads/e1/r2 &&
311 test_path_is_file .git/logs/HEAD
315 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
316 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
317 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
319 test_expect_success "verifying $m's log (logged by touch)" '
320 test_when_finished "rm -rf .git/$m .git/logs expect" &&
321 test_cmp expect .git/logs/$m
324 test_expect_success "create $m (logged by config)" '
325 test_config core.logAllRefUpdates true &&
326 GIT_COMMITTER_DATE="2005-05-26 23:32" \
327 git update-ref HEAD $A -m "Initial Creation" &&
328 test $A = $(git show-ref -s --verify $m)
330 test_expect_success "update $m (logged by config)" '
331 test_config core.logAllRefUpdates true &&
332 GIT_COMMITTER_DATE="2005-05-26 23:33" \
333 git update-ref HEAD $B $A -m "Switch" &&
334 test $B = $(git show-ref -s --verify $m)
336 test_expect_success "set $m (logged by config)" '
337 test_config core.logAllRefUpdates true &&
338 GIT_COMMITTER_DATE="2005-05-26 23:43" \
339 git update-ref HEAD $A &&
340 test $A = $(git show-ref -s --verify $m)
344 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
345 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
346 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
348 test_expect_success "verifying $m's log (logged by config)" '
349 test_when_finished "rm -f .git/$m .git/logs/$m expect" &&
350 test_cmp expect .git/logs/$m
353 test_expect_success 'set up for querying the reflog' '
354 git update-ref $m $D &&
355 cat >.git/logs/$m <<-EOF
356 $Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
357 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
358 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
359 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
360 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
364 ed="Thu, 26 May 2005 18:32:00 -0500"
365 gd="Thu, 26 May 2005 18:33:00 -0500"
366 ld="Thu, 26 May 2005 18:43:00 -0500"
367 test_expect_success 'Query "master@{May 25 2005}" (before history)' '
368 test_when_finished "rm -f o e" &&
369 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
372 echo "warning: log for '\''master'\'' only goes back to $ed" >expect &&
373 test_i18ncmp expect e
375 test_expect_success 'Query master@{2005-05-25} (before history)' '
376 test_when_finished "rm -f o e" &&
377 git rev-parse --verify master@{2005-05-25} >o 2>e &&
380 echo "warning: log for '\''master'\'' only goes back to $ed" >expect &&
381 test_i18ncmp expect e
383 test_expect_success 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' '
384 test_when_finished "rm -f o e" &&
385 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
388 echo "warning: log for '\''master'\'' only goes back to $ed" >expect &&
389 test_i18ncmp expect e
391 test_expect_success 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' '
392 test_when_finished "rm -f o e" &&
393 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
398 test_expect_success 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' '
399 test_when_finished "rm -f o e" &&
400 git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e &&
405 test_expect_success 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' '
406 test_when_finished "rm -f o e" &&
407 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
410 test_i18ngrep -F "warning: log for ref $m has gap after $gd" e
412 test_expect_success 'Query "master@{2005-05-26 23:38:00}" (middle of history)' '
413 test_when_finished "rm -f o e" &&
414 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
419 test_expect_success 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' '
420 test_when_finished "rm -f o e" &&
421 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
426 test_expect_success 'Query "master@{2005-05-28}" (past end of history)' '
427 test_when_finished "rm -f o e" &&
428 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
431 test_i18ngrep -F "warning: log for ref $m unexpectedly ended on $ld" e
434 rm -f .git/$m .git/logs/$m expect
436 test_expect_success 'creating initial files' '
437 test_when_finished rm -f M &&
440 GIT_AUTHOR_DATE="2005-05-26 23:30" \
441 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
442 h_TEST=$(git rev-parse --verify HEAD) &&
443 echo The other day this did not work. >M &&
444 echo And then Bob told me how to fix it. >>M &&
446 GIT_AUTHOR_DATE="2005-05-26 23:41" \
447 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
448 h_OTHER=$(git rev-parse --verify HEAD) &&
449 GIT_AUTHOR_DATE="2005-05-26 23:44" \
450 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
451 h_FIXED=$(git rev-parse --verify HEAD) &&
452 echo Merged initial commit and a later commit. >M &&
453 echo $h_TEST >.git/MERGE_HEAD &&
454 GIT_AUTHOR_DATE="2005-05-26 23:45" \
455 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
456 h_MERGED=$(git rev-parse --verify HEAD)
460 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
461 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
462 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
463 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
465 test_expect_success 'git commit logged updates' '
466 test_cmp expect .git/logs/$m
468 unset h_TEST h_OTHER h_FIXED h_MERGED
470 test_expect_success 'git cat-file blob master:F (expect OTHER)' '
471 test OTHER = $(git cat-file blob master:F)
473 test_expect_success 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' '
474 test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")
476 test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' '
477 test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")
480 # Test adding and deleting pseudorefs
482 test_expect_success 'given old value for missing pseudoref, do not create' '
483 test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
484 test_must_fail git rev-parse PSEUDOREF &&
485 test_i18ngrep "unable to resolve reference" err
488 test_expect_success 'create pseudoref' '
489 git update-ref PSEUDOREF $A &&
490 test $A = $(git rev-parse PSEUDOREF)
493 test_expect_success 'overwrite pseudoref with no old value given' '
494 git update-ref PSEUDOREF $B &&
495 test $B = $(git rev-parse PSEUDOREF)
498 test_expect_success 'overwrite pseudoref with correct old value' '
499 git update-ref PSEUDOREF $C $B &&
500 test $C = $(git rev-parse PSEUDOREF)
503 test_expect_success 'do not overwrite pseudoref with wrong old value' '
504 test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
505 test $C = $(git rev-parse PSEUDOREF) &&
506 test_i18ngrep "cannot lock ref.*expected" err
509 test_expect_success 'delete pseudoref' '
510 git update-ref -d PSEUDOREF &&
511 test_must_fail git rev-parse PSEUDOREF
514 test_expect_success 'do not delete pseudoref with wrong old value' '
515 git update-ref PSEUDOREF $A &&
516 test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
517 test $A = $(git rev-parse PSEUDOREF) &&
518 test_i18ngrep "cannot lock ref.*expected" err
521 test_expect_success 'delete pseudoref with correct old value' '
522 git update-ref -d PSEUDOREF $A &&
523 test_must_fail git rev-parse PSEUDOREF
526 test_expect_success 'create pseudoref with old OID zero' '
527 git update-ref PSEUDOREF $A $Z &&
528 test $A = $(git rev-parse PSEUDOREF)
531 test_expect_success 'do not overwrite pseudoref with old OID zero' '
532 test_when_finished git update-ref -d PSEUDOREF &&
533 test_must_fail git update-ref PSEUDOREF $B $Z 2>err &&
534 test $A = $(git rev-parse PSEUDOREF) &&
535 test_i18ngrep "already exists" err
545 pws='path with space'
547 test_expect_success 'stdin test setup' '
548 echo "$pws" >"$pws" &&
553 test_expect_success '-z fails without --stdin' '
554 test_must_fail git update-ref -z $m $m $m 2>err &&
555 test_i18ngrep "usage: git update-ref" err
558 test_expect_success 'stdin works with no input' '
560 git update-ref --stdin <stdin &&
561 git rev-parse --verify -q $m
564 test_expect_success 'stdin fails on empty line' '
566 test_must_fail git update-ref --stdin <stdin 2>err &&
567 grep "fatal: empty command in input" err
570 test_expect_success 'stdin fails on only whitespace' '
572 test_must_fail git update-ref --stdin <stdin 2>err &&
573 grep "fatal: whitespace before command: " err
576 test_expect_success 'stdin fails on leading whitespace' '
577 echo " create $a $m" >stdin &&
578 test_must_fail git update-ref --stdin <stdin 2>err &&
579 grep "fatal: whitespace before command: create $a $m" err
582 test_expect_success 'stdin fails on unknown command' '
583 echo "unknown $a" >stdin &&
584 test_must_fail git update-ref --stdin <stdin 2>err &&
585 grep "fatal: unknown command: unknown $a" err
588 test_expect_success 'stdin fails on unbalanced quotes' '
589 echo "create $a \"master" >stdin &&
590 test_must_fail git update-ref --stdin <stdin 2>err &&
591 grep "fatal: badly quoted argument: \\\"master" err
594 test_expect_success PREPARE_FOR_MAIN_BRANCH 'stdin fails on invalid escape' '
595 echo "create $a \"ma\zn\"" >stdin &&
596 test_must_fail git update-ref --stdin <stdin 2>err &&
597 grep "fatal: badly quoted argument: \\\"ma\\\\zn\\\"" err
600 test_expect_success 'stdin fails on junk after quoted argument' '
601 echo "create \"$a\"master" >stdin &&
602 test_must_fail git update-ref --stdin <stdin 2>err &&
603 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"master" err
606 test_expect_success 'stdin fails create with no ref' '
607 echo "create " >stdin &&
608 test_must_fail git update-ref --stdin <stdin 2>err &&
609 grep "fatal: create: missing <ref>" err
612 test_expect_success 'stdin fails create with no new value' '
613 echo "create $a" >stdin &&
614 test_must_fail git update-ref --stdin <stdin 2>err &&
615 grep "fatal: create $a: missing <newvalue>" err
618 test_expect_success 'stdin fails create with too many arguments' '
619 echo "create $a $m $m" >stdin &&
620 test_must_fail git update-ref --stdin <stdin 2>err &&
621 grep "fatal: create $a: extra input: $m" err
624 test_expect_success 'stdin fails update with no ref' '
625 echo "update " >stdin &&
626 test_must_fail git update-ref --stdin <stdin 2>err &&
627 grep "fatal: update: missing <ref>" err
630 test_expect_success 'stdin fails update with no new value' '
631 echo "update $a" >stdin &&
632 test_must_fail git update-ref --stdin <stdin 2>err &&
633 grep "fatal: update $a: missing <newvalue>" err
636 test_expect_success 'stdin fails update with too many arguments' '
637 echo "update $a $m $m $m" >stdin &&
638 test_must_fail git update-ref --stdin <stdin 2>err &&
639 grep "fatal: update $a: extra input: $m" err
642 test_expect_success 'stdin fails delete with no ref' '
643 echo "delete " >stdin &&
644 test_must_fail git update-ref --stdin <stdin 2>err &&
645 grep "fatal: delete: missing <ref>" err
648 test_expect_success 'stdin fails delete with too many arguments' '
649 echo "delete $a $m $m" >stdin &&
650 test_must_fail git update-ref --stdin <stdin 2>err &&
651 grep "fatal: delete $a: extra input: $m" err
654 test_expect_success 'stdin fails verify with too many arguments' '
655 echo "verify $a $m $m" >stdin &&
656 test_must_fail git update-ref --stdin <stdin 2>err &&
657 grep "fatal: verify $a: extra input: $m" err
660 test_expect_success 'stdin fails option with unknown name' '
661 echo "option unknown" >stdin &&
662 test_must_fail git update-ref --stdin <stdin 2>err &&
663 grep "fatal: option unknown: unknown" err
666 test_expect_success 'stdin fails with duplicate refs' '
672 test_must_fail git update-ref --stdin <stdin 2>err &&
673 test_i18ngrep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
676 test_expect_success 'stdin create ref works' '
677 echo "create $a $m" >stdin &&
678 git update-ref --stdin <stdin &&
679 git rev-parse $m >expect &&
680 git rev-parse $a >actual &&
681 test_cmp expect actual
684 test_expect_success 'stdin does not create reflogs by default' '
685 test_when_finished "git update-ref -d $outside" &&
686 echo "create $outside $m" >stdin &&
687 git update-ref --stdin <stdin &&
688 git rev-parse $m >expect &&
689 git rev-parse $outside >actual &&
690 test_cmp expect actual &&
691 test_must_fail git reflog exists $outside
694 test_expect_success 'stdin creates reflogs with --create-reflog' '
695 test_when_finished "git update-ref -d $outside" &&
696 echo "create $outside $m" >stdin &&
697 git update-ref --create-reflog --stdin <stdin &&
698 git rev-parse $m >expect &&
699 git rev-parse $outside >actual &&
700 test_cmp expect actual &&
701 git reflog exists $outside
704 test_expect_success 'stdin succeeds with quoted argument' '
705 git update-ref -d $a &&
706 echo "create $a \"$m\"" >stdin &&
707 git update-ref --stdin <stdin &&
708 git rev-parse $m >expect &&
709 git rev-parse $a >actual &&
710 test_cmp expect actual
713 test_expect_success PREPARE_FOR_MAIN_BRANCH 'stdin succeeds with escaped character' '
714 git update-ref -d $a &&
715 echo "create $a \"ma\\151n\"" >stdin &&
716 git update-ref --stdin <stdin &&
717 git rev-parse $m >expect &&
718 git rev-parse $a >actual &&
719 test_cmp expect actual
722 test_expect_success 'stdin update ref creates with zero old value' '
723 echo "update $b $m $Z" >stdin &&
724 git update-ref --stdin <stdin &&
725 git rev-parse $m >expect &&
726 git rev-parse $b >actual &&
727 test_cmp expect actual &&
731 test_expect_success 'stdin update ref creates with empty old value' '
732 echo "update $b $m $E" >stdin &&
733 git update-ref --stdin <stdin &&
734 git rev-parse $m >expect &&
735 git rev-parse $b >actual &&
736 test_cmp expect actual
739 test_expect_success 'stdin create ref works with path with space to blob' '
740 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
741 git update-ref --stdin <stdin &&
742 git rev-parse "$m:$pws" >expect &&
743 git rev-parse refs/blobs/pws >actual &&
744 test_cmp expect actual &&
745 git update-ref -d refs/blobs/pws
748 test_expect_success 'stdin update ref fails with wrong old value' '
749 echo "update $c $m $m~1" >stdin &&
750 test_must_fail git update-ref --stdin <stdin 2>err &&
751 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
752 test_must_fail git rev-parse --verify -q $c
755 test_expect_success 'stdin update ref fails with bad old value' '
756 echo "update $c $m does-not-exist" >stdin &&
757 test_must_fail git update-ref --stdin <stdin 2>err &&
758 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
759 test_must_fail git rev-parse --verify -q $c
762 test_expect_success 'stdin create ref fails with bad new value' '
763 echo "create $c does-not-exist" >stdin &&
764 test_must_fail git update-ref --stdin <stdin 2>err &&
765 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
766 test_must_fail git rev-parse --verify -q $c
769 test_expect_success 'stdin create ref fails with zero new value' '
770 echo "create $c " >stdin &&
771 test_must_fail git update-ref --stdin <stdin 2>err &&
772 grep "fatal: create $c: zero <newvalue>" err &&
773 test_must_fail git rev-parse --verify -q $c
776 test_expect_success 'stdin update ref works with right old value' '
777 echo "update $b $m~1 $m" >stdin &&
778 git update-ref --stdin <stdin &&
779 git rev-parse $m~1 >expect &&
780 git rev-parse $b >actual &&
781 test_cmp expect actual
784 test_expect_success 'stdin delete ref fails with wrong old value' '
785 echo "delete $a $m~1" >stdin &&
786 test_must_fail git update-ref --stdin <stdin 2>err &&
787 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
788 git rev-parse $m >expect &&
789 git rev-parse $a >actual &&
790 test_cmp expect actual
793 test_expect_success 'stdin delete ref fails with zero old value' '
794 echo "delete $a " >stdin &&
795 test_must_fail git update-ref --stdin <stdin 2>err &&
796 grep "fatal: delete $a: zero <oldvalue>" err &&
797 git rev-parse $m >expect &&
798 git rev-parse $a >actual &&
799 test_cmp expect actual
802 test_expect_success 'stdin update symref works option no-deref' '
803 git symbolic-ref TESTSYMREF $b &&
806 update TESTSYMREF $a $b
808 git update-ref --stdin <stdin &&
809 git rev-parse TESTSYMREF >expect &&
810 git rev-parse $a >actual &&
811 test_cmp expect actual &&
812 git rev-parse $m~1 >expect &&
813 git rev-parse $b >actual &&
814 test_cmp expect actual
817 test_expect_success 'stdin delete symref works option no-deref' '
818 git symbolic-ref TESTSYMREF $b &&
823 git update-ref --stdin <stdin &&
824 test_must_fail git rev-parse --verify -q TESTSYMREF &&
825 git rev-parse $m~1 >expect &&
826 git rev-parse $b >actual &&
827 test_cmp expect actual
830 test_expect_success 'stdin update symref works flag --no-deref' '
831 git symbolic-ref TESTSYMREFONE $b &&
832 git symbolic-ref TESTSYMREFTWO $b &&
834 update TESTSYMREFONE $a $b
835 update TESTSYMREFTWO $a $b
837 git update-ref --no-deref --stdin <stdin &&
838 git rev-parse TESTSYMREFONE TESTSYMREFTWO >expect &&
839 git rev-parse $a $a >actual &&
840 test_cmp expect actual &&
841 git rev-parse $m~1 >expect &&
842 git rev-parse $b >actual &&
843 test_cmp expect actual
846 test_expect_success 'stdin delete symref works flag --no-deref' '
847 git symbolic-ref TESTSYMREFONE $b &&
848 git symbolic-ref TESTSYMREFTWO $b &&
850 delete TESTSYMREFONE $b
851 delete TESTSYMREFTWO $b
853 git update-ref --no-deref --stdin <stdin &&
854 test_must_fail git rev-parse --verify -q TESTSYMREFONE &&
855 test_must_fail git rev-parse --verify -q TESTSYMREFTWO &&
856 git rev-parse $m~1 >expect &&
857 git rev-parse $b >actual &&
858 test_cmp expect actual
861 test_expect_success 'stdin delete ref works with right old value' '
862 echo "delete $b $m~1" >stdin &&
863 git update-ref --stdin <stdin &&
864 test_must_fail git rev-parse --verify -q $b
867 test_expect_success 'stdin update/create/verify combination works' '
873 git update-ref --stdin <stdin &&
874 git rev-parse $m >expect &&
875 git rev-parse $a >actual &&
876 test_cmp expect actual &&
877 git rev-parse $b >actual &&
878 test_cmp expect actual &&
879 test_must_fail git rev-parse --verify -q $c
882 test_expect_success 'stdin verify succeeds for correct value' '
883 git rev-parse $m >expect &&
884 echo "verify $m $m" >stdin &&
885 git update-ref --stdin <stdin &&
886 git rev-parse $m >actual &&
887 test_cmp expect actual
890 test_expect_success 'stdin verify succeeds for missing reference' '
891 echo "verify refs/heads/missing $Z" >stdin &&
892 git update-ref --stdin <stdin &&
893 test_must_fail git rev-parse --verify -q refs/heads/missing
896 test_expect_success 'stdin verify treats no value as missing' '
897 echo "verify refs/heads/missing" >stdin &&
898 git update-ref --stdin <stdin &&
899 test_must_fail git rev-parse --verify -q refs/heads/missing
902 test_expect_success 'stdin verify fails for wrong value' '
903 git rev-parse $m >expect &&
904 echo "verify $m $m~1" >stdin &&
905 test_must_fail git update-ref --stdin <stdin &&
906 git rev-parse $m >actual &&
907 test_cmp expect actual
910 test_expect_success 'stdin verify fails for mistaken null value' '
911 git rev-parse $m >expect &&
912 echo "verify $m $Z" >stdin &&
913 test_must_fail git update-ref --stdin <stdin &&
914 git rev-parse $m >actual &&
915 test_cmp expect actual
918 test_expect_success 'stdin verify fails for mistaken empty value' '
919 M=$(git rev-parse $m) &&
920 test_when_finished "git update-ref $m $M" &&
921 git rev-parse $m >expect &&
922 echo "verify $m" >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 update refs works with identity updates' '
934 git update-ref --stdin <stdin &&
935 git rev-parse $m >expect &&
936 git rev-parse $a >actual &&
937 test_cmp expect actual &&
938 git rev-parse $b >actual &&
939 test_cmp expect actual &&
940 test_must_fail git rev-parse --verify -q $c
943 test_expect_success 'stdin update refs fails with wrong old value' '
944 git update-ref $c $m &&
950 test_must_fail git update-ref --stdin <stdin 2>err &&
951 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
952 git rev-parse $m >expect &&
953 git rev-parse $a >actual &&
954 test_cmp expect actual &&
955 git rev-parse $b >actual &&
956 test_cmp expect actual &&
957 git rev-parse $c >actual &&
958 test_cmp expect actual
961 test_expect_success 'stdin delete refs works with packed and loose refs' '
962 git pack-refs --all &&
963 git update-ref $c $m~1 &&
969 git update-ref --stdin <stdin &&
970 test_must_fail git rev-parse --verify -q $a &&
971 test_must_fail git rev-parse --verify -q $b &&
972 test_must_fail git rev-parse --verify -q $c
975 test_expect_success 'stdin -z works on empty input' '
977 git update-ref -z --stdin <stdin &&
978 git rev-parse --verify -q $m
981 test_expect_success 'stdin -z fails on empty line' '
983 test_must_fail git update-ref -z --stdin <stdin 2>err &&
984 grep "fatal: whitespace before command: " err
987 test_expect_success 'stdin -z fails on empty command' '
988 printf $F "" >stdin &&
989 test_must_fail git update-ref -z --stdin <stdin 2>err &&
990 grep "fatal: empty command in input" err
993 test_expect_success 'stdin -z fails on only whitespace' '
994 printf $F " " >stdin &&
995 test_must_fail git update-ref -z --stdin <stdin 2>err &&
996 grep "fatal: whitespace before command: " err
999 test_expect_success 'stdin -z fails on leading whitespace' '
1000 printf $F " create $a" "$m" >stdin &&
1001 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1002 grep "fatal: whitespace before command: create $a" err
1005 test_expect_success 'stdin -z fails on unknown command' '
1006 printf $F "unknown $a" >stdin &&
1007 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1008 grep "fatal: unknown command: unknown $a" err
1011 test_expect_success 'stdin -z fails create with no ref' '
1012 printf $F "create " >stdin &&
1013 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1014 grep "fatal: create: missing <ref>" err
1017 test_expect_success 'stdin -z fails create with no new value' '
1018 printf $F "create $a" >stdin &&
1019 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1020 grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
1023 test_expect_success 'stdin -z fails create with too many arguments' '
1024 printf $F "create $a" "$m" "$m" >stdin &&
1025 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1026 grep "fatal: unknown command: $m" err
1029 test_expect_success 'stdin -z fails update with no ref' '
1030 printf $F "update " >stdin &&
1031 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1032 grep "fatal: update: missing <ref>" err
1035 test_expect_success 'stdin -z fails update with too few args' '
1036 printf $F "update $a" "$m" >stdin &&
1037 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1038 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
1041 test_expect_success 'stdin -z emits warning with empty new value' '
1042 git update-ref $a $m &&
1043 printf $F "update $a" "" "" >stdin &&
1044 git update-ref -z --stdin <stdin 2>err &&
1045 grep "warning: update $a: missing <newvalue>, treating as zero" err &&
1046 test_must_fail git rev-parse --verify -q $a
1049 test_expect_success 'stdin -z fails update with no new value' '
1050 printf $F "update $a" >stdin &&
1051 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1052 grep "fatal: update $a: unexpected end of input when reading <newvalue>" err
1055 test_expect_success 'stdin -z fails update with no old value' '
1056 printf $F "update $a" "$m" >stdin &&
1057 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1058 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
1061 test_expect_success 'stdin -z fails update with too many arguments' '
1062 printf $F "update $a" "$m" "$m" "$m" >stdin &&
1063 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1064 grep "fatal: unknown command: $m" err
1067 test_expect_success 'stdin -z fails delete with no ref' '
1068 printf $F "delete " >stdin &&
1069 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1070 grep "fatal: delete: missing <ref>" err
1073 test_expect_success 'stdin -z fails delete with no old value' '
1074 printf $F "delete $a" >stdin &&
1075 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1076 grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
1079 test_expect_success 'stdin -z fails delete with too many arguments' '
1080 printf $F "delete $a" "$m" "$m" >stdin &&
1081 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1082 grep "fatal: unknown command: $m" err
1085 test_expect_success 'stdin -z fails verify with too many arguments' '
1086 printf $F "verify $a" "$m" "$m" >stdin &&
1087 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1088 grep "fatal: unknown command: $m" err
1091 test_expect_success 'stdin -z fails verify with no old value' '
1092 printf $F "verify $a" >stdin &&
1093 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1094 grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err
1097 test_expect_success 'stdin -z fails option with unknown name' '
1098 printf $F "option unknown" >stdin &&
1099 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1100 grep "fatal: option unknown: unknown" err
1103 test_expect_success 'stdin -z fails with duplicate refs' '
1104 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
1105 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1106 test_i18ngrep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
1109 test_expect_success 'stdin -z create ref works' '
1110 printf $F "create $a" "$m" >stdin &&
1111 git update-ref -z --stdin <stdin &&
1112 git rev-parse $m >expect &&
1113 git rev-parse $a >actual &&
1114 test_cmp expect actual
1117 test_expect_success 'stdin -z update ref creates with zero old value' '
1118 printf $F "update $b" "$m" "$Z" >stdin &&
1119 git update-ref -z --stdin <stdin &&
1120 git rev-parse $m >expect &&
1121 git rev-parse $b >actual &&
1122 test_cmp expect actual &&
1123 git update-ref -d $b
1126 test_expect_success 'stdin -z update ref creates with empty old value' '
1127 printf $F "update $b" "$m" "" >stdin &&
1128 git update-ref -z --stdin <stdin &&
1129 git rev-parse $m >expect &&
1130 git rev-parse $b >actual &&
1131 test_cmp expect actual
1134 test_expect_success 'stdin -z create ref works with path with space to blob' '
1135 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
1136 git update-ref -z --stdin <stdin &&
1137 git rev-parse "$m:$pws" >expect &&
1138 git rev-parse refs/blobs/pws >actual &&
1139 test_cmp expect actual &&
1140 git update-ref -d refs/blobs/pws
1143 test_expect_success 'stdin -z update ref fails with wrong old value' '
1144 printf $F "update $c" "$m" "$m~1" >stdin &&
1145 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1146 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1147 test_must_fail git rev-parse --verify -q $c
1150 test_expect_success 'stdin -z update ref fails with bad old value' '
1151 printf $F "update $c" "$m" "does-not-exist" >stdin &&
1152 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1153 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
1154 test_must_fail git rev-parse --verify -q $c
1157 test_expect_success 'stdin -z create ref fails when ref exists' '
1158 git update-ref $c $m &&
1159 git rev-parse "$c" >expect &&
1160 printf $F "create $c" "$m~1" >stdin &&
1161 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1162 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1163 git rev-parse "$c" >actual &&
1164 test_cmp expect actual
1167 test_expect_success 'stdin -z create ref fails with bad new value' '
1168 git update-ref -d "$c" &&
1169 printf $F "create $c" "does-not-exist" >stdin &&
1170 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1171 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
1172 test_must_fail git rev-parse --verify -q $c
1175 test_expect_success 'stdin -z create ref fails with empty new value' '
1176 printf $F "create $c" "" >stdin &&
1177 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1178 grep "fatal: create $c: missing <newvalue>" err &&
1179 test_must_fail git rev-parse --verify -q $c
1182 test_expect_success 'stdin -z update ref works with right old value' '
1183 printf $F "update $b" "$m~1" "$m" >stdin &&
1184 git update-ref -z --stdin <stdin &&
1185 git rev-parse $m~1 >expect &&
1186 git rev-parse $b >actual &&
1187 test_cmp expect actual
1190 test_expect_success 'stdin -z delete ref fails with wrong old value' '
1191 printf $F "delete $a" "$m~1" >stdin &&
1192 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1193 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
1194 git rev-parse $m >expect &&
1195 git rev-parse $a >actual &&
1196 test_cmp expect actual
1199 test_expect_success 'stdin -z delete ref fails with zero old value' '
1200 printf $F "delete $a" "$Z" >stdin &&
1201 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1202 grep "fatal: delete $a: zero <oldvalue>" err &&
1203 git rev-parse $m >expect &&
1204 git rev-parse $a >actual &&
1205 test_cmp expect actual
1208 test_expect_success 'stdin -z update symref works option no-deref' '
1209 git symbolic-ref TESTSYMREF $b &&
1210 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
1211 git update-ref -z --stdin <stdin &&
1212 git rev-parse TESTSYMREF >expect &&
1213 git rev-parse $a >actual &&
1214 test_cmp expect actual &&
1215 git rev-parse $m~1 >expect &&
1216 git rev-parse $b >actual &&
1217 test_cmp expect actual
1220 test_expect_success 'stdin -z delete symref works option no-deref' '
1221 git symbolic-ref TESTSYMREF $b &&
1222 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
1223 git update-ref -z --stdin <stdin &&
1224 test_must_fail git rev-parse --verify -q TESTSYMREF &&
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 ref works with right old value' '
1231 printf $F "delete $b" "$m~1" >stdin &&
1232 git update-ref -z --stdin <stdin &&
1233 test_must_fail git rev-parse --verify -q $b
1236 test_expect_success 'stdin -z update/create/verify combination works' '
1237 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
1238 git update-ref -z --stdin <stdin &&
1239 git rev-parse $m >expect &&
1240 git rev-parse $a >actual &&
1241 test_cmp expect actual &&
1242 git rev-parse $b >actual &&
1243 test_cmp expect actual &&
1244 test_must_fail git rev-parse --verify -q $c
1247 test_expect_success 'stdin -z verify succeeds for correct value' '
1248 git rev-parse $m >expect &&
1249 printf $F "verify $m" "$m" >stdin &&
1250 git update-ref -z --stdin <stdin &&
1251 git rev-parse $m >actual &&
1252 test_cmp expect actual
1255 test_expect_success 'stdin -z verify succeeds for missing reference' '
1256 printf $F "verify refs/heads/missing" "$Z" >stdin &&
1257 git update-ref -z --stdin <stdin &&
1258 test_must_fail git rev-parse --verify -q refs/heads/missing
1261 test_expect_success 'stdin -z verify treats no value as missing' '
1262 printf $F "verify refs/heads/missing" "" >stdin &&
1263 git update-ref -z --stdin <stdin &&
1264 test_must_fail git rev-parse --verify -q refs/heads/missing
1267 test_expect_success 'stdin -z verify fails for wrong value' '
1268 git rev-parse $m >expect &&
1269 printf $F "verify $m" "$m~1" >stdin &&
1270 test_must_fail git update-ref -z --stdin <stdin &&
1271 git rev-parse $m >actual &&
1272 test_cmp expect actual
1275 test_expect_success 'stdin -z verify fails for mistaken null value' '
1276 git rev-parse $m >expect &&
1277 printf $F "verify $m" "$Z" >stdin &&
1278 test_must_fail git update-ref -z --stdin <stdin &&
1279 git rev-parse $m >actual &&
1280 test_cmp expect actual
1283 test_expect_success 'stdin -z verify fails for mistaken empty value' '
1284 M=$(git rev-parse $m) &&
1285 test_when_finished "git update-ref $m $M" &&
1286 git rev-parse $m >expect &&
1287 printf $F "verify $m" "" >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 update refs works with identity updates' '
1294 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
1295 git update-ref -z --stdin <stdin &&
1296 git rev-parse $m >expect &&
1297 git rev-parse $a >actual &&
1298 test_cmp expect actual &&
1299 git rev-parse $b >actual &&
1300 test_cmp expect actual &&
1301 test_must_fail git rev-parse --verify -q $c
1304 test_expect_success 'stdin -z update refs fails with wrong old value' '
1305 git update-ref $c $m &&
1306 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
1307 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1308 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1309 git rev-parse $m >expect &&
1310 git rev-parse $a >actual &&
1311 test_cmp expect actual &&
1312 git rev-parse $b >actual &&
1313 test_cmp expect actual &&
1314 git rev-parse $c >actual &&
1315 test_cmp expect actual
1318 test_expect_success 'stdin -z delete refs works with packed and loose refs' '
1319 git pack-refs --all &&
1320 git update-ref $c $m~1 &&
1321 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
1322 git update-ref -z --stdin <stdin &&
1323 test_must_fail git rev-parse --verify -q $a &&
1324 test_must_fail git rev-parse --verify -q $b &&
1325 test_must_fail git rev-parse --verify -q $c
1328 test_expect_success 'fails with duplicate HEAD update' '
1329 git branch target1 $A &&
1330 git checkout target1 &&
1331 cat >stdin <<-EOF &&
1332 update refs/heads/target1 $C
1336 test_must_fail git update-ref --stdin <stdin 2>err &&
1337 test_i18ngrep "fatal: multiple updates for '\''HEAD'\'' (including one via its referent .refs/heads/target1.) are not allowed" err &&
1338 echo "refs/heads/target1" >expect &&
1339 git symbolic-ref HEAD >actual &&
1340 test_cmp expect actual &&
1341 echo "$A" >expect &&
1342 git rev-parse refs/heads/target1 >actual &&
1343 test_cmp expect actual
1346 test_expect_success 'fails with duplicate ref update via symref' '
1347 git branch target2 $A &&
1348 git symbolic-ref refs/heads/symref2 refs/heads/target2 &&
1349 cat >stdin <<-EOF &&
1350 update refs/heads/target2 $C
1351 update refs/heads/symref2 $B
1353 test_must_fail git update-ref --stdin <stdin 2>err &&
1354 test_i18ngrep "fatal: multiple updates for '\''refs/heads/target2'\'' (including one via symref .refs/heads/symref2.) are not allowed" err &&
1355 echo "refs/heads/target2" >expect &&
1356 git symbolic-ref refs/heads/symref2 >actual &&
1357 test_cmp expect actual &&
1358 echo "$A" >expect &&
1359 git rev-parse refs/heads/target2 >actual &&
1360 test_cmp expect actual
1363 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' '
1365 for i in $(test_seq 33)
1367 echo "create refs/heads/$i HEAD"
1368 done >large_input &&
1369 run_with_limited_open_files git update-ref --stdin <large_input &&
1370 git rev-parse --verify -q refs/heads/33
1374 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches does not burst open file limit' '
1376 for i in $(test_seq 33)
1378 echo "delete refs/heads/$i HEAD"
1379 done >large_input &&
1380 run_with_limited_open_files git update-ref --stdin <large_input &&
1381 test_must_fail git rev-parse --verify -q refs/heads/33
1385 test_expect_success 'handle per-worktree refs in refs/bisect' '
1386 git commit --allow-empty -m "initial commit" &&
1387 git worktree add -b branch worktree &&
1390 git commit --allow-empty -m "test commit" &&
1391 git for-each-ref >for-each-ref.out &&
1392 ! grep refs/bisect for-each-ref.out &&
1393 git update-ref refs/bisect/something HEAD &&
1394 git rev-parse refs/bisect/something >../worktree-head &&
1395 git for-each-ref | grep refs/bisect/something
1397 git show-ref >actual &&
1398 ! grep 'refs/bisect' actual &&
1399 test_must_fail git rev-parse refs/bisect/something &&
1400 git update-ref refs/bisect/something HEAD &&
1401 git rev-parse refs/bisect/something >main-head &&
1402 ! test_cmp main-head worktree-head
1405 test_expect_success 'transaction handles empty commit' '
1406 cat >stdin <<-EOF &&
1411 git update-ref --stdin <stdin >actual &&
1412 printf "%s: ok\n" start prepare commit >expect &&
1413 test_cmp expect actual
1416 test_expect_success 'transaction handles empty commit with missing prepare' '
1417 cat >stdin <<-EOF &&
1421 git update-ref --stdin <stdin >actual &&
1422 printf "%s: ok\n" start commit >expect &&
1423 test_cmp expect actual
1426 test_expect_success 'transaction handles sole commit' '
1427 cat >stdin <<-EOF &&
1430 git update-ref --stdin <stdin >actual &&
1431 printf "%s: ok\n" commit >expect &&
1432 test_cmp expect actual
1435 test_expect_success 'transaction handles empty abort' '
1436 cat >stdin <<-EOF &&
1441 git update-ref --stdin <stdin >actual &&
1442 printf "%s: ok\n" start prepare abort >expect &&
1443 test_cmp expect actual
1446 test_expect_success 'transaction exits on multiple aborts' '
1447 cat >stdin <<-EOF &&
1451 test_must_fail git update-ref --stdin <stdin >actual 2>err &&
1452 printf "%s: ok\n" abort >expect &&
1453 test_cmp expect actual &&
1454 grep "fatal: transaction is closed" err
1457 test_expect_success 'transaction exits on start after prepare' '
1458 cat >stdin <<-EOF &&
1462 test_must_fail git update-ref --stdin <stdin 2>err >actual &&
1463 printf "%s: ok\n" prepare >expect &&
1464 test_cmp expect actual &&
1465 grep "fatal: prepared transactions can only be closed" err
1468 test_expect_success 'transaction handles empty abort with missing prepare' '
1469 cat >stdin <<-EOF &&
1473 git update-ref --stdin <stdin >actual &&
1474 printf "%s: ok\n" start abort >expect &&
1475 test_cmp expect actual
1478 test_expect_success 'transaction handles sole abort' '
1479 cat >stdin <<-EOF &&
1482 git update-ref --stdin <stdin >actual &&
1483 printf "%s: ok\n" abort >expect &&
1484 test_cmp expect actual
1487 test_expect_success 'transaction can handle commit' '
1488 cat >stdin <<-EOF &&
1493 git update-ref --stdin <stdin >actual &&
1494 printf "%s: ok\n" start commit >expect &&
1495 test_cmp expect actual &&
1496 git rev-parse HEAD >expect &&
1497 git rev-parse $a >actual &&
1498 test_cmp expect actual
1501 test_expect_success 'transaction can handle abort' '
1502 cat >stdin <<-EOF &&
1507 git update-ref --stdin <stdin >actual &&
1508 printf "%s: ok\n" start abort >expect &&
1509 test_cmp expect actual &&
1510 test_must_fail git show-ref --verify -q $b
1513 test_expect_success 'transaction aborts by default' '
1514 cat >stdin <<-EOF &&
1518 git update-ref --stdin <stdin >actual &&
1519 printf "%s: ok\n" start >expect &&
1520 test_cmp expect actual &&
1521 test_must_fail git show-ref --verify -q $b
1524 test_expect_success 'transaction with prepare aborts by default' '
1525 cat >stdin <<-EOF &&
1530 git update-ref --stdin <stdin >actual &&
1531 printf "%s: ok\n" start prepare >expect &&
1532 test_cmp expect actual &&
1533 test_must_fail git show-ref --verify -q $b
1536 test_expect_success 'transaction can commit multiple times' '
1537 cat >stdin <<-EOF &&
1539 create refs/heads/branch-1 $A
1542 create refs/heads/branch-2 $B
1545 git update-ref --stdin <stdin >actual &&
1546 printf "%s: ok\n" start commit start commit >expect &&
1547 test_cmp expect actual &&
1548 echo "$A" >expect &&
1549 git rev-parse refs/heads/branch-1 >actual &&
1550 test_cmp expect actual &&
1551 echo "$B" >expect &&
1552 git rev-parse refs/heads/branch-2 >actual &&
1553 test_cmp expect actual
1556 test_expect_success 'transaction can create and delete' '
1557 cat >stdin <<-EOF &&
1559 create refs/heads/create-and-delete $A
1562 delete refs/heads/create-and-delete $A
1565 git update-ref --stdin <stdin >actual &&
1566 printf "%s: ok\n" start commit start commit >expect &&
1567 test_must_fail git show-ref --verify refs/heads/create-and-delete
1570 test_expect_success 'transaction can commit after abort' '
1571 cat >stdin <<-EOF &&
1573 create refs/heads/abort $A
1576 create refs/heads/abort $A
1579 git update-ref --stdin <stdin >actual &&
1580 printf "%s: ok\n" start abort start commit >expect &&
1581 echo "$A" >expect &&
1582 git rev-parse refs/heads/abort >actual &&
1583 test_cmp expect actual
1586 test_expect_success 'transaction cannot restart ongoing transaction' '
1587 cat >stdin <<-EOF &&
1589 create refs/heads/restart $A
1593 test_must_fail git update-ref --stdin <stdin >actual &&
1594 test_must_fail git show-ref --verify refs/heads/restart