ef61fe324bdd14294c5203358ae91b85956f970e
1#!/bin/sh
2#
3# Copyright (c) 2006 Shawn Pearce
4#
5
6test_description='Test git update-ref and basic ref logging'
7. ./test-lib.sh
8
9Z=$_z40
10
11test_expect_success setup '
12
13 for name in A B C D E F
14 do
15 test_tick &&
16 T=$(git write-tree) &&
17 sha1=$(echo $name | git commit-tree $T) &&
18 eval $name=$sha1
19 done
20
21'
22
23m=refs/heads/master
24n_dir=refs/heads/gu
25n=$n_dir/fixes
26
27test_expect_success \
28 "create $m" \
29 "git update-ref $m $A &&
30 test $A"' = $(cat .git/'"$m"')'
31test_expect_success \
32 "create $m" \
33 "git update-ref $m $B $A &&
34 test $B"' = $(cat .git/'"$m"')'
35test_expect_success "fail to delete $m with stale ref" '
36 test_must_fail git update-ref -d $m $A &&
37 test $B = "$(cat .git/$m)"
38'
39test_expect_success "delete $m" '
40 git update-ref -d $m $B &&
41 ! test -f .git/$m
42'
43rm -f .git/$m
44
45test_expect_success "delete $m without oldvalue verification" "
46 git update-ref $m $A &&
47 test $A = \$(cat .git/$m) &&
48 git update-ref -d $m &&
49 ! test -f .git/$m
50"
51rm -f .git/$m
52
53test_expect_success \
54 "fail to create $n" \
55 "touch .git/$n_dir &&
56 test_must_fail git update-ref $n $A >out 2>err"
57rm -f .git/$n_dir out err
58
59test_expect_success \
60 "create $m (by HEAD)" \
61 "git update-ref HEAD $A &&
62 test $A"' = $(cat .git/'"$m"')'
63test_expect_success \
64 "create $m (by HEAD)" \
65 "git update-ref HEAD $B $A &&
66 test $B"' = $(cat .git/'"$m"')'
67test_expect_success "fail to delete $m (by HEAD) with stale ref" '
68 test_must_fail git update-ref -d HEAD $A &&
69 test $B = $(cat .git/$m)
70'
71test_expect_success "delete $m (by HEAD)" '
72 git update-ref -d HEAD $B &&
73 ! test -f .git/$m
74'
75rm -f .git/$m
76
77test_expect_success \
78 "create $m (by HEAD)" \
79 "git update-ref HEAD $A &&
80 test $A"' = $(cat .git/'"$m"')'
81test_expect_success \
82 "pack refs" \
83 "git pack-refs --all"
84test_expect_success \
85 "move $m (by HEAD)" \
86 "git update-ref HEAD $B $A &&
87 test $B"' = $(cat .git/'"$m"')'
88test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" '
89 git update-ref -d HEAD $B &&
90 ! grep "$m" .git/packed-refs &&
91 ! test -f .git/$m
92'
93rm -f .git/$m
94
95cp -f .git/HEAD .git/HEAD.orig
96test_expect_success "delete symref without dereference" '
97 git update-ref --no-deref -d HEAD &&
98 ! test -f .git/HEAD
99'
100cp -f .git/HEAD.orig .git/HEAD
101
102test_expect_success "delete symref without dereference when the referred ref is packed" '
103 echo foo >foo.c &&
104 git add foo.c &&
105 git commit -m foo &&
106 git pack-refs --all &&
107 git update-ref --no-deref -d HEAD &&
108 ! test -f .git/HEAD
109'
110cp -f .git/HEAD.orig .git/HEAD
111git update-ref -d $m
112
113test_expect_success '(not) create HEAD with old sha1' "
114 test_must_fail git update-ref HEAD $A $B
115"
116test_expect_success "(not) prior created .git/$m" "
117 ! test -f .git/$m
118"
119rm -f .git/$m
120
121test_expect_success \
122 "create HEAD" \
123 "git update-ref HEAD $A"
124test_expect_success '(not) change HEAD with wrong SHA1' "
125 test_must_fail git update-ref HEAD $B $Z
126"
127test_expect_success "(not) changed .git/$m" "
128 ! test $B"' = $(cat .git/'"$m"')
129'
130rm -f .git/$m
131
132: a repository with working tree always has reflog these days...
133: >.git/logs/refs/heads/master
134test_expect_success \
135 "create $m (logged by touch)" \
136 'GIT_COMMITTER_DATE="2005-05-26 23:30" \
137 git update-ref HEAD '"$A"' -m "Initial Creation" &&
138 test '"$A"' = $(cat .git/'"$m"')'
139test_expect_success \
140 "update $m (logged by touch)" \
141 'GIT_COMMITTER_DATE="2005-05-26 23:31" \
142 git update-ref HEAD'" $B $A "'-m "Switch" &&
143 test '"$B"' = $(cat .git/'"$m"')'
144test_expect_success \
145 "set $m (logged by touch)" \
146 'GIT_COMMITTER_DATE="2005-05-26 23:41" \
147 git update-ref HEAD'" $A &&
148 test $A"' = $(cat .git/'"$m"')'
149
150cat >expect <<EOF
151$Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
152$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
153$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
154EOF
155test_expect_success \
156 "verifying $m's log" \
157 "test_cmp expect .git/logs/$m"
158rm -rf .git/$m .git/logs expect
159
160test_expect_success \
161 'enable core.logAllRefUpdates' \
162 'git config core.logAllRefUpdates true &&
163 test true = $(git config --bool --get core.logAllRefUpdates)'
164
165test_expect_success \
166 "create $m (logged by config)" \
167 'GIT_COMMITTER_DATE="2005-05-26 23:32" \
168 git update-ref HEAD'" $A "'-m "Initial Creation" &&
169 test '"$A"' = $(cat .git/'"$m"')'
170test_expect_success \
171 "update $m (logged by config)" \
172 'GIT_COMMITTER_DATE="2005-05-26 23:33" \
173 git update-ref HEAD'" $B $A "'-m "Switch" &&
174 test '"$B"' = $(cat .git/'"$m"')'
175test_expect_success \
176 "set $m (logged by config)" \
177 'GIT_COMMITTER_DATE="2005-05-26 23:43" \
178 git update-ref HEAD '"$A &&
179 test $A"' = $(cat .git/'"$m"')'
180
181cat >expect <<EOF
182$Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
183$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
184$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
185EOF
186test_expect_success \
187 "verifying $m's log" \
188 'test_cmp expect .git/logs/$m'
189rm -f .git/$m .git/logs/$m expect
190
191git update-ref $m $D
192cat >.git/logs/$m <<EOF
1930000000000000000000000000000000000000000 $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
194$C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
195$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
196$F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
197$Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
198EOF
199
200ed="Thu, 26 May 2005 18:32:00 -0500"
201gd="Thu, 26 May 2005 18:33:00 -0500"
202ld="Thu, 26 May 2005 18:43:00 -0500"
203test_expect_success \
204 'Query "master@{May 25 2005}" (before history)' \
205 'rm -f o e &&
206 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
207 test '"$C"' = $(cat o) &&
208 test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
209test_expect_success \
210 "Query master@{2005-05-25} (before history)" \
211 'rm -f o e &&
212 git rev-parse --verify master@{2005-05-25} >o 2>e &&
213 test '"$C"' = $(cat o) &&
214 echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
215test_expect_success \
216 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
217 'rm -f o e &&
218 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
219 test '"$C"' = $(cat o) &&
220 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
221test_expect_success \
222 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
223 'rm -f o e &&
224 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
225 test '"$C"' = $(cat o) &&
226 test "" = "$(cat e)"'
227test_expect_success \
228 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \
229 'rm -f o e &&
230 git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e &&
231 test '"$A"' = $(cat o) &&
232 test "" = "$(cat e)"'
233test_expect_success \
234 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
235 'rm -f o e &&
236 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
237 test '"$B"' = $(cat o) &&
238 test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"'
239test_expect_success \
240 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
241 'rm -f o e &&
242 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
243 test '"$Z"' = $(cat o) &&
244 test "" = "$(cat e)"'
245test_expect_success \
246 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
247 'rm -f o e &&
248 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
249 test '"$E"' = $(cat o) &&
250 test "" = "$(cat e)"'
251test_expect_success \
252 'Query "master@{2005-05-28}" (past end of history)' \
253 'rm -f o e &&
254 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
255 test '"$D"' = $(cat o) &&
256 test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"'
257
258
259rm -f .git/$m .git/logs/$m expect
260
261test_expect_success \
262 'creating initial files' \
263 'echo TEST >F &&
264 git add F &&
265 GIT_AUTHOR_DATE="2005-05-26 23:30" \
266 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
267 h_TEST=$(git rev-parse --verify HEAD) &&
268 echo The other day this did not work. >M &&
269 echo And then Bob told me how to fix it. >>M &&
270 echo OTHER >F &&
271 GIT_AUTHOR_DATE="2005-05-26 23:41" \
272 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
273 h_OTHER=$(git rev-parse --verify HEAD) &&
274 GIT_AUTHOR_DATE="2005-05-26 23:44" \
275 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
276 h_FIXED=$(git rev-parse --verify HEAD) &&
277 echo Merged initial commit and a later commit. >M &&
278 echo $h_TEST >.git/MERGE_HEAD &&
279 GIT_AUTHOR_DATE="2005-05-26 23:45" \
280 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
281 h_MERGED=$(git rev-parse --verify HEAD) &&
282 rm -f M'
283
284cat >expect <<EOF
285$Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
286$h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
287$h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
288$h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
289EOF
290test_expect_success \
291 'git commit logged updates' \
292 "test_cmp expect .git/logs/$m"
293unset h_TEST h_OTHER h_FIXED h_MERGED
294
295test_expect_success \
296 'git cat-file blob master:F (expect OTHER)' \
297 'test OTHER = $(git cat-file blob master:F)'
298test_expect_success \
299 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
300 'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")'
301test_expect_success \
302 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
303 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'
304
305a=refs/heads/a
306b=refs/heads/b
307c=refs/heads/c
308E='""'
309F='%s\0'
310pws='path with space'
311
312test_expect_success 'stdin test setup' '
313 echo "$pws" >"$pws" &&
314 git add -- "$pws" &&
315 git commit -m "$pws"
316'
317
318test_expect_success '-z fails without --stdin' '
319 test_must_fail git update-ref -z $m $m $m 2>err &&
320 grep "usage: git update-ref" err
321'
322
323test_expect_success 'stdin works with no input' '
324 >stdin &&
325 git update-ref --stdin <stdin &&
326 git rev-parse --verify -q $m
327'
328
329test_expect_success 'stdin fails on empty line' '
330 echo "" >stdin &&
331 test_must_fail git update-ref --stdin <stdin 2>err &&
332 grep "fatal: empty command in input" err
333'
334
335test_expect_success 'stdin fails on only whitespace' '
336 echo " " >stdin &&
337 test_must_fail git update-ref --stdin <stdin 2>err &&
338 grep "fatal: whitespace before command: " err
339'
340
341test_expect_success 'stdin fails on leading whitespace' '
342 echo " create $a $m" >stdin &&
343 test_must_fail git update-ref --stdin <stdin 2>err &&
344 grep "fatal: whitespace before command: create $a $m" err
345'
346
347test_expect_success 'stdin fails on unknown command' '
348 echo "unknown $a" >stdin &&
349 test_must_fail git update-ref --stdin <stdin 2>err &&
350 grep "fatal: unknown command: unknown $a" err
351'
352
353test_expect_success 'stdin fails on unbalanced quotes' '
354 echo "create $a \"master" >stdin &&
355 test_must_fail git update-ref --stdin <stdin 2>err &&
356 grep "fatal: badly quoted argument: \\\"master" err
357'
358
359test_expect_success 'stdin fails on invalid escape' '
360 echo "create $a \"ma\zter\"" >stdin &&
361 test_must_fail git update-ref --stdin <stdin 2>err &&
362 grep "fatal: badly quoted argument: \\\"ma\\\\zter\\\"" err
363'
364
365test_expect_success 'stdin fails on junk after quoted argument' '
366 echo "create \"$a\"master" >stdin &&
367 test_must_fail git update-ref --stdin <stdin 2>err &&
368 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"master" err
369'
370
371test_expect_success 'stdin fails create with no ref' '
372 echo "create " >stdin &&
373 test_must_fail git update-ref --stdin <stdin 2>err &&
374 grep "fatal: create line missing <ref>" err
375'
376
377test_expect_success 'stdin fails create with bad ref name' '
378 echo "create ~a $m" >stdin &&
379 test_must_fail git update-ref --stdin <stdin 2>err &&
380 grep "fatal: invalid ref format: ~a" err
381'
382
383test_expect_success 'stdin fails create with no new value' '
384 echo "create $a" >stdin &&
385 test_must_fail git update-ref --stdin <stdin 2>err &&
386 grep "fatal: create $a missing <newvalue>" err
387'
388
389test_expect_success 'stdin fails create with too many arguments' '
390 echo "create $a $m $m" >stdin &&
391 test_must_fail git update-ref --stdin <stdin 2>err &&
392 grep "fatal: create $a has extra input: $m" err
393'
394
395test_expect_success 'stdin fails update with no ref' '
396 echo "update " >stdin &&
397 test_must_fail git update-ref --stdin <stdin 2>err &&
398 grep "fatal: update line missing <ref>" err
399'
400
401test_expect_success 'stdin fails update with bad ref name' '
402 echo "update ~a $m" >stdin &&
403 test_must_fail git update-ref --stdin <stdin 2>err &&
404 grep "fatal: invalid ref format: ~a" err
405'
406
407test_expect_success 'stdin fails update with no new value' '
408 echo "update $a" >stdin &&
409 test_must_fail git update-ref --stdin <stdin 2>err &&
410 grep "fatal: update $a missing <newvalue>" err
411'
412
413test_expect_success 'stdin fails update with too many arguments' '
414 echo "update $a $m $m $m" >stdin &&
415 test_must_fail git update-ref --stdin <stdin 2>err &&
416 grep "fatal: update $a has extra input: $m" err
417'
418
419test_expect_success 'stdin fails delete with no ref' '
420 echo "delete " >stdin &&
421 test_must_fail git update-ref --stdin <stdin 2>err &&
422 grep "fatal: delete line missing <ref>" err
423'
424
425test_expect_success 'stdin fails delete with bad ref name' '
426 echo "delete ~a $m" >stdin &&
427 test_must_fail git update-ref --stdin <stdin 2>err &&
428 grep "fatal: invalid ref format: ~a" err
429'
430
431test_expect_success 'stdin fails delete with too many arguments' '
432 echo "delete $a $m $m" >stdin &&
433 test_must_fail git update-ref --stdin <stdin 2>err &&
434 grep "fatal: delete $a has extra input: $m" err
435'
436
437test_expect_success 'stdin fails verify with too many arguments' '
438 echo "verify $a $m $m" >stdin &&
439 test_must_fail git update-ref --stdin <stdin 2>err &&
440 grep "fatal: verify $a has extra input: $m" err
441'
442
443test_expect_success 'stdin fails option with unknown name' '
444 echo "option unknown" >stdin &&
445 test_must_fail git update-ref --stdin <stdin 2>err &&
446 grep "fatal: option unknown: unknown" err
447'
448
449test_expect_success 'stdin fails with duplicate refs' '
450 cat >stdin <<-EOF &&
451 create $a $m
452 create $b $m
453 create $a $m
454 EOF
455 test_must_fail git update-ref --stdin <stdin 2>err &&
456 grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
457'
458
459test_expect_success 'stdin create ref works' '
460 echo "create $a $m" >stdin &&
461 git update-ref --stdin <stdin &&
462 git rev-parse $m >expect &&
463 git rev-parse $a >actual &&
464 test_cmp expect actual
465'
466
467test_expect_success 'stdin succeeds with quoted argument' '
468 git update-ref -d $a &&
469 echo "create $a \"$m\"" >stdin &&
470 git update-ref --stdin <stdin &&
471 git rev-parse $m >expect &&
472 git rev-parse $a >actual &&
473 test_cmp expect actual
474'
475
476test_expect_success 'stdin succeeds with escaped character' '
477 git update-ref -d $a &&
478 echo "create $a \"ma\\163ter\"" >stdin &&
479 git update-ref --stdin <stdin &&
480 git rev-parse $m >expect &&
481 git rev-parse $a >actual &&
482 test_cmp expect actual
483'
484
485test_expect_success 'stdin update ref creates with zero old value' '
486 echo "update $b $m $Z" >stdin &&
487 git update-ref --stdin <stdin &&
488 git rev-parse $m >expect &&
489 git rev-parse $b >actual &&
490 test_cmp expect actual &&
491 git update-ref -d $b
492'
493
494test_expect_success 'stdin update ref creates with empty old value' '
495 echo "update $b $m $E" >stdin &&
496 git update-ref --stdin <stdin &&
497 git rev-parse $m >expect &&
498 git rev-parse $b >actual &&
499 test_cmp expect actual
500'
501
502test_expect_success 'stdin create ref works with path with space to blob' '
503 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
504 git update-ref --stdin <stdin &&
505 git rev-parse "$m:$pws" >expect &&
506 git rev-parse refs/blobs/pws >actual &&
507 test_cmp expect actual &&
508 git update-ref -d refs/blobs/pws
509'
510
511test_expect_success 'stdin update ref fails with wrong old value' '
512 echo "update $c $m $m~1" >stdin &&
513 test_must_fail git update-ref --stdin <stdin 2>err &&
514 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
515 test_must_fail git rev-parse --verify -q $c
516'
517
518test_expect_success 'stdin update ref fails with bad old value' '
519 echo "update $c $m does-not-exist" >stdin &&
520 test_must_fail git update-ref --stdin <stdin 2>err &&
521 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
522 test_must_fail git rev-parse --verify -q $c
523'
524
525test_expect_success 'stdin create ref fails with bad new value' '
526 echo "create $c does-not-exist" >stdin &&
527 test_must_fail git update-ref --stdin <stdin 2>err &&
528 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
529 test_must_fail git rev-parse --verify -q $c
530'
531
532test_expect_success 'stdin create ref fails with zero new value' '
533 echo "create $c " >stdin &&
534 test_must_fail git update-ref --stdin <stdin 2>err &&
535 grep "fatal: create $c given zero <newvalue>" err &&
536 test_must_fail git rev-parse --verify -q $c
537'
538
539test_expect_success 'stdin update ref works with right old value' '
540 echo "update $b $m~1 $m" >stdin &&
541 git update-ref --stdin <stdin &&
542 git rev-parse $m~1 >expect &&
543 git rev-parse $b >actual &&
544 test_cmp expect actual
545'
546
547test_expect_success 'stdin delete ref fails with wrong old value' '
548 echo "delete $a $m~1" >stdin &&
549 test_must_fail git update-ref --stdin <stdin 2>err &&
550 grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
551 git rev-parse $m >expect &&
552 git rev-parse $a >actual &&
553 test_cmp expect actual
554'
555
556test_expect_success 'stdin delete ref fails with zero old value' '
557 echo "delete $a " >stdin &&
558 test_must_fail git update-ref --stdin <stdin 2>err &&
559 grep "fatal: delete $a given zero <oldvalue>" err &&
560 git rev-parse $m >expect &&
561 git rev-parse $a >actual &&
562 test_cmp expect actual
563'
564
565test_expect_success 'stdin update symref works option no-deref' '
566 git symbolic-ref TESTSYMREF $b &&
567 cat >stdin <<-EOF &&
568 option no-deref
569 update TESTSYMREF $a $b
570 EOF
571 git update-ref --stdin <stdin &&
572 git rev-parse TESTSYMREF >expect &&
573 git rev-parse $a >actual &&
574 test_cmp expect actual &&
575 git rev-parse $m~1 >expect &&
576 git rev-parse $b >actual &&
577 test_cmp expect actual
578'
579
580test_expect_success 'stdin delete symref works option no-deref' '
581 git symbolic-ref TESTSYMREF $b &&
582 cat >stdin <<-EOF &&
583 option no-deref
584 delete TESTSYMREF $b
585 EOF
586 git update-ref --stdin <stdin &&
587 test_must_fail git rev-parse --verify -q TESTSYMREF &&
588 git rev-parse $m~1 >expect &&
589 git rev-parse $b >actual &&
590 test_cmp expect actual
591'
592
593test_expect_success 'stdin delete ref works with right old value' '
594 echo "delete $b $m~1" >stdin &&
595 git update-ref --stdin <stdin &&
596 test_must_fail git rev-parse --verify -q $b
597'
598
599test_expect_success 'stdin update/create/verify combination works' '
600 cat >stdin <<-EOF &&
601 update $a $m
602 create $b $m
603 verify $c
604 EOF
605 git update-ref --stdin <stdin &&
606 git rev-parse $m >expect &&
607 git rev-parse $a >actual &&
608 test_cmp expect actual &&
609 git rev-parse $b >actual &&
610 test_cmp expect actual &&
611 test_must_fail git rev-parse --verify -q $c
612'
613
614test_expect_success 'stdin update refs works with identity updates' '
615 cat >stdin <<-EOF &&
616 update $a $m $m
617 update $b $m $m
618 update $c $Z $E
619 EOF
620 git update-ref --stdin <stdin &&
621 git rev-parse $m >expect &&
622 git rev-parse $a >actual &&
623 test_cmp expect actual &&
624 git rev-parse $b >actual &&
625 test_cmp expect actual &&
626 test_must_fail git rev-parse --verify -q $c
627'
628
629test_expect_success 'stdin update refs fails with wrong old value' '
630 git update-ref $c $m &&
631 cat >stdin <<-EOF &&
632 update $a $m $m
633 update $b $m $m
634 update $c ''
635 EOF
636 test_must_fail git update-ref --stdin <stdin 2>err &&
637 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
638 git rev-parse $m >expect &&
639 git rev-parse $a >actual &&
640 test_cmp expect actual &&
641 git rev-parse $b >actual &&
642 test_cmp expect actual &&
643 git rev-parse $c >actual &&
644 test_cmp expect actual
645'
646
647test_expect_success 'stdin delete refs works with packed and loose refs' '
648 git pack-refs --all &&
649 git update-ref $c $m~1 &&
650 cat >stdin <<-EOF &&
651 delete $a $m
652 update $b $Z $m
653 update $c $E $m~1
654 EOF
655 git update-ref --stdin <stdin &&
656 test_must_fail git rev-parse --verify -q $a &&
657 test_must_fail git rev-parse --verify -q $b &&
658 test_must_fail git rev-parse --verify -q $c
659'
660
661test_expect_success 'stdin -z works on empty input' '
662 >stdin &&
663 git update-ref -z --stdin <stdin &&
664 git rev-parse --verify -q $m
665'
666
667test_expect_success 'stdin -z fails on empty line' '
668 echo "" >stdin &&
669 test_must_fail git update-ref -z --stdin <stdin 2>err &&
670 grep "fatal: whitespace before command: " err
671'
672
673test_expect_success 'stdin -z fails on empty command' '
674 printf $F "" >stdin &&
675 test_must_fail git update-ref -z --stdin <stdin 2>err &&
676 grep "fatal: empty command in input" err
677'
678
679test_expect_success 'stdin -z fails on only whitespace' '
680 printf $F " " >stdin &&
681 test_must_fail git update-ref -z --stdin <stdin 2>err &&
682 grep "fatal: whitespace before command: " err
683'
684
685test_expect_success 'stdin -z fails on leading whitespace' '
686 printf $F " create $a" "$m" >stdin &&
687 test_must_fail git update-ref -z --stdin <stdin 2>err &&
688 grep "fatal: whitespace before command: create $a" err
689'
690
691test_expect_success 'stdin -z fails on unknown command' '
692 printf $F "unknown $a" >stdin &&
693 test_must_fail git update-ref -z --stdin <stdin 2>err &&
694 grep "fatal: unknown command: unknown $a" err
695'
696
697test_expect_success 'stdin -z fails create with no ref' '
698 printf $F "create " >stdin &&
699 test_must_fail git update-ref -z --stdin <stdin 2>err &&
700 grep "fatal: create line missing <ref>" err
701'
702
703test_expect_success 'stdin -z fails create with bad ref name' '
704 printf $F "create ~a " "$m" >stdin &&
705 test_must_fail git update-ref -z --stdin <stdin 2>err &&
706 grep "fatal: invalid ref format: ~a " err
707'
708
709test_expect_success 'stdin -z fails create with no new value' '
710 printf $F "create $a" >stdin &&
711 test_must_fail git update-ref -z --stdin <stdin 2>err &&
712 grep "fatal: create $a missing <newvalue>" err
713'
714
715test_expect_success 'stdin -z fails create with too many arguments' '
716 printf $F "create $a" "$m" "$m" >stdin &&
717 test_must_fail git update-ref -z --stdin <stdin 2>err &&
718 grep "fatal: unknown command: $m" err
719'
720
721test_expect_success 'stdin -z fails update with no ref' '
722 printf $F "update " >stdin &&
723 test_must_fail git update-ref -z --stdin <stdin 2>err &&
724 grep "fatal: update line missing <ref>" err
725'
726
727test_expect_success 'stdin -z fails update with bad ref name' '
728 printf $F "update ~a" "$m" >stdin &&
729 test_must_fail git update-ref -z --stdin <stdin 2>err &&
730 grep "fatal: invalid ref format: ~a" err
731'
732
733test_expect_success 'stdin -z fails update with no new value' '
734 printf $F "update $a" >stdin &&
735 test_must_fail git update-ref -z --stdin <stdin 2>err &&
736 grep "fatal: update $a missing <newvalue>" err
737'
738
739test_expect_success 'stdin -z fails update with no old value' '
740 printf $F "update $a" "$m" >stdin &&
741 test_must_fail git update-ref -z --stdin <stdin 2>err &&
742 grep "fatal: update $a missing \\[<oldvalue>\\] NUL" err
743'
744
745test_expect_success 'stdin -z fails update with too many arguments' '
746 printf $F "update $a" "$m" "$m" "$m" >stdin &&
747 test_must_fail git update-ref -z --stdin <stdin 2>err &&
748 grep "fatal: unknown command: $m" err
749'
750
751test_expect_success 'stdin -z fails delete with no ref' '
752 printf $F "delete " >stdin &&
753 test_must_fail git update-ref -z --stdin <stdin 2>err &&
754 grep "fatal: delete line missing <ref>" err
755'
756
757test_expect_success 'stdin -z fails delete with bad ref name' '
758 printf $F "delete ~a" "$m" >stdin &&
759 test_must_fail git update-ref -z --stdin <stdin 2>err &&
760 grep "fatal: invalid ref format: ~a" err
761'
762
763test_expect_success 'stdin -z fails delete with no old value' '
764 printf $F "delete $a" >stdin &&
765 test_must_fail git update-ref -z --stdin <stdin 2>err &&
766 grep "fatal: delete $a missing \\[<oldvalue>\\] NUL" err
767'
768
769test_expect_success 'stdin -z fails delete with too many arguments' '
770 printf $F "delete $a" "$m" "$m" >stdin &&
771 test_must_fail git update-ref -z --stdin <stdin 2>err &&
772 grep "fatal: unknown command: $m" err
773'
774
775test_expect_success 'stdin -z fails verify with too many arguments' '
776 printf $F "verify $a" "$m" "$m" >stdin &&
777 test_must_fail git update-ref -z --stdin <stdin 2>err &&
778 grep "fatal: unknown command: $m" err
779'
780
781test_expect_success 'stdin -z fails verify with no old value' '
782 printf $F "verify $a" >stdin &&
783 test_must_fail git update-ref -z --stdin <stdin 2>err &&
784 grep "fatal: verify $a missing \\[<oldvalue>\\] NUL" err
785'
786
787test_expect_success 'stdin -z fails option with unknown name' '
788 printf $F "option unknown" >stdin &&
789 test_must_fail git update-ref -z --stdin <stdin 2>err &&
790 grep "fatal: option unknown: unknown" err
791'
792
793test_expect_success 'stdin -z fails with duplicate refs' '
794 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
795 test_must_fail git update-ref -z --stdin <stdin 2>err &&
796 grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err
797'
798
799test_expect_success 'stdin -z create ref works' '
800 printf $F "create $a" "$m" >stdin &&
801 git update-ref -z --stdin <stdin &&
802 git rev-parse $m >expect &&
803 git rev-parse $a >actual &&
804 test_cmp expect actual
805'
806
807test_expect_success 'stdin -z update ref creates with zero old value' '
808 printf $F "update $b" "$m" "$Z" >stdin &&
809 git update-ref -z --stdin <stdin &&
810 git rev-parse $m >expect &&
811 git rev-parse $b >actual &&
812 test_cmp expect actual &&
813 git update-ref -d $b
814'
815
816test_expect_success 'stdin -z update ref creates with empty old value' '
817 printf $F "update $b" "$m" "" >stdin &&
818 git update-ref -z --stdin <stdin &&
819 git rev-parse $m >expect &&
820 git rev-parse $b >actual &&
821 test_cmp expect actual
822'
823
824test_expect_success 'stdin -z create ref works with path with space to blob' '
825 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
826 git update-ref -z --stdin <stdin &&
827 git rev-parse "$m:$pws" >expect &&
828 git rev-parse refs/blobs/pws >actual &&
829 test_cmp expect actual &&
830 git update-ref -d refs/blobs/pws
831'
832
833test_expect_success 'stdin -z update ref fails with wrong old value' '
834 printf $F "update $c" "$m" "$m~1" >stdin &&
835 test_must_fail git update-ref -z --stdin <stdin 2>err &&
836 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
837 test_must_fail git rev-parse --verify -q $c
838'
839
840test_expect_success 'stdin -z update ref fails with bad old value' '
841 printf $F "update $c" "$m" "does-not-exist" >stdin &&
842 test_must_fail git update-ref -z --stdin <stdin 2>err &&
843 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
844 test_must_fail git rev-parse --verify -q $c
845'
846
847test_expect_success 'stdin -z create ref fails with bad new value' '
848 printf $F "create $c" "does-not-exist" >stdin &&
849 test_must_fail git update-ref -z --stdin <stdin 2>err &&
850 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
851 test_must_fail git rev-parse --verify -q $c
852'
853
854test_expect_failure 'stdin -z create ref fails with empty new value' '
855 printf $F "create $c" "" >stdin &&
856 test_must_fail git update-ref -z --stdin <stdin 2>err &&
857 grep "fatal: create $c missing <newvalue>" err &&
858 test_must_fail git rev-parse --verify -q $c
859'
860
861test_expect_success 'stdin -z update ref works with right old value' '
862 printf $F "update $b" "$m~1" "$m" >stdin &&
863 git update-ref -z --stdin <stdin &&
864 git rev-parse $m~1 >expect &&
865 git rev-parse $b >actual &&
866 test_cmp expect actual
867'
868
869test_expect_success 'stdin -z delete ref fails with wrong old value' '
870 printf $F "delete $a" "$m~1" >stdin &&
871 test_must_fail git update-ref -z --stdin <stdin 2>err &&
872 grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err &&
873 git rev-parse $m >expect &&
874 git rev-parse $a >actual &&
875 test_cmp expect actual
876'
877
878test_expect_success 'stdin -z delete ref fails with zero old value' '
879 printf $F "delete $a" "$Z" >stdin &&
880 test_must_fail git update-ref -z --stdin <stdin 2>err &&
881 grep "fatal: delete $a given zero <oldvalue>" err &&
882 git rev-parse $m >expect &&
883 git rev-parse $a >actual &&
884 test_cmp expect actual
885'
886
887test_expect_success 'stdin -z update symref works option no-deref' '
888 git symbolic-ref TESTSYMREF $b &&
889 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
890 git update-ref -z --stdin <stdin &&
891 git rev-parse TESTSYMREF >expect &&
892 git rev-parse $a >actual &&
893 test_cmp expect actual &&
894 git rev-parse $m~1 >expect &&
895 git rev-parse $b >actual &&
896 test_cmp expect actual
897'
898
899test_expect_success 'stdin -z delete symref works option no-deref' '
900 git symbolic-ref TESTSYMREF $b &&
901 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
902 git update-ref -z --stdin <stdin &&
903 test_must_fail git rev-parse --verify -q TESTSYMREF &&
904 git rev-parse $m~1 >expect &&
905 git rev-parse $b >actual &&
906 test_cmp expect actual
907'
908
909test_expect_success 'stdin -z delete ref works with right old value' '
910 printf $F "delete $b" "$m~1" >stdin &&
911 git update-ref -z --stdin <stdin &&
912 test_must_fail git rev-parse --verify -q $b
913'
914
915test_expect_success 'stdin -z update/create/verify combination works' '
916 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
917 git update-ref -z --stdin <stdin &&
918 git rev-parse $m >expect &&
919 git rev-parse $a >actual &&
920 test_cmp expect actual &&
921 git rev-parse $b >actual &&
922 test_cmp expect actual &&
923 test_must_fail git rev-parse --verify -q $c
924'
925
926test_expect_success 'stdin -z update refs works with identity updates' '
927 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
928 git update-ref -z --stdin <stdin &&
929 git rev-parse $m >expect &&
930 git rev-parse $a >actual &&
931 test_cmp expect actual &&
932 git rev-parse $b >actual &&
933 test_cmp expect actual &&
934 test_must_fail git rev-parse --verify -q $c
935'
936
937test_expect_success 'stdin -z update refs fails with wrong old value' '
938 git update-ref $c $m &&
939 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
940 test_must_fail git update-ref -z --stdin <stdin 2>err &&
941 grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
942 git rev-parse $m >expect &&
943 git rev-parse $a >actual &&
944 test_cmp expect actual &&
945 git rev-parse $b >actual &&
946 test_cmp expect actual &&
947 git rev-parse $c >actual &&
948 test_cmp expect actual
949'
950
951test_expect_success 'stdin -z delete refs works with packed and loose refs' '
952 git pack-refs --all &&
953 git update-ref $c $m~1 &&
954 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
955 git update-ref -z --stdin <stdin &&
956 test_must_fail git rev-parse --verify -q $a &&
957 test_must_fail git rev-parse --verify -q $b &&
958 test_must_fail git rev-parse --verify -q $c
959'
960
961test_done