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 git checkout --orphan main &&
31 create_test_commits "" &&
34 git init --bare -b main &&
35 create_test_commits "bare" &&
39 test_expect_success "create $m" '
40 git update-ref $m $A &&
41 test $A = $(git show-ref -s --verify $m)
43 test_expect_success "create $m with oldvalue verification" '
44 git update-ref $m $B $A &&
45 test $B = $(git show-ref -s --verify $m)
47 test_expect_success "fail to delete $m with stale ref" '
48 test_must_fail git update-ref -d $m $A &&
49 test $B = "$(git show-ref -s --verify $m)"
51 test_expect_success "delete $m" '
52 test_when_finished "git update-ref -d $m" &&
53 git update-ref -d $m $B &&
54 test_must_fail git show-ref --verify -q $m
57 test_expect_success "delete $m without oldvalue verification" '
58 test_when_finished "git update-ref -d $m" &&
59 git update-ref $m $A &&
60 test $A = $(git show-ref -s --verify $m) &&
61 git update-ref -d $m &&
62 test_must_fail git show-ref --verify -q $m
65 test_expect_success "fail to create $n" '
66 test_when_finished "rm -f .git/$n_dir" &&
68 test_must_fail git update-ref $n $A
71 test_expect_success "create $m (by HEAD)" '
72 git update-ref HEAD $A &&
73 test $A = $(git show-ref -s --verify $m)
75 test_expect_success "create $m (by HEAD) with oldvalue verification" '
76 git update-ref HEAD $B $A &&
77 test $B = $(git show-ref -s --verify $m)
79 test_expect_success "fail to delete $m (by HEAD) with stale ref" '
80 test_must_fail git update-ref -d HEAD $A &&
81 test $B = $(git show-ref -s --verify $m)
83 test_expect_success "delete $m (by HEAD)" '
84 test_when_finished "git update-ref -d $m" &&
85 git update-ref -d HEAD $B &&
86 test_must_fail git show-ref --verify -q $m
89 test_expect_success "deleting current branch adds message to HEAD's log" '
90 test_when_finished "git update-ref -d $m" &&
91 git update-ref $m $A &&
92 git symbolic-ref HEAD $m &&
93 git update-ref -m delete-$m -d $m &&
94 test_must_fail git show-ref --verify -q $m &&
95 grep "delete-$m$" .git/logs/HEAD
98 test_expect_success "deleting by HEAD adds message to HEAD's log" '
99 test_when_finished "git update-ref -d $m" &&
100 git update-ref $m $A &&
101 git symbolic-ref HEAD $m &&
102 git update-ref -m delete-by-head -d HEAD &&
103 test_must_fail git show-ref --verify -q $m &&
104 grep "delete-by-head$" .git/logs/HEAD
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 && \
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' '
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" &&
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" &&
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 git symbolic-ref refs/heads/self refs/heads/self &&
225 test_when_finished "rm -f .git/refs/heads/self" &&
226 test_path_is_file .git/refs/heads/self &&
227 test_must_fail git update-ref -d refs/heads/self &&
228 test_path_is_file .git/refs/heads/self
231 test_expect_success 'update-ref --no-deref -d can delete self-reference' '
232 git symbolic-ref refs/heads/self refs/heads/self &&
233 test_when_finished "rm -f .git/refs/heads/self" &&
234 test_path_is_file .git/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 '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 test_path_is_file .git/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 rm -f .git/logs/refs/heads/main
269 test_expect_success "create $m (logged by touch)" '
270 test_config core.logAllRefUpdates false &&
271 GIT_COMMITTER_DATE="2005-05-26 23:30" \
272 git update-ref --create-reflog HEAD $A -m "Initial Creation" &&
273 test $A = $(git show-ref -s --verify $m)
275 test_expect_success "update $m (logged by touch)" '
276 test_config core.logAllRefUpdates false &&
277 GIT_COMMITTER_DATE="2005-05-26 23:31" \
278 git update-ref HEAD $B $A -m "Switch" &&
279 test $B = $(git show-ref -s --verify $m)
281 test_expect_success "set $m (logged by touch)" '
282 test_config core.logAllRefUpdates false &&
283 GIT_COMMITTER_DATE="2005-05-26 23:41" \
284 git update-ref HEAD $A &&
285 test $A = $(git show-ref -s --verify $m)
288 test_expect_success 'empty directory removal' '
289 git branch d1/d2/r1 HEAD &&
290 git branch d1/r2 HEAD &&
291 test_path_is_file .git/refs/heads/d1/d2/r1 &&
292 test_path_is_file .git/logs/refs/heads/d1/d2/r1 &&
293 git branch -d d1/d2/r1 &&
294 test_must_fail git show-ref --verify -q refs/heads/d1/d2 &&
295 test_must_fail git show-ref --verify -q logs/refs/heads/d1/d2 &&
296 test_path_is_file .git/refs/heads/d1/r2 &&
297 test_path_is_file .git/logs/refs/heads/d1/r2
300 test_expect_success 'symref empty directory removal' '
301 git branch e1/e2/r1 HEAD &&
302 git branch e1/r2 HEAD &&
303 git checkout e1/e2/r1 &&
304 test_when_finished "git checkout main" &&
305 test_path_is_file .git/refs/heads/e1/e2/r1 &&
306 test_path_is_file .git/logs/refs/heads/e1/e2/r1 &&
307 git update-ref -d HEAD &&
308 test_must_fail git show-ref --verify -q refs/heads/e1/e2 &&
309 test_must_fail git show-ref --verify -q logs/refs/heads/e1/e2 &&
310 test_path_is_file .git/refs/heads/e1/r2 &&
311 test_path_is_file .git/logs/refs/heads/e1/r2 &&
312 test_path_is_file .git/logs/HEAD
316 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
317 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
318 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
320 test_expect_success "verifying $m's log (logged by touch)" '
321 test_when_finished "rm -rf .git/$m .git/logs expect" &&
322 test_cmp expect .git/logs/$m
325 test_expect_success "create $m (logged by config)" '
326 test_config core.logAllRefUpdates true &&
327 GIT_COMMITTER_DATE="2005-05-26 23:32" \
328 git update-ref HEAD $A -m "Initial Creation" &&
329 test $A = $(git show-ref -s --verify $m)
331 test_expect_success "update $m (logged by config)" '
332 test_config core.logAllRefUpdates true &&
333 GIT_COMMITTER_DATE="2005-05-26 23:33" \
334 git update-ref HEAD $B $A -m "Switch" &&
335 test $B = $(git show-ref -s --verify $m)
337 test_expect_success "set $m (logged by config)" '
338 test_config core.logAllRefUpdates true &&
339 GIT_COMMITTER_DATE="2005-05-26 23:43" \
340 git update-ref HEAD $A &&
341 test $A = $(git show-ref -s --verify $m)
345 $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
346 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
347 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
349 test_expect_success "verifying $m's log (logged by config)" '
350 test_when_finished "rm -f .git/$m .git/logs/$m expect" &&
351 test_cmp expect .git/logs/$m
354 test_expect_success 'set up for querying the reflog' '
355 git update-ref $m $D &&
356 cat >.git/logs/$m <<-EOF
357 $Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
358 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
359 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
360 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
361 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
365 ed="Thu, 26 May 2005 18:32:00 -0500"
366 gd="Thu, 26 May 2005 18:33:00 -0500"
367 ld="Thu, 26 May 2005 18:43:00 -0500"
368 test_expect_success 'Query "main@{May 25 2005}" (before history)' '
369 test_when_finished "rm -f o e" &&
370 git rev-parse --verify "main@{May 25 2005}" >o 2>e &&
373 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
374 test_i18ncmp expect e
376 test_expect_success 'Query main@{2005-05-25} (before history)' '
377 test_when_finished "rm -f o e" &&
378 git rev-parse --verify main@{2005-05-25} >o 2>e &&
381 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
382 test_i18ncmp expect e
384 test_expect_success 'Query "main@{May 26 2005 23:31:59}" (1 second before history)' '
385 test_when_finished "rm -f o e" &&
386 git rev-parse --verify "main@{May 26 2005 23:31:59}" >o 2>e &&
389 echo "warning: log for '\''main'\'' only goes back to $ed" >expect &&
390 test_i18ncmp expect e
392 test_expect_success 'Query "main@{May 26 2005 23:32:00}" (exactly history start)' '
393 test_when_finished "rm -f o e" &&
394 git rev-parse --verify "main@{May 26 2005 23:32:00}" >o 2>e &&
399 test_expect_success 'Query "main@{May 26 2005 23:32:30}" (first non-creation change)' '
400 test_when_finished "rm -f o e" &&
401 git rev-parse --verify "main@{May 26 2005 23:32:30}" >o 2>e &&
406 test_expect_success 'Query "main@{2005-05-26 23:33:01}" (middle of history with gap)' '
407 test_when_finished "rm -f o e" &&
408 git rev-parse --verify "main@{2005-05-26 23:33:01}" >o 2>e &&
411 test_i18ngrep -F "warning: log for ref $m has gap after $gd" e
413 test_expect_success 'Query "main@{2005-05-26 23:38:00}" (middle of history)' '
414 test_when_finished "rm -f o e" &&
415 git rev-parse --verify "main@{2005-05-26 23:38:00}" >o 2>e &&
420 test_expect_success 'Query "main@{2005-05-26 23:43:00}" (exact end of history)' '
421 test_when_finished "rm -f o e" &&
422 git rev-parse --verify "main@{2005-05-26 23:43:00}" >o 2>e &&
427 test_expect_success 'Query "main@{2005-05-28}" (past end of history)' '
428 test_when_finished "rm -f o e" &&
429 git rev-parse --verify "main@{2005-05-28}" >o 2>e &&
432 test_i18ngrep -F "warning: log for ref $m unexpectedly ended on $ld" e
435 rm -f .git/$m .git/logs/$m expect
437 test_expect_success 'creating initial files' '
438 test_when_finished rm -f M &&
441 GIT_AUTHOR_DATE="2005-05-26 23:30" \
442 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
443 h_TEST=$(git rev-parse --verify HEAD) &&
444 echo The other day this did not work. >M &&
445 echo And then Bob told me how to fix it. >>M &&
447 GIT_AUTHOR_DATE="2005-05-26 23:41" \
448 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
449 h_OTHER=$(git rev-parse --verify HEAD) &&
450 GIT_AUTHOR_DATE="2005-05-26 23:44" \
451 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
452 h_FIXED=$(git rev-parse --verify HEAD) &&
453 echo Merged initial commit and a later commit. >M &&
454 echo $h_TEST >.git/MERGE_HEAD &&
455 GIT_AUTHOR_DATE="2005-05-26 23:45" \
456 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
457 h_MERGED=$(git rev-parse --verify HEAD)
461 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
462 $h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
463 $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
464 $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
466 test_expect_success 'git commit logged updates' '
467 test_cmp expect .git/logs/$m
469 unset h_TEST h_OTHER h_FIXED h_MERGED
471 test_expect_success 'git cat-file blob main:F (expect OTHER)' '
472 test OTHER = $(git cat-file blob main:F)
474 test_expect_success 'git cat-file blob main@{2005-05-26 23:30}:F (expect TEST)' '
475 test TEST = $(git cat-file blob "main@{2005-05-26 23:30}:F")
477 test_expect_success 'git cat-file blob main@{2005-05-26 23:42}:F (expect OTHER)' '
478 test OTHER = $(git cat-file blob "main@{2005-05-26 23:42}:F")
481 # Test adding and deleting pseudorefs
483 test_expect_success 'given old value for missing pseudoref, do not create' '
484 test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
485 test_must_fail git rev-parse PSEUDOREF &&
486 test_i18ngrep "unable to resolve reference" err
489 test_expect_success 'create pseudoref' '
490 git update-ref PSEUDOREF $A &&
491 test $A = $(git rev-parse PSEUDOREF)
494 test_expect_success 'overwrite pseudoref with no old value given' '
495 git update-ref PSEUDOREF $B &&
496 test $B = $(git rev-parse PSEUDOREF)
499 test_expect_success 'overwrite pseudoref with correct old value' '
500 git update-ref PSEUDOREF $C $B &&
501 test $C = $(git rev-parse PSEUDOREF)
504 test_expect_success 'do not overwrite pseudoref with wrong old value' '
505 test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
506 test $C = $(git rev-parse PSEUDOREF) &&
507 test_i18ngrep "cannot lock ref.*expected" err
510 test_expect_success 'delete pseudoref' '
511 git update-ref -d PSEUDOREF &&
512 test_must_fail git rev-parse PSEUDOREF
515 test_expect_success 'do not delete pseudoref with wrong old value' '
516 git update-ref PSEUDOREF $A &&
517 test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
518 test $A = $(git rev-parse PSEUDOREF) &&
519 test_i18ngrep "cannot lock ref.*expected" err
522 test_expect_success 'delete pseudoref with correct old value' '
523 git update-ref -d PSEUDOREF $A &&
524 test_must_fail git rev-parse PSEUDOREF
527 test_expect_success 'create pseudoref with old OID zero' '
528 git update-ref PSEUDOREF $A $Z &&
529 test $A = $(git rev-parse PSEUDOREF)
532 test_expect_success 'do not overwrite pseudoref with old OID zero' '
533 test_when_finished git update-ref -d PSEUDOREF &&
534 test_must_fail git update-ref PSEUDOREF $B $Z 2>err &&
535 test $A = $(git rev-parse PSEUDOREF) &&
536 test_i18ngrep "already exists" err
546 pws='path with space'
548 test_expect_success 'stdin test setup' '
549 echo "$pws" >"$pws" &&
554 test_expect_success '-z fails without --stdin' '
555 test_must_fail git update-ref -z $m $m $m 2>err &&
556 test_i18ngrep "usage: git update-ref" err
559 test_expect_success 'stdin works with no input' '
561 git update-ref --stdin <stdin &&
562 git rev-parse --verify -q $m
565 test_expect_success 'stdin fails on empty line' '
567 test_must_fail git update-ref --stdin <stdin 2>err &&
568 grep "fatal: empty command in input" err
571 test_expect_success 'stdin fails on only whitespace' '
573 test_must_fail git update-ref --stdin <stdin 2>err &&
574 grep "fatal: whitespace before command: " err
577 test_expect_success 'stdin fails on leading whitespace' '
578 echo " create $a $m" >stdin &&
579 test_must_fail git update-ref --stdin <stdin 2>err &&
580 grep "fatal: whitespace before command: create $a $m" err
583 test_expect_success 'stdin fails on unknown command' '
584 echo "unknown $a" >stdin &&
585 test_must_fail git update-ref --stdin <stdin 2>err &&
586 grep "fatal: unknown command: unknown $a" err
589 test_expect_success 'stdin fails on unbalanced quotes' '
590 echo "create $a \"main" >stdin &&
591 test_must_fail git update-ref --stdin <stdin 2>err &&
592 grep "fatal: badly quoted argument: \\\"main" err
595 test_expect_success 'stdin fails on invalid escape' '
596 echo "create $a \"ma\zn\"" >stdin &&
597 test_must_fail git update-ref --stdin <stdin 2>err &&
598 grep "fatal: badly quoted argument: \\\"ma\\\\zn\\\"" err
601 test_expect_success 'stdin fails on junk after quoted argument' '
602 echo "create \"$a\"main" >stdin &&
603 test_must_fail git update-ref --stdin <stdin 2>err &&
604 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"main" err
607 test_expect_success 'stdin fails create with no ref' '
608 echo "create " >stdin &&
609 test_must_fail git update-ref --stdin <stdin 2>err &&
610 grep "fatal: create: missing <ref>" err
613 test_expect_success 'stdin fails create with no new value' '
614 echo "create $a" >stdin &&
615 test_must_fail git update-ref --stdin <stdin 2>err &&
616 grep "fatal: create $a: missing <newvalue>" err
619 test_expect_success 'stdin fails create with too many arguments' '
620 echo "create $a $m $m" >stdin &&
621 test_must_fail git update-ref --stdin <stdin 2>err &&
622 grep "fatal: create $a: extra input: $m" err
625 test_expect_success 'stdin fails update with no ref' '
626 echo "update " >stdin &&
627 test_must_fail git update-ref --stdin <stdin 2>err &&
628 grep "fatal: update: missing <ref>" err
631 test_expect_success 'stdin fails update with no new value' '
632 echo "update $a" >stdin &&
633 test_must_fail git update-ref --stdin <stdin 2>err &&
634 grep "fatal: update $a: missing <newvalue>" err
637 test_expect_success 'stdin fails update with too many arguments' '
638 echo "update $a $m $m $m" >stdin &&
639 test_must_fail git update-ref --stdin <stdin 2>err &&
640 grep "fatal: update $a: extra input: $m" err
643 test_expect_success 'stdin fails delete with no ref' '
644 echo "delete " >stdin &&
645 test_must_fail git update-ref --stdin <stdin 2>err &&
646 grep "fatal: delete: missing <ref>" err
649 test_expect_success 'stdin fails delete with too many arguments' '
650 echo "delete $a $m $m" >stdin &&
651 test_must_fail git update-ref --stdin <stdin 2>err &&
652 grep "fatal: delete $a: extra input: $m" err
655 test_expect_success 'stdin fails verify with too many arguments' '
656 echo "verify $a $m $m" >stdin &&
657 test_must_fail git update-ref --stdin <stdin 2>err &&
658 grep "fatal: verify $a: extra input: $m" err
661 test_expect_success 'stdin fails option with unknown name' '
662 echo "option unknown" >stdin &&
663 test_must_fail git update-ref --stdin <stdin 2>err &&
664 grep "fatal: option unknown: unknown" err
667 test_expect_success 'stdin fails with duplicate refs' '
673 test_must_fail git update-ref --stdin <stdin 2>err &&
674 test_i18ngrep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
677 test_expect_success 'stdin create ref works' '
678 echo "create $a $m" >stdin &&
679 git update-ref --stdin <stdin &&
680 git rev-parse $m >expect &&
681 git rev-parse $a >actual &&
682 test_cmp expect actual
685 test_expect_success 'stdin does not create reflogs by default' '
686 test_when_finished "git update-ref -d $outside" &&
687 echo "create $outside $m" >stdin &&
688 git update-ref --stdin <stdin &&
689 git rev-parse $m >expect &&
690 git rev-parse $outside >actual &&
691 test_cmp expect actual &&
692 test_must_fail git reflog exists $outside
695 test_expect_success 'stdin creates reflogs with --create-reflog' '
696 test_when_finished "git update-ref -d $outside" &&
697 echo "create $outside $m" >stdin &&
698 git update-ref --create-reflog --stdin <stdin &&
699 git rev-parse $m >expect &&
700 git rev-parse $outside >actual &&
701 test_cmp expect actual &&
702 git reflog exists $outside
705 test_expect_success 'stdin succeeds with quoted argument' '
706 git update-ref -d $a &&
707 echo "create $a \"$m\"" >stdin &&
708 git update-ref --stdin <stdin &&
709 git rev-parse $m >expect &&
710 git rev-parse $a >actual &&
711 test_cmp expect actual
714 test_expect_success 'stdin succeeds with escaped character' '
715 git update-ref -d $a &&
716 echo "create $a \"ma\\151n\"" >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 update ref creates with zero old value' '
724 echo "update $b $m $Z" >stdin &&
725 git update-ref --stdin <stdin &&
726 git rev-parse $m >expect &&
727 git rev-parse $b >actual &&
728 test_cmp expect actual &&
732 test_expect_success 'stdin update ref creates with empty old value' '
733 echo "update $b $m $E" >stdin &&
734 git update-ref --stdin <stdin &&
735 git rev-parse $m >expect &&
736 git rev-parse $b >actual &&
737 test_cmp expect actual
740 test_expect_success 'stdin create ref works with path with space to blob' '
741 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
742 git update-ref --stdin <stdin &&
743 git rev-parse "$m:$pws" >expect &&
744 git rev-parse refs/blobs/pws >actual &&
745 test_cmp expect actual &&
746 git update-ref -d refs/blobs/pws
749 test_expect_success 'stdin update ref fails with wrong old value' '
750 echo "update $c $m $m~1" >stdin &&
751 test_must_fail git update-ref --stdin <stdin 2>err &&
752 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
753 test_must_fail git rev-parse --verify -q $c
756 test_expect_success 'stdin update ref fails with bad old value' '
757 echo "update $c $m does-not-exist" >stdin &&
758 test_must_fail git update-ref --stdin <stdin 2>err &&
759 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
760 test_must_fail git rev-parse --verify -q $c
763 test_expect_success 'stdin create ref fails with bad new value' '
764 echo "create $c does-not-exist" >stdin &&
765 test_must_fail git update-ref --stdin <stdin 2>err &&
766 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
767 test_must_fail git rev-parse --verify -q $c
770 test_expect_success 'stdin create ref fails with zero new value' '
771 echo "create $c " >stdin &&
772 test_must_fail git update-ref --stdin <stdin 2>err &&
773 grep "fatal: create $c: zero <newvalue>" err &&
774 test_must_fail git rev-parse --verify -q $c
777 test_expect_success 'stdin update ref works with right old value' '
778 echo "update $b $m~1 $m" >stdin &&
779 git update-ref --stdin <stdin &&
780 git rev-parse $m~1 >expect &&
781 git rev-parse $b >actual &&
782 test_cmp expect actual
785 test_expect_success 'stdin delete ref fails with wrong old value' '
786 echo "delete $a $m~1" >stdin &&
787 test_must_fail git update-ref --stdin <stdin 2>err &&
788 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
789 git rev-parse $m >expect &&
790 git rev-parse $a >actual &&
791 test_cmp expect actual
794 test_expect_success 'stdin delete ref fails with zero old value' '
795 echo "delete $a " >stdin &&
796 test_must_fail git update-ref --stdin <stdin 2>err &&
797 grep "fatal: delete $a: zero <oldvalue>" err &&
798 git rev-parse $m >expect &&
799 git rev-parse $a >actual &&
800 test_cmp expect actual
803 test_expect_success 'stdin update symref works option no-deref' '
804 git symbolic-ref TESTSYMREF $b &&
807 update TESTSYMREF $a $b
809 git update-ref --stdin <stdin &&
810 git rev-parse TESTSYMREF >expect &&
811 git rev-parse $a >actual &&
812 test_cmp expect actual &&
813 git rev-parse $m~1 >expect &&
814 git rev-parse $b >actual &&
815 test_cmp expect actual
818 test_expect_success 'stdin delete symref works option no-deref' '
819 git symbolic-ref TESTSYMREF $b &&
824 git update-ref --stdin <stdin &&
825 test_must_fail git rev-parse --verify -q TESTSYMREF &&
826 git rev-parse $m~1 >expect &&
827 git rev-parse $b >actual &&
828 test_cmp expect actual
831 test_expect_success 'stdin update symref works flag --no-deref' '
832 git symbolic-ref TESTSYMREFONE $b &&
833 git symbolic-ref TESTSYMREFTWO $b &&
835 update TESTSYMREFONE $a $b
836 update TESTSYMREFTWO $a $b
838 git update-ref --no-deref --stdin <stdin &&
839 git rev-parse TESTSYMREFONE TESTSYMREFTWO >expect &&
840 git rev-parse $a $a >actual &&
841 test_cmp expect actual &&
842 git rev-parse $m~1 >expect &&
843 git rev-parse $b >actual &&
844 test_cmp expect actual
847 test_expect_success 'stdin delete symref works flag --no-deref' '
848 git symbolic-ref TESTSYMREFONE $b &&
849 git symbolic-ref TESTSYMREFTWO $b &&
851 delete TESTSYMREFONE $b
852 delete TESTSYMREFTWO $b
854 git update-ref --no-deref --stdin <stdin &&
855 test_must_fail git rev-parse --verify -q TESTSYMREFONE &&
856 test_must_fail git rev-parse --verify -q TESTSYMREFTWO &&
857 git rev-parse $m~1 >expect &&
858 git rev-parse $b >actual &&
859 test_cmp expect actual
862 test_expect_success 'stdin delete ref works with right old value' '
863 echo "delete $b $m~1" >stdin &&
864 git update-ref --stdin <stdin &&
865 test_must_fail git rev-parse --verify -q $b
868 test_expect_success 'stdin update/create/verify combination works' '
874 git update-ref --stdin <stdin &&
875 git rev-parse $m >expect &&
876 git rev-parse $a >actual &&
877 test_cmp expect actual &&
878 git rev-parse $b >actual &&
879 test_cmp expect actual &&
880 test_must_fail git rev-parse --verify -q $c
883 test_expect_success 'stdin verify succeeds for correct value' '
884 git rev-parse $m >expect &&
885 echo "verify $m $m" >stdin &&
886 git update-ref --stdin <stdin &&
887 git rev-parse $m >actual &&
888 test_cmp expect actual
891 test_expect_success 'stdin verify succeeds for missing reference' '
892 echo "verify refs/heads/missing $Z" >stdin &&
893 git update-ref --stdin <stdin &&
894 test_must_fail git rev-parse --verify -q refs/heads/missing
897 test_expect_success 'stdin verify treats no value as missing' '
898 echo "verify refs/heads/missing" >stdin &&
899 git update-ref --stdin <stdin &&
900 test_must_fail git rev-parse --verify -q refs/heads/missing
903 test_expect_success 'stdin verify fails for wrong value' '
904 git rev-parse $m >expect &&
905 echo "verify $m $m~1" >stdin &&
906 test_must_fail git update-ref --stdin <stdin &&
907 git rev-parse $m >actual &&
908 test_cmp expect actual
911 test_expect_success 'stdin verify fails for mistaken null value' '
912 git rev-parse $m >expect &&
913 echo "verify $m $Z" >stdin &&
914 test_must_fail git update-ref --stdin <stdin &&
915 git rev-parse $m >actual &&
916 test_cmp expect actual
919 test_expect_success 'stdin verify fails for mistaken empty value' '
920 M=$(git rev-parse $m) &&
921 test_when_finished "git update-ref $m $M" &&
922 git rev-parse $m >expect &&
923 echo "verify $m" >stdin &&
924 test_must_fail git update-ref --stdin <stdin &&
925 git rev-parse $m >actual &&
926 test_cmp expect actual
929 test_expect_success 'stdin update refs works with identity updates' '
935 git update-ref --stdin <stdin &&
936 git rev-parse $m >expect &&
937 git rev-parse $a >actual &&
938 test_cmp expect actual &&
939 git rev-parse $b >actual &&
940 test_cmp expect actual &&
941 test_must_fail git rev-parse --verify -q $c
944 test_expect_success 'stdin update refs fails with wrong old value' '
945 git update-ref $c $m &&
951 test_must_fail git update-ref --stdin <stdin 2>err &&
952 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
953 git rev-parse $m >expect &&
954 git rev-parse $a >actual &&
955 test_cmp expect actual &&
956 git rev-parse $b >actual &&
957 test_cmp expect actual &&
958 git rev-parse $c >actual &&
959 test_cmp expect actual
962 test_expect_success 'stdin delete refs works with packed and loose refs' '
963 git pack-refs --all &&
964 git update-ref $c $m~1 &&
970 git update-ref --stdin <stdin &&
971 test_must_fail git rev-parse --verify -q $a &&
972 test_must_fail git rev-parse --verify -q $b &&
973 test_must_fail git rev-parse --verify -q $c
976 test_expect_success 'stdin -z works on empty input' '
978 git update-ref -z --stdin <stdin &&
979 git rev-parse --verify -q $m
982 test_expect_success 'stdin -z fails on empty line' '
984 test_must_fail git update-ref -z --stdin <stdin 2>err &&
985 grep "fatal: whitespace before command: " err
988 test_expect_success 'stdin -z fails on empty command' '
989 printf $F "" >stdin &&
990 test_must_fail git update-ref -z --stdin <stdin 2>err &&
991 grep "fatal: empty command in input" err
994 test_expect_success 'stdin -z fails on only whitespace' '
995 printf $F " " >stdin &&
996 test_must_fail git update-ref -z --stdin <stdin 2>err &&
997 grep "fatal: whitespace before command: " err
1000 test_expect_success 'stdin -z fails on leading whitespace' '
1001 printf $F " create $a" "$m" >stdin &&
1002 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1003 grep "fatal: whitespace before command: create $a" err
1006 test_expect_success 'stdin -z fails on unknown command' '
1007 printf $F "unknown $a" >stdin &&
1008 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1009 grep "fatal: unknown command: unknown $a" err
1012 test_expect_success 'stdin -z fails create with no ref' '
1013 printf $F "create " >stdin &&
1014 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1015 grep "fatal: create: missing <ref>" err
1018 test_expect_success 'stdin -z fails create with no new value' '
1019 printf $F "create $a" >stdin &&
1020 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1021 grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
1024 test_expect_success 'stdin -z fails create with too many arguments' '
1025 printf $F "create $a" "$m" "$m" >stdin &&
1026 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1027 grep "fatal: unknown command: $m" err
1030 test_expect_success 'stdin -z fails update with no ref' '
1031 printf $F "update " >stdin &&
1032 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1033 grep "fatal: update: missing <ref>" err
1036 test_expect_success 'stdin -z fails update with too few args' '
1037 printf $F "update $a" "$m" >stdin &&
1038 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1039 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
1042 test_expect_success 'stdin -z emits warning with empty new value' '
1043 git update-ref $a $m &&
1044 printf $F "update $a" "" "" >stdin &&
1045 git update-ref -z --stdin <stdin 2>err &&
1046 grep "warning: update $a: missing <newvalue>, treating as zero" err &&
1047 test_must_fail git rev-parse --verify -q $a
1050 test_expect_success 'stdin -z fails update with no new value' '
1051 printf $F "update $a" >stdin &&
1052 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1053 grep "fatal: update $a: unexpected end of input when reading <newvalue>" err
1056 test_expect_success 'stdin -z fails update with no old value' '
1057 printf $F "update $a" "$m" >stdin &&
1058 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1059 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
1062 test_expect_success 'stdin -z fails update with too many arguments' '
1063 printf $F "update $a" "$m" "$m" "$m" >stdin &&
1064 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1065 grep "fatal: unknown command: $m" err
1068 test_expect_success 'stdin -z fails delete with no ref' '
1069 printf $F "delete " >stdin &&
1070 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1071 grep "fatal: delete: missing <ref>" err
1074 test_expect_success 'stdin -z fails delete with no old value' '
1075 printf $F "delete $a" >stdin &&
1076 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1077 grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
1080 test_expect_success 'stdin -z fails delete with too many arguments' '
1081 printf $F "delete $a" "$m" "$m" >stdin &&
1082 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1083 grep "fatal: unknown command: $m" err
1086 test_expect_success 'stdin -z fails verify with too many arguments' '
1087 printf $F "verify $a" "$m" "$m" >stdin &&
1088 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1089 grep "fatal: unknown command: $m" err
1092 test_expect_success 'stdin -z fails verify with no old value' '
1093 printf $F "verify $a" >stdin &&
1094 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1095 grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err
1098 test_expect_success 'stdin -z fails option with unknown name' '
1099 printf $F "option unknown" >stdin &&
1100 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1101 grep "fatal: option unknown: unknown" err
1104 test_expect_success 'stdin -z fails with duplicate refs' '
1105 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
1106 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1107 test_i18ngrep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
1110 test_expect_success 'stdin -z create ref works' '
1111 printf $F "create $a" "$m" >stdin &&
1112 git update-ref -z --stdin <stdin &&
1113 git rev-parse $m >expect &&
1114 git rev-parse $a >actual &&
1115 test_cmp expect actual
1118 test_expect_success 'stdin -z update ref creates with zero old value' '
1119 printf $F "update $b" "$m" "$Z" >stdin &&
1120 git update-ref -z --stdin <stdin &&
1121 git rev-parse $m >expect &&
1122 git rev-parse $b >actual &&
1123 test_cmp expect actual &&
1124 git update-ref -d $b
1127 test_expect_success 'stdin -z update ref creates with empty old value' '
1128 printf $F "update $b" "$m" "" >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
1135 test_expect_success 'stdin -z create ref works with path with space to blob' '
1136 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
1137 git update-ref -z --stdin <stdin &&
1138 git rev-parse "$m:$pws" >expect &&
1139 git rev-parse refs/blobs/pws >actual &&
1140 test_cmp expect actual &&
1141 git update-ref -d refs/blobs/pws
1144 test_expect_success 'stdin -z update ref fails with wrong old value' '
1145 printf $F "update $c" "$m" "$m~1" >stdin &&
1146 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1147 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1148 test_must_fail git rev-parse --verify -q $c
1151 test_expect_success 'stdin -z update ref fails with bad old value' '
1152 printf $F "update $c" "$m" "does-not-exist" >stdin &&
1153 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1154 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
1155 test_must_fail git rev-parse --verify -q $c
1158 test_expect_success 'stdin -z create ref fails when ref exists' '
1159 git update-ref $c $m &&
1160 git rev-parse "$c" >expect &&
1161 printf $F "create $c" "$m~1" >stdin &&
1162 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1163 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1164 git rev-parse "$c" >actual &&
1165 test_cmp expect actual
1168 test_expect_success 'stdin -z create ref fails with bad new value' '
1169 git update-ref -d "$c" &&
1170 printf $F "create $c" "does-not-exist" >stdin &&
1171 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1172 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
1173 test_must_fail git rev-parse --verify -q $c
1176 test_expect_success 'stdin -z create ref fails with empty new value' '
1177 printf $F "create $c" "" >stdin &&
1178 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1179 grep "fatal: create $c: missing <newvalue>" err &&
1180 test_must_fail git rev-parse --verify -q $c
1183 test_expect_success 'stdin -z update ref works with right old value' '
1184 printf $F "update $b" "$m~1" "$m" >stdin &&
1185 git update-ref -z --stdin <stdin &&
1186 git rev-parse $m~1 >expect &&
1187 git rev-parse $b >actual &&
1188 test_cmp expect actual
1191 test_expect_success 'stdin -z delete ref fails with wrong old value' '
1192 printf $F "delete $a" "$m~1" >stdin &&
1193 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1194 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
1195 git rev-parse $m >expect &&
1196 git rev-parse $a >actual &&
1197 test_cmp expect actual
1200 test_expect_success 'stdin -z delete ref fails with zero old value' '
1201 printf $F "delete $a" "$Z" >stdin &&
1202 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1203 grep "fatal: delete $a: zero <oldvalue>" err &&
1204 git rev-parse $m >expect &&
1205 git rev-parse $a >actual &&
1206 test_cmp expect actual
1209 test_expect_success 'stdin -z update symref works option no-deref' '
1210 git symbolic-ref TESTSYMREF $b &&
1211 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
1212 git update-ref -z --stdin <stdin &&
1213 git rev-parse TESTSYMREF >expect &&
1214 git rev-parse $a >actual &&
1215 test_cmp expect actual &&
1216 git rev-parse $m~1 >expect &&
1217 git rev-parse $b >actual &&
1218 test_cmp expect actual
1221 test_expect_success 'stdin -z delete symref works option no-deref' '
1222 git symbolic-ref TESTSYMREF $b &&
1223 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
1224 git update-ref -z --stdin <stdin &&
1225 test_must_fail git rev-parse --verify -q TESTSYMREF &&
1226 git rev-parse $m~1 >expect &&
1227 git rev-parse $b >actual &&
1228 test_cmp expect actual
1231 test_expect_success 'stdin -z delete ref works with right old value' '
1232 printf $F "delete $b" "$m~1" >stdin &&
1233 git update-ref -z --stdin <stdin &&
1234 test_must_fail git rev-parse --verify -q $b
1237 test_expect_success 'stdin -z update/create/verify combination works' '
1238 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
1239 git update-ref -z --stdin <stdin &&
1240 git rev-parse $m >expect &&
1241 git rev-parse $a >actual &&
1242 test_cmp expect actual &&
1243 git rev-parse $b >actual &&
1244 test_cmp expect actual &&
1245 test_must_fail git rev-parse --verify -q $c
1248 test_expect_success 'stdin -z verify succeeds for correct value' '
1249 git rev-parse $m >expect &&
1250 printf $F "verify $m" "$m" >stdin &&
1251 git update-ref -z --stdin <stdin &&
1252 git rev-parse $m >actual &&
1253 test_cmp expect actual
1256 test_expect_success 'stdin -z verify succeeds for missing reference' '
1257 printf $F "verify refs/heads/missing" "$Z" >stdin &&
1258 git update-ref -z --stdin <stdin &&
1259 test_must_fail git rev-parse --verify -q refs/heads/missing
1262 test_expect_success 'stdin -z verify treats no value as missing' '
1263 printf $F "verify refs/heads/missing" "" >stdin &&
1264 git update-ref -z --stdin <stdin &&
1265 test_must_fail git rev-parse --verify -q refs/heads/missing
1268 test_expect_success 'stdin -z verify fails for wrong value' '
1269 git rev-parse $m >expect &&
1270 printf $F "verify $m" "$m~1" >stdin &&
1271 test_must_fail git update-ref -z --stdin <stdin &&
1272 git rev-parse $m >actual &&
1273 test_cmp expect actual
1276 test_expect_success 'stdin -z verify fails for mistaken null value' '
1277 git rev-parse $m >expect &&
1278 printf $F "verify $m" "$Z" >stdin &&
1279 test_must_fail git update-ref -z --stdin <stdin &&
1280 git rev-parse $m >actual &&
1281 test_cmp expect actual
1284 test_expect_success 'stdin -z verify fails for mistaken empty value' '
1285 M=$(git rev-parse $m) &&
1286 test_when_finished "git update-ref $m $M" &&
1287 git rev-parse $m >expect &&
1288 printf $F "verify $m" "" >stdin &&
1289 test_must_fail git update-ref -z --stdin <stdin &&
1290 git rev-parse $m >actual &&
1291 test_cmp expect actual
1294 test_expect_success 'stdin -z update refs works with identity updates' '
1295 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
1296 git update-ref -z --stdin <stdin &&
1297 git rev-parse $m >expect &&
1298 git rev-parse $a >actual &&
1299 test_cmp expect actual &&
1300 git rev-parse $b >actual &&
1301 test_cmp expect actual &&
1302 test_must_fail git rev-parse --verify -q $c
1305 test_expect_success 'stdin -z update refs fails with wrong old value' '
1306 git update-ref $c $m &&
1307 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
1308 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1309 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
1310 git rev-parse $m >expect &&
1311 git rev-parse $a >actual &&
1312 test_cmp expect actual &&
1313 git rev-parse $b >actual &&
1314 test_cmp expect actual &&
1315 git rev-parse $c >actual &&
1316 test_cmp expect actual
1319 test_expect_success 'stdin -z delete refs works with packed and loose refs' '
1320 git pack-refs --all &&
1321 git update-ref $c $m~1 &&
1322 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
1323 git update-ref -z --stdin <stdin &&
1324 test_must_fail git rev-parse --verify -q $a &&
1325 test_must_fail git rev-parse --verify -q $b &&
1326 test_must_fail git rev-parse --verify -q $c
1329 test_expect_success 'fails with duplicate HEAD update' '
1330 git branch target1 $A &&
1331 git checkout target1 &&
1332 cat >stdin <<-EOF &&
1333 update refs/heads/target1 $C
1337 test_must_fail git update-ref --stdin <stdin 2>err &&
1338 test_i18ngrep "fatal: multiple updates for '\''HEAD'\'' (including one via its referent .refs/heads/target1.) are not allowed" err &&
1339 echo "refs/heads/target1" >expect &&
1340 git symbolic-ref HEAD >actual &&
1341 test_cmp expect actual &&
1342 echo "$A" >expect &&
1343 git rev-parse refs/heads/target1 >actual &&
1344 test_cmp expect actual
1347 test_expect_success 'fails with duplicate ref update via symref' '
1348 git branch target2 $A &&
1349 git symbolic-ref refs/heads/symref2 refs/heads/target2 &&
1350 cat >stdin <<-EOF &&
1351 update refs/heads/target2 $C
1352 update refs/heads/symref2 $B
1354 test_must_fail git update-ref --stdin <stdin 2>err &&
1355 test_i18ngrep "fatal: multiple updates for '\''refs/heads/target2'\'' (including one via symref .refs/heads/symref2.) are not allowed" err &&
1356 echo "refs/heads/target2" >expect &&
1357 git symbolic-ref refs/heads/symref2 >actual &&
1358 test_cmp expect actual &&
1359 echo "$A" >expect &&
1360 git rev-parse refs/heads/target2 >actual &&
1361 test_cmp expect actual
1364 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' '
1366 for i in $(test_seq 33)
1368 echo "create refs/heads/$i HEAD"
1369 done >large_input &&
1370 run_with_limited_open_files git update-ref --stdin <large_input &&
1371 git rev-parse --verify -q refs/heads/33
1375 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches does not burst open file limit' '
1377 for i in $(test_seq 33)
1379 echo "delete refs/heads/$i HEAD"
1380 done >large_input &&
1381 run_with_limited_open_files git update-ref --stdin <large_input &&
1382 test_must_fail git rev-parse --verify -q refs/heads/33
1386 test_expect_success 'handle per-worktree refs in refs/bisect' '
1387 git commit --allow-empty -m "initial commit" &&
1388 git worktree add -b branch worktree &&
1391 git commit --allow-empty -m "test commit" &&
1392 git for-each-ref >for-each-ref.out &&
1393 ! grep refs/bisect for-each-ref.out &&
1394 git update-ref refs/bisect/something HEAD &&
1395 git rev-parse refs/bisect/something >../worktree-head &&
1396 git for-each-ref | grep refs/bisect/something
1398 git show-ref >actual &&
1399 ! grep 'refs/bisect' actual &&
1400 test_must_fail git rev-parse refs/bisect/something &&
1401 git update-ref refs/bisect/something HEAD &&
1402 git rev-parse refs/bisect/something >main-head &&
1403 ! test_cmp main-head worktree-head
1406 test_expect_success 'transaction handles empty commit' '
1407 cat >stdin <<-EOF &&
1412 git update-ref --stdin <stdin >actual &&
1413 printf "%s: ok\n" start prepare commit >expect &&
1414 test_cmp expect actual
1417 test_expect_success 'transaction handles empty commit with missing prepare' '
1418 cat >stdin <<-EOF &&
1422 git update-ref --stdin <stdin >actual &&
1423 printf "%s: ok\n" start commit >expect &&
1424 test_cmp expect actual
1427 test_expect_success 'transaction handles sole commit' '
1428 cat >stdin <<-EOF &&
1431 git update-ref --stdin <stdin >actual &&
1432 printf "%s: ok\n" commit >expect &&
1433 test_cmp expect actual
1436 test_expect_success 'transaction handles empty abort' '
1437 cat >stdin <<-EOF &&
1442 git update-ref --stdin <stdin >actual &&
1443 printf "%s: ok\n" start prepare abort >expect &&
1444 test_cmp expect actual
1447 test_expect_success 'transaction exits on multiple aborts' '
1448 cat >stdin <<-EOF &&
1452 test_must_fail git update-ref --stdin <stdin >actual 2>err &&
1453 printf "%s: ok\n" abort >expect &&
1454 test_cmp expect actual &&
1455 grep "fatal: transaction is closed" err
1458 test_expect_success 'transaction exits on start after prepare' '
1459 cat >stdin <<-EOF &&
1463 test_must_fail git update-ref --stdin <stdin 2>err >actual &&
1464 printf "%s: ok\n" prepare >expect &&
1465 test_cmp expect actual &&
1466 grep "fatal: prepared transactions can only be closed" err
1469 test_expect_success 'transaction handles empty abort with missing prepare' '
1470 cat >stdin <<-EOF &&
1474 git update-ref --stdin <stdin >actual &&
1475 printf "%s: ok\n" start abort >expect &&
1476 test_cmp expect actual
1479 test_expect_success 'transaction handles sole abort' '
1480 cat >stdin <<-EOF &&
1483 git update-ref --stdin <stdin >actual &&
1484 printf "%s: ok\n" abort >expect &&
1485 test_cmp expect actual
1488 test_expect_success 'transaction can handle commit' '
1489 cat >stdin <<-EOF &&
1494 git update-ref --stdin <stdin >actual &&
1495 printf "%s: ok\n" start commit >expect &&
1496 test_cmp expect actual &&
1497 git rev-parse HEAD >expect &&
1498 git rev-parse $a >actual &&
1499 test_cmp expect actual
1502 test_expect_success 'transaction can handle abort' '
1503 cat >stdin <<-EOF &&
1508 git update-ref --stdin <stdin >actual &&
1509 printf "%s: ok\n" start abort >expect &&
1510 test_cmp expect actual &&
1511 test_must_fail git show-ref --verify -q $b
1514 test_expect_success 'transaction aborts by default' '
1515 cat >stdin <<-EOF &&
1519 git update-ref --stdin <stdin >actual &&
1520 printf "%s: ok\n" start >expect &&
1521 test_cmp expect actual &&
1522 test_must_fail git show-ref --verify -q $b
1525 test_expect_success 'transaction with prepare aborts by default' '
1526 cat >stdin <<-EOF &&
1531 git update-ref --stdin <stdin >actual &&
1532 printf "%s: ok\n" start prepare >expect &&
1533 test_cmp expect actual &&
1534 test_must_fail git show-ref --verify -q $b
1537 test_expect_success 'transaction can commit multiple times' '
1538 cat >stdin <<-EOF &&
1540 create refs/heads/branch-1 $A
1543 create refs/heads/branch-2 $B
1546 git update-ref --stdin <stdin >actual &&
1547 printf "%s: ok\n" start commit start commit >expect &&
1548 test_cmp expect actual &&
1549 echo "$A" >expect &&
1550 git rev-parse refs/heads/branch-1 >actual &&
1551 test_cmp expect actual &&
1552 echo "$B" >expect &&
1553 git rev-parse refs/heads/branch-2 >actual &&
1554 test_cmp expect actual
1557 test_expect_success 'transaction can create and delete' '
1558 cat >stdin <<-EOF &&
1560 create refs/heads/create-and-delete $A
1563 delete refs/heads/create-and-delete $A
1566 git update-ref --stdin <stdin >actual &&
1567 printf "%s: ok\n" start commit start commit >expect &&
1568 test_must_fail git show-ref --verify refs/heads/create-and-delete
1571 test_expect_success 'transaction can commit after abort' '
1572 cat >stdin <<-EOF &&
1574 create refs/heads/abort $A
1577 create refs/heads/abort $A
1580 git update-ref --stdin <stdin >actual &&
1581 printf "%s: ok\n" start abort start commit >expect &&
1582 echo "$A" >expect &&
1583 git rev-parse refs/heads/abort >actual &&
1584 test_cmp expect actual
1587 test_expect_success 'transaction cannot restart ongoing transaction' '
1588 cat >stdin <<-EOF &&
1590 create refs/heads/restart $A
1594 test_must_fail git update-ref --stdin <stdin >actual &&
1595 test_must_fail git show-ref --verify refs/heads/restart