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