]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1400-update-ref.sh
Git 2.30-rc0
[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
8125a58b 9Z=$ZERO_OID
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
1cec9c2d
KM
38test_expect_success "create $m" '
39 git update-ref $m $A &&
cdb73ca5 40 test $A = $(git show-ref -s --verify $m)
1cec9c2d
KM
41'
42test_expect_success "create $m with oldvalue verification" '
43 git update-ref $m $B $A &&
cdb73ca5 44 test $B = $(git show-ref -s --verify $m)
1cec9c2d 45'
40672a19
KW
46test_expect_success "fail to delete $m with stale ref" '
47 test_must_fail git update-ref -d $m $A &&
cdb73ca5 48 test $B = "$(git show-ref -s --verify $m)"
40672a19
KW
49'
50test_expect_success "delete $m" '
c0e17261 51 test_when_finished "git update-ref -d $m" &&
40672a19 52 git update-ref -d $m $B &&
c0e17261 53 test_must_fail git show-ref --verify -q $m
40672a19 54'
6de08ae6 55
2405ed07 56test_expect_success "delete $m without oldvalue verification" '
c0e17261 57 test_when_finished "git update-ref -d $m" &&
3fe8dce6 58 git update-ref $m $A &&
cdb73ca5 59 test $A = $(git show-ref -s --verify $m) &&
3fe8dce6 60 git update-ref -d $m &&
c0e17261 61 test_must_fail git show-ref --verify -q $m
2405ed07 62'
3fe8dce6 63
2405ed07
KM
64test_expect_success "fail to create $n" '
65 test_when_finished "rm -f .git/$n_dir" &&
66 touch .git/$n_dir &&
67 test_must_fail git update-ref $n $A
68'
818f477c 69
1cec9c2d
KM
70test_expect_success "create $m (by HEAD)" '
71 git update-ref HEAD $A &&
cdb73ca5 72 test $A = $(git show-ref -s --verify $m)
1cec9c2d
KM
73'
74test_expect_success "create $m (by HEAD) with oldvalue verification" '
75 git update-ref HEAD $B $A &&
cdb73ca5 76 test $B = $(git show-ref -s --verify $m)
1cec9c2d 77'
40672a19
KW
78test_expect_success "fail to delete $m (by HEAD) with stale ref" '
79 test_must_fail git update-ref -d HEAD $A &&
cdb73ca5 80 test $B = $(git show-ref -s --verify $m)
40672a19
KW
81'
82test_expect_success "delete $m (by HEAD)" '
c0e17261 83 test_when_finished "git update-ref -d $m" &&
40672a19 84 git update-ref -d HEAD $B &&
c0e17261 85 test_must_fail git show-ref --verify -q $m
40672a19 86'
6de08ae6 87
de922669 88test_expect_success "deleting current branch adds message to HEAD's log" '
c0e17261 89 test_when_finished "git update-ref -d $m" &&
de922669
KM
90 git update-ref $m $A &&
91 git symbolic-ref HEAD $m &&
92 git update-ref -m delete-$m -d $m &&
c0e17261 93 test_must_fail git show-ref --verify -q $m &&
de922669
KM
94 grep "delete-$m$" .git/logs/HEAD
95'
de922669
KM
96
97test_expect_success "deleting by HEAD adds message to HEAD's log" '
c0e17261 98 test_when_finished "git update-ref -d $m" &&
de922669
KM
99 git update-ref $m $A &&
100 git symbolic-ref HEAD $m &&
101 git update-ref -m delete-by-head -d HEAD &&
c0e17261 102 test_must_fail git show-ref --verify -q $m &&
de922669
KM
103 grep "delete-by-head$" .git/logs/HEAD
104'
de922669 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
09743417 163test_expect_success 'core.logAllRefUpdates=always creates reflog for ORIG_HEAD' '
341fb286
CW
164 test_config core.logAllRefUpdates always &&
165 git update-ref ORIG_HEAD $A &&
09743417 166 git reflog exists ORIG_HEAD
341fb286
CW
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
1cec9c2d
KM
179test_expect_success "create $m (by HEAD)" '
180 git update-ref HEAD $A &&
cdb73ca5 181 test $A = $(git show-ref -s --verify $m)
1cec9c2d
KM
182'
183test_expect_success 'pack refs' '
184 git pack-refs --all
185'
186test_expect_success "move $m (by HEAD)" '
187 git update-ref HEAD $B $A &&
cdb73ca5 188 test $B = $(git show-ref -s --verify $m)
1cec9c2d 189'
b274a714 190test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" '
c0e17261 191 test_when_finished "git update-ref -d $m" &&
75c96e05
JH
192 git update-ref -d HEAD $B &&
193 ! grep "$m" .git/packed-refs &&
c0e17261 194 test_must_fail git show-ref --verify -q $m
75c96e05 195'
75c96e05 196
1cec9c2d 197test_expect_success 'delete symref without dereference' '
c0e17261
PS
198 test_when_finished "git update-ref -d $m" &&
199 echo foo >foo.c &&
200 git add foo.c &&
201 git commit -m foo &&
202 git symbolic-ref SYMREF $m &&
203 git update-ref --no-deref -d SYMREF &&
204 git show-ref --verify -q $m &&
205 test_must_fail git show-ref --verify -q SYMREF &&
206 test_must_fail git symbolic-ref SYMREF
569740bd 207'
569740bd 208
1cec9c2d 209test_expect_success 'delete symref without dereference when the referred ref is packed' '
c0e17261 210 test_when_finished "git update-ref -d $m" &&
045a476f
MV
211 echo foo >foo.c &&
212 git add foo.c &&
213 git commit -m foo &&
c0e17261 214 git symbolic-ref SYMREF $m &&
045a476f 215 git pack-refs --all &&
c0e17261
PS
216 git update-ref --no-deref -d SYMREF &&
217 git show-ref --verify -q $m &&
218 test_must_fail git show-ref --verify -q SYMREF &&
219 test_must_fail git symbolic-ref SYMREF
045a476f 220'
2405ed07 221
62a2d525
JN
222test_expect_success 'update-ref -d is not confused by self-reference' '
223 git symbolic-ref refs/heads/self refs/heads/self &&
224 test_when_finished "rm -f .git/refs/heads/self" &&
225 test_path_is_file .git/refs/heads/self &&
226 test_must_fail git update-ref -d refs/heads/self &&
227 test_path_is_file .git/refs/heads/self
228'
229
230test_expect_success 'update-ref --no-deref -d can delete self-reference' '
231 git symbolic-ref refs/heads/self refs/heads/self &&
232 test_when_finished "rm -f .git/refs/heads/self" &&
233 test_path_is_file .git/refs/heads/self &&
234 git update-ref --no-deref -d refs/heads/self &&
c0e17261 235 test_must_fail git show-ref --verify -q refs/heads/self
62a2d525
JN
236'
237
238test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
239 >.git/refs/heads/bad &&
240 test_when_finished "rm -f .git/refs/heads/bad" &&
241 git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
c0e17261 242 test_when_finished "git update-ref -d refs/heads/ref-to-bad" &&
62a2d525
JN
243 test_path_is_file .git/refs/heads/ref-to-bad &&
244 git update-ref --no-deref -d refs/heads/ref-to-bad &&
c0e17261 245 test_must_fail git show-ref --verify -q refs/heads/ref-to-bad
62a2d525
JN
246'
247
1cec9c2d 248test_expect_success '(not) create HEAD with old sha1' '
d492b31c 249 test_must_fail git update-ref HEAD $A $B
1cec9c2d 250'
2405ed07 251test_expect_success "(not) prior created .git/$m" '
c0e17261
PS
252 test_when_finished "git update-ref -d $m" &&
253 test_must_fail git show-ref --verify -q $m
2405ed07 254'
6de08ae6 255
1cec9c2d
KM
256test_expect_success 'create HEAD' '
257 git update-ref HEAD $A
258'
259test_expect_success '(not) change HEAD with wrong SHA1' '
d492b31c 260 test_must_fail git update-ref HEAD $B $Z
1cec9c2d 261'
2405ed07 262test_expect_success "(not) changed .git/$m" '
c0e17261 263 test_when_finished "git update-ref -d $m" &&
cdb73ca5 264 ! test $B = $(git show-ref -s --verify $m)
41ac414e 265'
6de08ae6 266
d0ab0584 267rm -f .git/logs/refs/heads/master
1cec9c2d
KM
268test_expect_success "create $m (logged by touch)" '
269 test_config core.logAllRefUpdates false &&
270 GIT_COMMITTER_DATE="2005-05-26 23:30" \
271 git update-ref --create-reflog HEAD $A -m "Initial Creation" &&
cdb73ca5 272 test $A = $(git show-ref -s --verify $m)
1cec9c2d
KM
273'
274test_expect_success "update $m (logged by touch)" '
275 test_config core.logAllRefUpdates false &&
276 GIT_COMMITTER_DATE="2005-05-26 23:31" \
277 git update-ref HEAD $B $A -m "Switch" &&
cdb73ca5 278 test $B = $(git show-ref -s --verify $m)
1cec9c2d
KM
279'
280test_expect_success "set $m (logged by touch)" '
281 test_config core.logAllRefUpdates false &&
282 GIT_COMMITTER_DATE="2005-05-26 23:41" \
283 git update-ref HEAD $A &&
cdb73ca5 284 test $A = $(git show-ref -s --verify $m)
1cec9c2d
KM
285'
286
287test_expect_success 'empty directory removal' '
44639777
MH
288 git branch d1/d2/r1 HEAD &&
289 git branch d1/r2 HEAD &&
cd81af4b
KM
290 test_path_is_file .git/refs/heads/d1/d2/r1 &&
291 test_path_is_file .git/logs/refs/heads/d1/d2/r1 &&
44639777 292 git branch -d d1/d2/r1 &&
c0e17261
PS
293 test_must_fail git show-ref --verify -q refs/heads/d1/d2 &&
294 test_must_fail git show-ref --verify -q logs/refs/heads/d1/d2 &&
cd81af4b
KM
295 test_path_is_file .git/refs/heads/d1/r2 &&
296 test_path_is_file .git/logs/refs/heads/d1/r2
44639777
MH
297'
298
1cec9c2d 299test_expect_success 'symref empty directory removal' '
44639777
MH
300 git branch e1/e2/r1 HEAD &&
301 git branch e1/r2 HEAD &&
302 git checkout e1/e2/r1 &&
303 test_when_finished "git checkout master" &&
cd81af4b
KM
304 test_path_is_file .git/refs/heads/e1/e2/r1 &&
305 test_path_is_file .git/logs/refs/heads/e1/e2/r1 &&
44639777 306 git update-ref -d HEAD &&
c0e17261
PS
307 test_must_fail git show-ref --verify -q refs/heads/e1/e2 &&
308 test_must_fail git show-ref --verify -q logs/refs/heads/e1/e2 &&
cd81af4b
KM
309 test_path_is_file .git/refs/heads/e1/r2 &&
310 test_path_is_file .git/logs/refs/heads/e1/r2 &&
311 test_path_is_file .git/logs/HEAD
44639777
MH
312'
313
6de08ae6
SP
314cat >expect <<EOF
315$Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creation
316$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
317$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
318EOF
2405ed07
KM
319test_expect_success "verifying $m's log (logged by touch)" '
320 test_when_finished "rm -rf .git/$m .git/logs expect" &&
321 test_cmp expect .git/logs/$m
322'
6de08ae6 323
1cec9c2d
KM
324test_expect_success "create $m (logged by config)" '
325 test_config core.logAllRefUpdates true &&
326 GIT_COMMITTER_DATE="2005-05-26 23:32" \
327 git update-ref HEAD $A -m "Initial Creation" &&
cdb73ca5 328 test $A = $(git show-ref -s --verify $m)
1cec9c2d
KM
329'
330test_expect_success "update $m (logged by config)" '
331 test_config core.logAllRefUpdates true &&
332 GIT_COMMITTER_DATE="2005-05-26 23:33" \
c76b84a1 333 git update-ref HEAD $B $A -m "Switch" &&
cdb73ca5 334 test $B = $(git show-ref -s --verify $m)
1cec9c2d
KM
335'
336test_expect_success "set $m (logged by config)" '
337 test_config core.logAllRefUpdates true &&
338 GIT_COMMITTER_DATE="2005-05-26 23:43" \
339 git update-ref HEAD $A &&
cdb73ca5 340 test $A = $(git show-ref -s --verify $m)
1cec9c2d 341'
6de08ae6
SP
342
343cat >expect <<EOF
344$Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000 Initial Creation
345$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
346$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
347EOF
1cec9c2d
KM
348test_expect_success "verifying $m's log (logged by config)" '
349 test_when_finished "rm -f .git/$m .git/logs/$m expect" &&
350 test_cmp expect .git/logs/$m
351'
6de08ae6 352
3ce47211
JS
353test_expect_success 'set up for querying the reflog' '
354 git update-ref $m $D &&
355 cat >.git/logs/$m <<-EOF
356 $Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
357 $C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
358 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
359 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
360 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
361 EOF
362'
e5229042
SP
363
364ed="Thu, 26 May 2005 18:32:00 -0500"
365gd="Thu, 26 May 2005 18:33:00 -0500"
366ld="Thu, 26 May 2005 18:43:00 -0500"
1cec9c2d
KM
367test_expect_success 'Query "master@{May 25 2005}" (before history)' '
368 test_when_finished "rm -f o e" &&
369 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
e5d7b2f6
JK
370 echo "$C" >expect &&
371 test_cmp expect o &&
b0418303
JK
372 echo "warning: log for '\''master'\'' only goes back to $ed" >expect &&
373 test_i18ncmp expect e
1cec9c2d
KM
374'
375test_expect_success 'Query master@{2005-05-25} (before history)' '
376 test_when_finished "rm -f o e" &&
377 git rev-parse --verify master@{2005-05-25} >o 2>e &&
e5d7b2f6
JK
378 echo "$C" >expect &&
379 test_cmp expect o &&
b0418303
JK
380 echo "warning: log for '\''master'\'' only goes back to $ed" >expect &&
381 test_i18ncmp expect e
1cec9c2d
KM
382'
383test_expect_success 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' '
384 test_when_finished "rm -f o e" &&
385 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
e5d7b2f6
JK
386 echo "$C" >expect &&
387 test_cmp expect o &&
b0418303
JK
388 echo "warning: log for '\''master'\'' only goes back to $ed" >expect &&
389 test_i18ncmp expect e
1cec9c2d
KM
390'
391test_expect_success 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' '
392 test_when_finished "rm -f o e" &&
393 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
e5d7b2f6
JK
394 echo "$C" >expect &&
395 test_cmp expect o &&
c93a5aae 396 test_must_be_empty e
1cec9c2d
KM
397'
398test_expect_success 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' '
399 test_when_finished "rm -f o e" &&
400 git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e &&
e5d7b2f6
JK
401 echo "$A" >expect &&
402 test_cmp expect o &&
c93a5aae 403 test_must_be_empty e
1cec9c2d
KM
404'
405test_expect_success 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' '
406 test_when_finished "rm -f o e" &&
407 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
e5d7b2f6
JK
408 echo "$B" >expect &&
409 test_cmp expect o &&
661558f0 410 test_i18ngrep -F "warning: log for ref $m has gap after $gd" e
1cec9c2d
KM
411'
412test_expect_success 'Query "master@{2005-05-26 23:38:00}" (middle of history)' '
413 test_when_finished "rm -f o e" &&
414 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
e5d7b2f6
JK
415 echo "$Z" >expect &&
416 test_cmp expect o &&
c93a5aae 417 test_must_be_empty e
1cec9c2d
KM
418'
419test_expect_success 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' '
420 test_when_finished "rm -f o e" &&
421 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
e5d7b2f6
JK
422 echo "$E" >expect &&
423 test_cmp expect o &&
c93a5aae 424 test_must_be_empty e
1cec9c2d
KM
425'
426test_expect_success 'Query "master@{2005-05-28}" (past end of history)' '
427 test_when_finished "rm -f o e" &&
428 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
e5d7b2f6
JK
429 echo "$D" >expect &&
430 test_cmp expect o &&
661558f0 431 test_i18ngrep -F "warning: log for ref $m unexpectedly ended on $ld" e
1cec9c2d 432'
cce91a2c
SP
433
434rm -f .git/$m .git/logs/$m expect
435
1cec9c2d
KM
436test_expect_success 'creating initial files' '
437 test_when_finished rm -f M &&
438 echo TEST >F &&
439 git add F &&
440 GIT_AUTHOR_DATE="2005-05-26 23:30" \
441 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
442 h_TEST=$(git rev-parse --verify HEAD) &&
443 echo The other day this did not work. >M &&
444 echo And then Bob told me how to fix it. >>M &&
445 echo OTHER >F &&
446 GIT_AUTHOR_DATE="2005-05-26 23:41" \
447 GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a &&
448 h_OTHER=$(git rev-parse --verify HEAD) &&
449 GIT_AUTHOR_DATE="2005-05-26 23:44" \
450 GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend &&
451 h_FIXED=$(git rev-parse --verify HEAD) &&
452 echo Merged initial commit and a later commit. >M &&
453 echo $h_TEST >.git/MERGE_HEAD &&
454 GIT_AUTHOR_DATE="2005-05-26 23:45" \
455 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
456 h_MERGED=$(git rev-parse --verify HEAD)
457'
9c7466fa
SP
458
459cat >expect <<EOF
a3a733e6 460$Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add
9c7466fa 461$h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 commit: The other day this did not work.
a3a733e6
SP
462$h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 commit (amend): The other day this did not work.
463$h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
9c7466fa 464EOF
1cec9c2d
KM
465test_expect_success 'git commit logged updates' '
466 test_cmp expect .git/logs/$m
467'
a3a733e6 468unset h_TEST h_OTHER h_FIXED h_MERGED
cce91a2c 469
1cec9c2d
KM
470test_expect_success 'git cat-file blob master:F (expect OTHER)' '
471 test OTHER = $(git cat-file blob master:F)
472'
473test_expect_success 'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' '
474 test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")
475'
476test_expect_success 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' '
477 test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")
478'
cce91a2c 479
65eb8fc3
480# Test adding and deleting pseudorefs
481
482test_expect_success 'given old value for missing pseudoref, do not create' '
483 test_must_fail git update-ref PSEUDOREF $A $B 2>err &&
0b7de6c6 484 test_must_fail git rev-parse PSEUDOREF &&
09743417 485 test_i18ngrep "unable to resolve reference" err
65eb8fc3
486'
487
488test_expect_success 'create pseudoref' '
489 git update-ref PSEUDOREF $A &&
0b7de6c6 490 test $A = $(git rev-parse PSEUDOREF)
65eb8fc3
491'
492
493test_expect_success 'overwrite pseudoref with no old value given' '
494 git update-ref PSEUDOREF $B &&
0b7de6c6 495 test $B = $(git rev-parse PSEUDOREF)
65eb8fc3
496'
497
498test_expect_success 'overwrite pseudoref with correct old value' '
499 git update-ref PSEUDOREF $C $B &&
0b7de6c6 500 test $C = $(git rev-parse PSEUDOREF)
65eb8fc3
501'
502
503test_expect_success 'do not overwrite pseudoref with wrong old value' '
504 test_must_fail git update-ref PSEUDOREF $D $E 2>err &&
0b7de6c6 505 test $C = $(git rev-parse PSEUDOREF) &&
09743417 506 test_i18ngrep "cannot lock ref.*expected" err
65eb8fc3
507'
508
509test_expect_success 'delete pseudoref' '
510 git update-ref -d PSEUDOREF &&
0b7de6c6 511 test_must_fail git rev-parse PSEUDOREF
65eb8fc3
512'
513
514test_expect_success 'do not delete pseudoref with wrong old value' '
515 git update-ref PSEUDOREF $A &&
516 test_must_fail git update-ref -d PSEUDOREF $B 2>err &&
0b7de6c6 517 test $A = $(git rev-parse PSEUDOREF) &&
09743417 518 test_i18ngrep "cannot lock ref.*expected" err
65eb8fc3
519'
520
521test_expect_success 'delete pseudoref with correct old value' '
522 git update-ref -d PSEUDOREF $A &&
0b7de6c6 523 test_must_fail git rev-parse PSEUDOREF
65eb8fc3
524'
525
db0210d4 526test_expect_success 'create pseudoref with old OID zero' '
65eb8fc3 527 git update-ref PSEUDOREF $A $Z &&
0b7de6c6 528 test $A = $(git rev-parse PSEUDOREF)
65eb8fc3
529'
530
db0210d4 531test_expect_success 'do not overwrite pseudoref with old OID zero' '
65eb8fc3
532 test_when_finished git update-ref -d PSEUDOREF &&
533 test_must_fail git update-ref PSEUDOREF $B $Z 2>err &&
0b7de6c6 534 test $A = $(git rev-parse PSEUDOREF) &&
661558f0 535 test_i18ngrep "already exists" err
65eb8fc3
536'
537
538# Test --stdin
539
c6268bc0
BK
540a=refs/heads/a
541b=refs/heads/b
542c=refs/heads/c
543E='""'
544F='%s\0'
545pws='path with space'
546
547test_expect_success 'stdin test setup' '
548 echo "$pws" >"$pws" &&
549 git add -- "$pws" &&
550 git commit -m "$pws"
551'
552
553test_expect_success '-z fails without --stdin' '
554 test_must_fail git update-ref -z $m $m $m 2>err &&
1edbaac3 555 test_i18ngrep "usage: git update-ref" err
c6268bc0
BK
556'
557
558test_expect_success 'stdin works with no input' '
559 >stdin &&
560 git update-ref --stdin <stdin &&
561 git rev-parse --verify -q $m
562'
563
564test_expect_success 'stdin fails on empty line' '
565 echo "" >stdin &&
566 test_must_fail git update-ref --stdin <stdin 2>err &&
567 grep "fatal: empty command in input" err
568'
569
570test_expect_success 'stdin fails on only whitespace' '
571 echo " " >stdin &&
572 test_must_fail git update-ref --stdin <stdin 2>err &&
573 grep "fatal: whitespace before command: " err
574'
575
576test_expect_success 'stdin fails on leading whitespace' '
577 echo " create $a $m" >stdin &&
578 test_must_fail git update-ref --stdin <stdin 2>err &&
579 grep "fatal: whitespace before command: create $a $m" err
580'
581
582test_expect_success 'stdin fails on unknown command' '
583 echo "unknown $a" >stdin &&
584 test_must_fail git update-ref --stdin <stdin 2>err &&
585 grep "fatal: unknown command: unknown $a" err
586'
587
20fcffcc 588test_expect_success 'stdin fails on unbalanced quotes' '
c6268bc0
BK
589 echo "create $a \"master" >stdin &&
590 test_must_fail git update-ref --stdin <stdin 2>err &&
591 grep "fatal: badly quoted argument: \\\"master" err
592'
593
3224b0f0
JS
594test_expect_success PREPARE_FOR_MAIN_BRANCH 'stdin fails on invalid escape' '
595 echo "create $a \"ma\zn\"" >stdin &&
20fcffcc 596 test_must_fail git update-ref --stdin <stdin 2>err &&
3224b0f0 597 grep "fatal: badly quoted argument: \\\"ma\\\\zn\\\"" err
20fcffcc
MH
598'
599
697a4151 600test_expect_success 'stdin fails on junk after quoted argument' '
c6268bc0
BK
601 echo "create \"$a\"master" >stdin &&
602 test_must_fail git update-ref --stdin <stdin 2>err &&
697a4151 603 grep "fatal: unexpected character after quoted argument: \\\"$a\\\"master" err
c6268bc0
BK
604'
605
606test_expect_success 'stdin fails create with no ref' '
607 echo "create " >stdin &&
608 test_must_fail git update-ref --stdin <stdin 2>err &&
f11b09fb 609 grep "fatal: create: missing <ref>" err
c6268bc0
BK
610'
611
c6268bc0
BK
612test_expect_success 'stdin fails create with no new value' '
613 echo "create $a" >stdin &&
614 test_must_fail git update-ref --stdin <stdin 2>err &&
f11b09fb 615 grep "fatal: create $a: missing <newvalue>" err
c6268bc0
BK
616'
617
618test_expect_success 'stdin fails create with too many arguments' '
619 echo "create $a $m $m" >stdin &&
620 test_must_fail git update-ref --stdin <stdin 2>err &&
f11b09fb 621 grep "fatal: create $a: extra input: $m" err
c6268bc0
BK
622'
623
624test_expect_success 'stdin fails update with no ref' '
625 echo "update " >stdin &&
626 test_must_fail git update-ref --stdin <stdin 2>err &&
f11b09fb 627 grep "fatal: update: missing <ref>" err
c6268bc0
BK
628'
629
c6268bc0
BK
630test_expect_success 'stdin fails update with no new value' '
631 echo "update $a" >stdin &&
632 test_must_fail git update-ref --stdin <stdin 2>err &&
f11b09fb 633 grep "fatal: update $a: missing <newvalue>" err
c6268bc0
BK
634'
635
636test_expect_success 'stdin fails update with too many arguments' '
637 echo "update $a $m $m $m" >stdin &&
638 test_must_fail git update-ref --stdin <stdin 2>err &&
f11b09fb 639 grep "fatal: update $a: extra input: $m" err
c6268bc0
BK
640'
641
642test_expect_success 'stdin fails delete with no ref' '
643 echo "delete " >stdin &&
644 test_must_fail git update-ref --stdin <stdin 2>err &&
f11b09fb 645 grep "fatal: delete: missing <ref>" err
c6268bc0
BK
646'
647
c6268bc0
BK
648test_expect_success 'stdin fails delete with too many arguments' '
649 echo "delete $a $m $m" >stdin &&
650 test_must_fail git update-ref --stdin <stdin 2>err &&
f11b09fb 651 grep "fatal: delete $a: extra input: $m" err
c6268bc0
BK
652'
653
654test_expect_success 'stdin fails verify with too many arguments' '
655 echo "verify $a $m $m" >stdin &&
656 test_must_fail git update-ref --stdin <stdin 2>err &&
f11b09fb 657 grep "fatal: verify $a: extra input: $m" err
c6268bc0
BK
658'
659
660test_expect_success 'stdin fails option with unknown name' '
661 echo "option unknown" >stdin &&
662 test_must_fail git update-ref --stdin <stdin 2>err &&
663 grep "fatal: option unknown: unknown" err
664'
665
666test_expect_success 'stdin fails with duplicate refs' '
667 cat >stdin <<-EOF &&
668 create $a $m
669 create $b $m
670 create $a $m
671 EOF
672 test_must_fail git update-ref --stdin <stdin 2>err &&
661558f0 673 test_i18ngrep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
c6268bc0
BK
674'
675
676test_expect_success 'stdin create ref works' '
677 echo "create $a $m" >stdin &&
678 git update-ref --stdin <stdin &&
679 git rev-parse $m >expect &&
680 git rev-parse $a >actual &&
681 test_cmp expect actual
682'
683
144c76fa
DT
684test_expect_success 'stdin does not create reflogs by default' '
685 test_when_finished "git update-ref -d $outside" &&
686 echo "create $outside $m" >stdin &&
687 git update-ref --stdin <stdin &&
688 git rev-parse $m >expect &&
689 git rev-parse $outside >actual &&
690 test_cmp expect actual &&
691 test_must_fail git reflog exists $outside
692'
693
694test_expect_success 'stdin creates reflogs with --create-reflog' '
341fb286 695 test_when_finished "git update-ref -d $outside" &&
144c76fa
DT
696 echo "create $outside $m" >stdin &&
697 git update-ref --create-reflog --stdin <stdin &&
698 git rev-parse $m >expect &&
699 git rev-parse $outside >actual &&
700 test_cmp expect actual &&
701 git reflog exists $outside
702'
703
20fcffcc
MH
704test_expect_success 'stdin succeeds with quoted argument' '
705 git update-ref -d $a &&
706 echo "create $a \"$m\"" >stdin &&
707 git update-ref --stdin <stdin &&
708 git rev-parse $m >expect &&
709 git rev-parse $a >actual &&
710 test_cmp expect actual
711'
712
3224b0f0 713test_expect_success PREPARE_FOR_MAIN_BRANCH 'stdin succeeds with escaped character' '
20fcffcc 714 git update-ref -d $a &&
3224b0f0 715 echo "create $a \"ma\\151n\"" >stdin &&
20fcffcc
MH
716 git update-ref --stdin <stdin &&
717 git rev-parse $m >expect &&
718 git rev-parse $a >actual &&
719 test_cmp expect actual
720'
721
c6268bc0
BK
722test_expect_success 'stdin update ref creates with zero old value' '
723 echo "update $b $m $Z" >stdin &&
724 git update-ref --stdin <stdin &&
725 git rev-parse $m >expect &&
726 git rev-parse $b >actual &&
727 test_cmp expect actual &&
728 git update-ref -d $b
729'
730
731test_expect_success 'stdin update ref creates with empty old value' '
732 echo "update $b $m $E" >stdin &&
733 git update-ref --stdin <stdin &&
734 git rev-parse $m >expect &&
735 git rev-parse $b >actual &&
736 test_cmp expect actual
737'
738
739test_expect_success 'stdin create ref works with path with space to blob' '
740 echo "create refs/blobs/pws \"$m:$pws\"" >stdin &&
741 git update-ref --stdin <stdin &&
742 git rev-parse "$m:$pws" >expect &&
743 git rev-parse refs/blobs/pws >actual &&
744 test_cmp expect actual &&
745 git update-ref -d refs/blobs/pws
746'
747
748test_expect_success 'stdin update ref fails with wrong old value' '
749 echo "update $c $m $m~1" >stdin &&
750 test_must_fail git update-ref --stdin <stdin 2>err &&
c2e0a718 751 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
c6268bc0
BK
752 test_must_fail git rev-parse --verify -q $c
753'
754
755test_expect_success 'stdin update ref fails with bad old value' '
756 echo "update $c $m does-not-exist" >stdin &&
757 test_must_fail git update-ref --stdin <stdin 2>err &&
9255f059 758 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
c6268bc0
BK
759 test_must_fail git rev-parse --verify -q $c
760'
761
762test_expect_success 'stdin create ref fails with bad new value' '
763 echo "create $c does-not-exist" >stdin &&
764 test_must_fail git update-ref --stdin <stdin 2>err &&
9255f059 765 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
c6268bc0
BK
766 test_must_fail git rev-parse --verify -q $c
767'
768
769test_expect_success 'stdin create ref fails with zero new value' '
770 echo "create $c " >stdin &&
771 test_must_fail git update-ref --stdin <stdin 2>err &&
f11b09fb 772 grep "fatal: create $c: zero <newvalue>" err &&
c6268bc0
BK
773 test_must_fail git rev-parse --verify -q $c
774'
775
776test_expect_success 'stdin update ref works with right old value' '
777 echo "update $b $m~1 $m" >stdin &&
778 git update-ref --stdin <stdin &&
779 git rev-parse $m~1 >expect &&
780 git rev-parse $b >actual &&
781 test_cmp expect actual
782'
783
784test_expect_success 'stdin delete ref fails with wrong old value' '
785 echo "delete $a $m~1" >stdin &&
786 test_must_fail git update-ref --stdin <stdin 2>err &&
c2e0a718 787 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
c6268bc0
BK
788 git rev-parse $m >expect &&
789 git rev-parse $a >actual &&
790 test_cmp expect actual
791'
792
793test_expect_success 'stdin delete ref fails with zero old value' '
794 echo "delete $a " >stdin &&
795 test_must_fail git update-ref --stdin <stdin 2>err &&
f11b09fb 796 grep "fatal: delete $a: zero <oldvalue>" err &&
c6268bc0
BK
797 git rev-parse $m >expect &&
798 git rev-parse $a >actual &&
799 test_cmp expect actual
800'
801
802test_expect_success 'stdin update symref works option no-deref' '
803 git symbolic-ref TESTSYMREF $b &&
804 cat >stdin <<-EOF &&
805 option no-deref
806 update TESTSYMREF $a $b
807 EOF
808 git update-ref --stdin <stdin &&
809 git rev-parse TESTSYMREF >expect &&
810 git rev-parse $a >actual &&
811 test_cmp expect actual &&
812 git rev-parse $m~1 >expect &&
813 git rev-parse $b >actual &&
814 test_cmp expect actual
815'
816
817test_expect_success 'stdin delete symref works option no-deref' '
818 git symbolic-ref TESTSYMREF $b &&
819 cat >stdin <<-EOF &&
820 option no-deref
821 delete TESTSYMREF $b
822 EOF
823 git update-ref --stdin <stdin &&
824 test_must_fail git rev-parse --verify -q TESTSYMREF &&
825 git rev-parse $m~1 >expect &&
826 git rev-parse $b >actual &&
827 test_cmp expect actual
828'
829
d345e9fb
EN
830test_expect_success 'stdin update symref works flag --no-deref' '
831 git symbolic-ref TESTSYMREFONE $b &&
832 git symbolic-ref TESTSYMREFTWO $b &&
833 cat >stdin <<-EOF &&
834 update TESTSYMREFONE $a $b
835 update TESTSYMREFTWO $a $b
836 EOF
837 git update-ref --no-deref --stdin <stdin &&
838 git rev-parse TESTSYMREFONE TESTSYMREFTWO >expect &&
839 git rev-parse $a $a >actual &&
840 test_cmp expect actual &&
841 git rev-parse $m~1 >expect &&
842 git rev-parse $b >actual &&
843 test_cmp expect actual
844'
845
846test_expect_success 'stdin delete symref works flag --no-deref' '
847 git symbolic-ref TESTSYMREFONE $b &&
848 git symbolic-ref TESTSYMREFTWO $b &&
849 cat >stdin <<-EOF &&
850 delete TESTSYMREFONE $b
851 delete TESTSYMREFTWO $b
852 EOF
853 git update-ref --no-deref --stdin <stdin &&
854 test_must_fail git rev-parse --verify -q TESTSYMREFONE &&
855 test_must_fail git rev-parse --verify -q TESTSYMREFTWO &&
856 git rev-parse $m~1 >expect &&
857 git rev-parse $b >actual &&
858 test_cmp expect actual
859'
860
c6268bc0
BK
861test_expect_success 'stdin delete ref works with right old value' '
862 echo "delete $b $m~1" >stdin &&
863 git update-ref --stdin <stdin &&
864 test_must_fail git rev-parse --verify -q $b
865'
866
867test_expect_success 'stdin update/create/verify combination works' '
868 cat >stdin <<-EOF &&
869 update $a $m
870 create $b $m
871 verify $c
872 EOF
873 git update-ref --stdin <stdin &&
874 git rev-parse $m >expect &&
875 git rev-parse $a >actual &&
876 test_cmp expect actual &&
877 git rev-parse $b >actual &&
878 test_cmp expect actual &&
879 test_must_fail git rev-parse --verify -q $c
880'
881
a46e41fc
MH
882test_expect_success 'stdin verify succeeds for correct value' '
883 git rev-parse $m >expect &&
884 echo "verify $m $m" >stdin &&
885 git update-ref --stdin <stdin &&
886 git rev-parse $m >actual &&
887 test_cmp expect actual
888'
889
890test_expect_success 'stdin verify succeeds for missing reference' '
891 echo "verify refs/heads/missing $Z" >stdin &&
892 git update-ref --stdin <stdin &&
893 test_must_fail git rev-parse --verify -q refs/heads/missing
894'
895
896test_expect_success 'stdin verify treats no value as missing' '
897 echo "verify refs/heads/missing" >stdin &&
898 git update-ref --stdin <stdin &&
899 test_must_fail git rev-parse --verify -q refs/heads/missing
900'
901
902test_expect_success 'stdin verify fails for wrong value' '
903 git rev-parse $m >expect &&
904 echo "verify $m $m~1" >stdin &&
905 test_must_fail git update-ref --stdin <stdin &&
906 git rev-parse $m >actual &&
907 test_cmp expect actual
908'
909
910test_expect_success 'stdin verify fails for mistaken null value' '
911 git rev-parse $m >expect &&
912 echo "verify $m $Z" >stdin &&
913 test_must_fail git update-ref --stdin <stdin &&
914 git rev-parse $m >actual &&
915 test_cmp expect actual
916'
917
0e729c7e 918test_expect_success 'stdin verify fails for mistaken empty value' '
a46e41fc
MH
919 M=$(git rev-parse $m) &&
920 test_when_finished "git update-ref $m $M" &&
921 git rev-parse $m >expect &&
922 echo "verify $m" >stdin &&
923 test_must_fail git update-ref --stdin <stdin &&
924 git rev-parse $m >actual &&
925 test_cmp expect actual
926'
927
c6268bc0
BK
928test_expect_success 'stdin update refs works with identity updates' '
929 cat >stdin <<-EOF &&
930 update $a $m $m
931 update $b $m $m
932 update $c $Z $E
933 EOF
934 git update-ref --stdin <stdin &&
935 git rev-parse $m >expect &&
936 git rev-parse $a >actual &&
937 test_cmp expect actual &&
938 git rev-parse $b >actual &&
939 test_cmp expect actual &&
940 test_must_fail git rev-parse --verify -q $c
941'
942
943test_expect_success 'stdin update refs fails with wrong old value' '
944 git update-ref $c $m &&
945 cat >stdin <<-EOF &&
946 update $a $m $m
947 update $b $m $m
948 update $c ''
949 EOF
950 test_must_fail git update-ref --stdin <stdin 2>err &&
c2e0a718 951 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
c6268bc0
BK
952 git rev-parse $m >expect &&
953 git rev-parse $a >actual &&
954 test_cmp expect actual &&
955 git rev-parse $b >actual &&
956 test_cmp expect actual &&
957 git rev-parse $c >actual &&
958 test_cmp expect actual
959'
960
961test_expect_success 'stdin delete refs works with packed and loose refs' '
962 git pack-refs --all &&
963 git update-ref $c $m~1 &&
964 cat >stdin <<-EOF &&
965 delete $a $m
966 update $b $Z $m
967 update $c $E $m~1
968 EOF
969 git update-ref --stdin <stdin &&
970 test_must_fail git rev-parse --verify -q $a &&
971 test_must_fail git rev-parse --verify -q $b &&
972 test_must_fail git rev-parse --verify -q $c
973'
974
975test_expect_success 'stdin -z works on empty input' '
976 >stdin &&
977 git update-ref -z --stdin <stdin &&
978 git rev-parse --verify -q $m
979'
980
981test_expect_success 'stdin -z fails on empty line' '
982 echo "" >stdin &&
983 test_must_fail git update-ref -z --stdin <stdin 2>err &&
984 grep "fatal: whitespace before command: " err
985'
986
987test_expect_success 'stdin -z fails on empty command' '
988 printf $F "" >stdin &&
989 test_must_fail git update-ref -z --stdin <stdin 2>err &&
990 grep "fatal: empty command in input" err
991'
992
993test_expect_success 'stdin -z fails on only whitespace' '
994 printf $F " " >stdin &&
995 test_must_fail git update-ref -z --stdin <stdin 2>err &&
996 grep "fatal: whitespace before command: " err
997'
998
999test_expect_success 'stdin -z fails on leading whitespace' '
1000 printf $F " create $a" "$m" >stdin &&
1001 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1002 grep "fatal: whitespace before command: create $a" err
1003'
1004
1005test_expect_success 'stdin -z fails on unknown command' '
1006 printf $F "unknown $a" >stdin &&
1007 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1008 grep "fatal: unknown command: unknown $a" err
1009'
1010
1011test_expect_success 'stdin -z fails create with no ref' '
1012 printf $F "create " >stdin &&
1013 test_must_fail git update-ref -z --stdin <stdin 2>err &&
f11b09fb 1014 grep "fatal: create: missing <ref>" err
c6268bc0
BK
1015'
1016
c6268bc0
BK
1017test_expect_success 'stdin -z fails create with no new value' '
1018 printf $F "create $a" >stdin &&
1019 test_must_fail git update-ref -z --stdin <stdin 2>err &&
726f6916 1020 grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
c6268bc0
BK
1021'
1022
1023test_expect_success 'stdin -z fails create with too many arguments' '
1024 printf $F "create $a" "$m" "$m" >stdin &&
1025 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1026 grep "fatal: unknown command: $m" err
1027'
1028
1029test_expect_success 'stdin -z fails update with no ref' '
1030 printf $F "update " >stdin &&
1031 test_must_fail git update-ref -z --stdin <stdin 2>err &&
f11b09fb 1032 grep "fatal: update: missing <ref>" err
c6268bc0
BK
1033'
1034
ff6ee395
MH
1035test_expect_success 'stdin -z fails update with too few args' '
1036 printf $F "update $a" "$m" >stdin &&
1037 test_must_fail git update-ref -z --stdin <stdin 2>err &&
726f6916 1038 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
c6268bc0
BK
1039'
1040
1fbd5049 1041test_expect_success 'stdin -z emits warning with empty new value' '
191f241b
MH
1042 git update-ref $a $m &&
1043 printf $F "update $a" "" "" >stdin &&
1fbd5049
MH
1044 git update-ref -z --stdin <stdin 2>err &&
1045 grep "warning: update $a: missing <newvalue>, treating as zero" err &&
191f241b
MH
1046 test_must_fail git rev-parse --verify -q $a
1047'
1048
c6268bc0
BK
1049test_expect_success 'stdin -z fails update with no new value' '
1050 printf $F "update $a" >stdin &&
1051 test_must_fail git update-ref -z --stdin <stdin 2>err &&
726f6916 1052 grep "fatal: update $a: unexpected end of input when reading <newvalue>" err
c6268bc0
BK
1053'
1054
1055test_expect_success 'stdin -z fails update with no old value' '
1056 printf $F "update $a" "$m" >stdin &&
1057 test_must_fail git update-ref -z --stdin <stdin 2>err &&
726f6916 1058 grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
c6268bc0
BK
1059'
1060
1061test_expect_success 'stdin -z fails update with too many arguments' '
1062 printf $F "update $a" "$m" "$m" "$m" >stdin &&
1063 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1064 grep "fatal: unknown command: $m" err
1065'
1066
1067test_expect_success 'stdin -z fails delete with no ref' '
1068 printf $F "delete " >stdin &&
1069 test_must_fail git update-ref -z --stdin <stdin 2>err &&
f11b09fb 1070 grep "fatal: delete: missing <ref>" err
c6268bc0
BK
1071'
1072
c6268bc0
BK
1073test_expect_success 'stdin -z fails delete with no old value' '
1074 printf $F "delete $a" >stdin &&
1075 test_must_fail git update-ref -z --stdin <stdin 2>err &&
726f6916 1076 grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
c6268bc0
BK
1077'
1078
1079test_expect_success 'stdin -z fails delete with too many arguments' '
1080 printf $F "delete $a" "$m" "$m" >stdin &&
1081 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1082 grep "fatal: unknown command: $m" err
1083'
1084
1085test_expect_success 'stdin -z fails verify with too many arguments' '
1086 printf $F "verify $a" "$m" "$m" >stdin &&
1087 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1088 grep "fatal: unknown command: $m" err
1089'
1090
1091test_expect_success 'stdin -z fails verify with no old value' '
1092 printf $F "verify $a" >stdin &&
1093 test_must_fail git update-ref -z --stdin <stdin 2>err &&
726f6916 1094 grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err
c6268bc0
BK
1095'
1096
1097test_expect_success 'stdin -z fails option with unknown name' '
1098 printf $F "option unknown" >stdin &&
1099 test_must_fail git update-ref -z --stdin <stdin 2>err &&
1100 grep "fatal: option unknown: unknown" err
1101'
1102
1103test_expect_success 'stdin -z fails with duplicate refs' '
1104 printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin &&
1105 test_must_fail git update-ref -z --stdin <stdin 2>err &&
661558f0 1106 test_i18ngrep "fatal: multiple updates for ref '"'"'$a'"'"' not allowed" err
c6268bc0
BK
1107'
1108
1109test_expect_success 'stdin -z create ref works' '
1110 printf $F "create $a" "$m" >stdin &&
1111 git update-ref -z --stdin <stdin &&
1112 git rev-parse $m >expect &&
1113 git rev-parse $a >actual &&
1114 test_cmp expect actual
1115'
1116
1117test_expect_success 'stdin -z update ref creates with zero old value' '
1118 printf $F "update $b" "$m" "$Z" >stdin &&
1119 git update-ref -z --stdin <stdin &&
1120 git rev-parse $m >expect &&
1121 git rev-parse $b >actual &&
1122 test_cmp expect actual &&
1123 git update-ref -d $b
1124'
1125
1126test_expect_success 'stdin -z update ref creates with empty old value' '
1127 printf $F "update $b" "$m" "" >stdin &&
1128 git update-ref -z --stdin <stdin &&
1129 git rev-parse $m >expect &&
1130 git rev-parse $b >actual &&
1131 test_cmp expect actual
1132'
1133
1134test_expect_success 'stdin -z create ref works with path with space to blob' '
1135 printf $F "create refs/blobs/pws" "$m:$pws" >stdin &&
1136 git update-ref -z --stdin <stdin &&
1137 git rev-parse "$m:$pws" >expect &&
1138 git rev-parse refs/blobs/pws >actual &&
1139 test_cmp expect actual &&
1140 git update-ref -d refs/blobs/pws
1141'
1142
1143test_expect_success 'stdin -z update ref fails with wrong old value' '
1144 printf $F "update $c" "$m" "$m~1" >stdin &&
1145 test_must_fail git update-ref -z --stdin <stdin 2>err &&
c2e0a718 1146 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
c6268bc0
BK
1147 test_must_fail git rev-parse --verify -q $c
1148'
1149
1150test_expect_success 'stdin -z update ref fails with bad old value' '
1151 printf $F "update $c" "$m" "does-not-exist" >stdin &&
1152 test_must_fail git update-ref -z --stdin <stdin 2>err &&
9255f059 1153 grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err &&
c6268bc0
BK
1154 test_must_fail git rev-parse --verify -q $c
1155'
1156
b9d56b5d
AG
1157test_expect_success 'stdin -z create ref fails when ref exists' '
1158 git update-ref $c $m &&
1159 git rev-parse "$c" >expect &&
1160 printf $F "create $c" "$m~1" >stdin &&
1161 test_must_fail git update-ref -z --stdin <stdin 2>err &&
c2e0a718 1162 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
b9d56b5d
AG
1163 git rev-parse "$c" >actual &&
1164 test_cmp expect actual
1165'
1166
c6268bc0 1167test_expect_success 'stdin -z create ref fails with bad new value' '
b9d56b5d 1168 git update-ref -d "$c" &&
c6268bc0
BK
1169 printf $F "create $c" "does-not-exist" >stdin &&
1170 test_must_fail git update-ref -z --stdin <stdin 2>err &&
9255f059 1171 grep "fatal: create $c: invalid <newvalue>: does-not-exist" err &&
c6268bc0
BK
1172 test_must_fail git rev-parse --verify -q $c
1173'
1174
3afcc463 1175test_expect_success 'stdin -z create ref fails with empty new value' '
c6268bc0
BK
1176 printf $F "create $c" "" >stdin &&
1177 test_must_fail git update-ref -z --stdin <stdin 2>err &&
f11b09fb 1178 grep "fatal: create $c: missing <newvalue>" err &&
c6268bc0
BK
1179 test_must_fail git rev-parse --verify -q $c
1180'
1181
1182test_expect_success 'stdin -z update ref works with right old value' '
1183 printf $F "update $b" "$m~1" "$m" >stdin &&
1184 git update-ref -z --stdin <stdin &&
1185 git rev-parse $m~1 >expect &&
1186 git rev-parse $b >actual &&
1187 test_cmp expect actual
1188'
1189
1190test_expect_success 'stdin -z delete ref fails with wrong old value' '
1191 printf $F "delete $a" "$m~1" >stdin &&
1192 test_must_fail git update-ref -z --stdin <stdin 2>err &&
c2e0a718 1193 grep "fatal: cannot lock ref '"'"'$a'"'"'" err &&
c6268bc0
BK
1194 git rev-parse $m >expect &&
1195 git rev-parse $a >actual &&
1196 test_cmp expect actual
1197'
1198
1199test_expect_success 'stdin -z delete ref fails with zero old value' '
1200 printf $F "delete $a" "$Z" >stdin &&
1201 test_must_fail git update-ref -z --stdin <stdin 2>err &&
f11b09fb 1202 grep "fatal: delete $a: zero <oldvalue>" err &&
c6268bc0
BK
1203 git rev-parse $m >expect &&
1204 git rev-parse $a >actual &&
1205 test_cmp expect actual
1206'
1207
1208test_expect_success 'stdin -z update symref works option no-deref' '
1209 git symbolic-ref TESTSYMREF $b &&
1210 printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin &&
1211 git update-ref -z --stdin <stdin &&
1212 git rev-parse TESTSYMREF >expect &&
1213 git rev-parse $a >actual &&
1214 test_cmp expect actual &&
1215 git rev-parse $m~1 >expect &&
1216 git rev-parse $b >actual &&
1217 test_cmp expect actual
1218'
1219
1220test_expect_success 'stdin -z delete symref works option no-deref' '
1221 git symbolic-ref TESTSYMREF $b &&
1222 printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin &&
1223 git update-ref -z --stdin <stdin &&
1224 test_must_fail git rev-parse --verify -q TESTSYMREF &&
1225 git rev-parse $m~1 >expect &&
1226 git rev-parse $b >actual &&
1227 test_cmp expect actual
1228'
1229
1230test_expect_success 'stdin -z delete ref works with right old value' '
1231 printf $F "delete $b" "$m~1" >stdin &&
1232 git update-ref -z --stdin <stdin &&
1233 test_must_fail git rev-parse --verify -q $b
1234'
1235
1236test_expect_success 'stdin -z update/create/verify combination works' '
1237 printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin &&
1238 git update-ref -z --stdin <stdin &&
1239 git rev-parse $m >expect &&
1240 git rev-parse $a >actual &&
1241 test_cmp expect actual &&
1242 git rev-parse $b >actual &&
1243 test_cmp expect actual &&
1244 test_must_fail git rev-parse --verify -q $c
1245'
1246
a46e41fc
MH
1247test_expect_success 'stdin -z verify succeeds for correct value' '
1248 git rev-parse $m >expect &&
1249 printf $F "verify $m" "$m" >stdin &&
1250 git update-ref -z --stdin <stdin &&
1251 git rev-parse $m >actual &&
1252 test_cmp expect actual
1253'
1254
1255test_expect_success 'stdin -z verify succeeds for missing reference' '
1256 printf $F "verify refs/heads/missing" "$Z" >stdin &&
1257 git update-ref -z --stdin <stdin &&
1258 test_must_fail git rev-parse --verify -q refs/heads/missing
1259'
1260
1261test_expect_success 'stdin -z verify treats no value as missing' '
1262 printf $F "verify refs/heads/missing" "" >stdin &&
1263 git update-ref -z --stdin <stdin &&
1264 test_must_fail git rev-parse --verify -q refs/heads/missing
1265'
1266
1267test_expect_success 'stdin -z verify fails for wrong value' '
1268 git rev-parse $m >expect &&
1269 printf $F "verify $m" "$m~1" >stdin &&
1270 test_must_fail git update-ref -z --stdin <stdin &&
1271 git rev-parse $m >actual &&
1272 test_cmp expect actual
1273'
1274
1275test_expect_success 'stdin -z verify fails for mistaken null value' '
1276 git rev-parse $m >expect &&
1277 printf $F "verify $m" "$Z" >stdin &&
1278 test_must_fail git update-ref -z --stdin <stdin &&
1279 git rev-parse $m >actual &&
1280 test_cmp expect actual
1281'
1282
0e729c7e 1283test_expect_success 'stdin -z verify fails for mistaken empty value' '
a46e41fc
MH
1284 M=$(git rev-parse $m) &&
1285 test_when_finished "git update-ref $m $M" &&
1286 git rev-parse $m >expect &&
1287 printf $F "verify $m" "" >stdin &&
1288 test_must_fail git update-ref -z --stdin <stdin &&
1289 git rev-parse $m >actual &&
1290 test_cmp expect actual
1291'
1292
c6268bc0
BK
1293test_expect_success 'stdin -z update refs works with identity updates' '
1294 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
1295 git update-ref -z --stdin <stdin &&
1296 git rev-parse $m >expect &&
1297 git rev-parse $a >actual &&
1298 test_cmp expect actual &&
1299 git rev-parse $b >actual &&
1300 test_cmp expect actual &&
1301 test_must_fail git rev-parse --verify -q $c
1302'
1303
1304test_expect_success 'stdin -z update refs fails with wrong old value' '
1305 git update-ref $c $m &&
c1329110 1306 printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin &&
c6268bc0 1307 test_must_fail git update-ref -z --stdin <stdin 2>err &&
c2e0a718 1308 grep "fatal: cannot lock ref '"'"'$c'"'"'" err &&
c6268bc0
BK
1309 git rev-parse $m >expect &&
1310 git rev-parse $a >actual &&
1311 test_cmp expect actual &&
1312 git rev-parse $b >actual &&
1313 test_cmp expect actual &&
1314 git rev-parse $c >actual &&
1315 test_cmp expect actual
1316'
1317
1318test_expect_success 'stdin -z delete refs works with packed and loose refs' '
1319 git pack-refs --all &&
1320 git update-ref $c $m~1 &&
1321 printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin &&
1322 git update-ref -z --stdin <stdin &&
1323 test_must_fail git rev-parse --verify -q $a &&
1324 test_must_fail git rev-parse --verify -q $b &&
1325 test_must_fail git rev-parse --verify -q $c
1326'
1327
92b1551b
MH
1328test_expect_success 'fails with duplicate HEAD update' '
1329 git branch target1 $A &&
1330 git checkout target1 &&
1331 cat >stdin <<-EOF &&
1332 update refs/heads/target1 $C
1333 option no-deref
1334 update HEAD $B
1335 EOF
1336 test_must_fail git update-ref --stdin <stdin 2>err &&
661558f0 1337 test_i18ngrep "fatal: multiple updates for '\''HEAD'\'' (including one via its referent .refs/heads/target1.) are not allowed" err &&
92b1551b
MH
1338 echo "refs/heads/target1" >expect &&
1339 git symbolic-ref HEAD >actual &&
1340 test_cmp expect actual &&
1341 echo "$A" >expect &&
1342 git rev-parse refs/heads/target1 >actual &&
1343 test_cmp expect actual
1344'
1345
1346test_expect_success 'fails with duplicate ref update via symref' '
1347 git branch target2 $A &&
1348 git symbolic-ref refs/heads/symref2 refs/heads/target2 &&
1349 cat >stdin <<-EOF &&
1350 update refs/heads/target2 $C
1351 update refs/heads/symref2 $B
1352 EOF
1353 test_must_fail git update-ref --stdin <stdin 2>err &&
661558f0 1354 test_i18ngrep "fatal: multiple updates for '\''refs/heads/target2'\'' (including one via symref .refs/heads/symref2.) are not allowed" err &&
92b1551b
MH
1355 echo "refs/heads/target2" >expect &&
1356 git symbolic-ref refs/heads/symref2 >actual &&
1357 test_cmp expect actual &&
1358 echo "$A" >expect &&
1359 git rev-parse refs/heads/target2 >actual &&
1360 test_cmp expect actual
1361'
1362
cf018ee0 1363test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' '
d415ad02
SB
1364(
1365 for i in $(test_seq 33)
1366 do
1367 echo "create refs/heads/$i HEAD"
1368 done >large_input &&
1369 run_with_limited_open_files git update-ref --stdin <large_input &&
1370 git rev-parse --verify -q refs/heads/33
1371)
1372'
1373
cf018ee0 1374test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches does not burst open file limit' '
d415ad02
SB
1375(
1376 for i in $(test_seq 33)
1377 do
1378 echo "delete refs/heads/$i HEAD"
1379 done >large_input &&
1380 run_with_limited_open_files git update-ref --stdin <large_input &&
1381 test_must_fail git rev-parse --verify -q refs/heads/33
1382)
1383'
1384
ce414b33
DT
1385test_expect_success 'handle per-worktree refs in refs/bisect' '
1386 git commit --allow-empty -m "initial commit" &&
1387 git worktree add -b branch worktree &&
1388 (
1389 cd worktree &&
1390 git commit --allow-empty -m "test commit" &&
1391 git for-each-ref >for-each-ref.out &&
1392 ! grep refs/bisect for-each-ref.out &&
1393 git update-ref refs/bisect/something HEAD &&
1394 git rev-parse refs/bisect/something >../worktree-head &&
1395 git for-each-ref | grep refs/bisect/something
1396 ) &&
c0e17261
PS
1397 git show-ref >actual &&
1398 ! grep 'refs/bisect' actual &&
ce414b33
DT
1399 test_must_fail git rev-parse refs/bisect/something &&
1400 git update-ref refs/bisect/something HEAD &&
1401 git rev-parse refs/bisect/something >main-head &&
1402 ! test_cmp main-head worktree-head
1403'
1404
e48cf33b
PS
1405test_expect_success 'transaction handles empty commit' '
1406 cat >stdin <<-EOF &&
1407 start
1408 prepare
1409 commit
1410 EOF
1411 git update-ref --stdin <stdin >actual &&
1412 printf "%s: ok\n" start prepare commit >expect &&
1413 test_cmp expect actual
1414'
1415
1416test_expect_success 'transaction handles empty commit with missing prepare' '
1417 cat >stdin <<-EOF &&
1418 start
1419 commit
1420 EOF
1421 git update-ref --stdin <stdin >actual &&
1422 printf "%s: ok\n" start commit >expect &&
1423 test_cmp expect actual
1424'
1425
1426test_expect_success 'transaction handles sole commit' '
1427 cat >stdin <<-EOF &&
1428 commit
1429 EOF
1430 git update-ref --stdin <stdin >actual &&
1431 printf "%s: ok\n" commit >expect &&
1432 test_cmp expect actual
1433'
1434
1435test_expect_success 'transaction handles empty abort' '
1436 cat >stdin <<-EOF &&
1437 start
1438 prepare
1439 abort
1440 EOF
1441 git update-ref --stdin <stdin >actual &&
1442 printf "%s: ok\n" start prepare abort >expect &&
1443 test_cmp expect actual
1444'
1445
1446test_expect_success 'transaction exits on multiple aborts' '
1447 cat >stdin <<-EOF &&
1448 abort
1449 abort
1450 EOF
1451 test_must_fail git update-ref --stdin <stdin >actual 2>err &&
1452 printf "%s: ok\n" abort >expect &&
1453 test_cmp expect actual &&
1454 grep "fatal: transaction is closed" err
1455'
1456
1457test_expect_success 'transaction exits on start after prepare' '
1458 cat >stdin <<-EOF &&
1459 prepare
1460 start
1461 EOF
1462 test_must_fail git update-ref --stdin <stdin 2>err >actual &&
1463 printf "%s: ok\n" prepare >expect &&
1464 test_cmp expect actual &&
1465 grep "fatal: prepared transactions can only be closed" err
1466'
1467
1468test_expect_success 'transaction handles empty abort with missing prepare' '
1469 cat >stdin <<-EOF &&
1470 start
1471 abort
1472 EOF
1473 git update-ref --stdin <stdin >actual &&
1474 printf "%s: ok\n" start abort >expect &&
1475 test_cmp expect actual
1476'
1477
1478test_expect_success 'transaction handles sole abort' '
1479 cat >stdin <<-EOF &&
1480 abort
1481 EOF
1482 git update-ref --stdin <stdin >actual &&
1483 printf "%s: ok\n" abort >expect &&
1484 test_cmp expect actual
1485'
1486
1487test_expect_success 'transaction can handle commit' '
1488 cat >stdin <<-EOF &&
1489 start
1490 create $a HEAD
1491 commit
1492 EOF
1493 git update-ref --stdin <stdin >actual &&
1494 printf "%s: ok\n" start commit >expect &&
1495 test_cmp expect actual &&
1496 git rev-parse HEAD >expect &&
1497 git rev-parse $a >actual &&
1498 test_cmp expect actual
1499'
1500
1501test_expect_success 'transaction can handle abort' '
1502 cat >stdin <<-EOF &&
1503 start
1504 create $b HEAD
1505 abort
1506 EOF
1507 git update-ref --stdin <stdin >actual &&
1508 printf "%s: ok\n" start abort >expect &&
1509 test_cmp expect actual &&
c0e17261 1510 test_must_fail git show-ref --verify -q $b
e48cf33b
PS
1511'
1512
1513test_expect_success 'transaction aborts by default' '
1514 cat >stdin <<-EOF &&
1515 start
1516 create $b HEAD
1517 EOF
1518 git update-ref --stdin <stdin >actual &&
1519 printf "%s: ok\n" start >expect &&
1520 test_cmp expect actual &&
c0e17261 1521 test_must_fail git show-ref --verify -q $b
e48cf33b
PS
1522'
1523
1524test_expect_success 'transaction with prepare aborts by default' '
1525 cat >stdin <<-EOF &&
1526 start
1527 create $b HEAD
1528 prepare
1529 EOF
1530 git update-ref --stdin <stdin >actual &&
1531 printf "%s: ok\n" start prepare >expect &&
1532 test_cmp expect actual &&
c0e17261 1533 test_must_fail git show-ref --verify -q $b
e48cf33b
PS
1534'
1535
262a4d28
PS
1536test_expect_success 'transaction can commit multiple times' '
1537 cat >stdin <<-EOF &&
1538 start
1539 create refs/heads/branch-1 $A
1540 commit
1541 start
1542 create refs/heads/branch-2 $B
1543 commit
1544 EOF
1545 git update-ref --stdin <stdin >actual &&
1546 printf "%s: ok\n" start commit start commit >expect &&
1547 test_cmp expect actual &&
1548 echo "$A" >expect &&
1549 git rev-parse refs/heads/branch-1 >actual &&
1550 test_cmp expect actual &&
1551 echo "$B" >expect &&
1552 git rev-parse refs/heads/branch-2 >actual &&
1553 test_cmp expect actual
1554'
1555
1556test_expect_success 'transaction can create and delete' '
1557 cat >stdin <<-EOF &&
1558 start
1559 create refs/heads/create-and-delete $A
1560 commit
1561 start
1562 delete refs/heads/create-and-delete $A
1563 commit
1564 EOF
1565 git update-ref --stdin <stdin >actual &&
1566 printf "%s: ok\n" start commit start commit >expect &&
1567 test_must_fail git show-ref --verify refs/heads/create-and-delete
1568'
1569
1570test_expect_success 'transaction can commit after abort' '
1571 cat >stdin <<-EOF &&
1572 start
1573 create refs/heads/abort $A
1574 abort
1575 start
1576 create refs/heads/abort $A
1577 commit
1578 EOF
1579 git update-ref --stdin <stdin >actual &&
1580 printf "%s: ok\n" start abort start commit >expect &&
1581 echo "$A" >expect &&
1582 git rev-parse refs/heads/abort >actual &&
1583 test_cmp expect actual
1584'
1585
8c4417f1
PS
1586test_expect_success 'transaction cannot restart ongoing transaction' '
1587 cat >stdin <<-EOF &&
1588 start
1589 create refs/heads/restart $A
1590 start
1591 commit
1592 EOF
1593 test_must_fail git update-ref --stdin <stdin >actual &&
1594 test_must_fail git show-ref --verify refs/heads/restart
1595'
1596
6de08ae6 1597test_done