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