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