@@ -48,17 +48,17 @@ test_expect_success "fail to delete $m with stale ref" '
48
48
test $B = "$(git show-ref -s --verify $m)"
49
49
'
50
50
test_expect_success " delete $m " '
51
- test_when_finished "rm -f .git/ $m" &&
51
+ test_when_finished "git update-ref -d $m" &&
52
52
git update-ref -d $m $B &&
53
- test_path_is_missing . git/ $m
53
+ test_must_fail git show-ref --verify -q $m
54
54
'
55
55
56
56
test_expect_success " delete $m without oldvalue verification" '
57
- test_when_finished "rm -f .git/ $m" &&
57
+ test_when_finished "git update-ref -d $m" &&
58
58
git update-ref $m $A &&
59
59
test $A = $(git show-ref -s --verify $m) &&
60
60
git update-ref -d $m &&
61
- test_path_is_missing . git/ $m
61
+ test_must_fail git show-ref --verify -q $m
62
62
'
63
63
64
64
test_expect_success " fail to create $n " '
@@ -80,26 +80,26 @@ test_expect_success "fail to delete $m (by HEAD) with stale ref" '
80
80
test $B = $(git show-ref -s --verify $m)
81
81
'
82
82
test_expect_success " delete $m (by HEAD)" '
83
- test_when_finished "rm -f .git/ $m" &&
83
+ test_when_finished "git update-ref -d $m" &&
84
84
git update-ref -d HEAD $B &&
85
- test_path_is_missing . git/ $m
85
+ test_must_fail git show-ref --verify -q $m
86
86
'
87
87
88
88
test_expect_success " deleting current branch adds message to HEAD's log" '
89
- test_when_finished "rm -f .git/ $m" &&
89
+ test_when_finished "git update-ref -d $m" &&
90
90
git update-ref $m $A &&
91
91
git symbolic-ref HEAD $m &&
92
92
git update-ref -m delete-$m -d $m &&
93
- test_path_is_missing . git/ $m &&
93
+ test_must_fail git show-ref --verify -q $m &&
94
94
grep "delete-$m$" .git/logs/HEAD
95
95
'
96
96
97
97
test_expect_success " deleting by HEAD adds message to HEAD's log" '
98
- test_when_finished "rm -f .git/ $m" &&
98
+ test_when_finished "git update-ref -d $m" &&
99
99
git update-ref $m $A &&
100
100
git symbolic-ref HEAD $m &&
101
101
git update-ref -m delete-by-head -d HEAD &&
102
- test_path_is_missing . git/ $m &&
102
+ test_must_fail git show-ref --verify -q $m &&
103
103
grep "delete-by-head$" .git/logs/HEAD
104
104
'
105
105
@@ -188,31 +188,37 @@ test_expect_success "move $m (by HEAD)" '
188
188
test $B = $(git show-ref -s --verify $m)
189
189
'
190
190
test_expect_success " delete $m (by HEAD) should remove both packed and loose $m " '
191
- test_when_finished "rm -f .git/ $m" &&
191
+ test_when_finished "git update-ref -d $m" &&
192
192
git update-ref -d HEAD $B &&
193
193
! grep "$m" .git/packed-refs &&
194
- test_path_is_missing . git/ $m
194
+ test_must_fail git show-ref --verify -q $m
195
195
'
196
196
197
- cp -f .git/HEAD .git/HEAD.orig
198
197
test_expect_success ' delete symref without dereference' '
199
- test_when_finished "cp -f .git/HEAD.orig .git/HEAD" &&
200
- git update-ref --no-deref -d HEAD &&
201
- test_path_is_missing .git/HEAD
198
+ test_when_finished "git update-ref -d $m" &&
199
+ echo foo >foo.c &&
200
+ git add foo.c &&
201
+ git commit -m foo &&
202
+ git symbolic-ref SYMREF $m &&
203
+ git update-ref --no-deref -d SYMREF &&
204
+ git show-ref --verify -q $m &&
205
+ test_must_fail git show-ref --verify -q SYMREF &&
206
+ test_must_fail git symbolic-ref SYMREF
202
207
'
203
208
204
209
test_expect_success ' delete symref without dereference when the referred ref is packed' '
205
- test_when_finished "cp -f .git/HEAD.orig .git/HEAD " &&
210
+ test_when_finished "git update-ref -d $m " &&
206
211
echo foo >foo.c &&
207
212
git add foo.c &&
208
213
git commit -m foo &&
214
+ git symbolic-ref SYMREF $m &&
209
215
git pack-refs --all &&
210
- git update-ref --no-deref -d HEAD &&
211
- test_path_is_missing .git/HEAD
216
+ git update-ref --no-deref -d SYMREF &&
217
+ git show-ref --verify -q $m &&
218
+ test_must_fail git show-ref --verify -q SYMREF &&
219
+ test_must_fail git symbolic-ref SYMREF
212
220
'
213
221
214
- git update-ref -d $m
215
-
216
222
test_expect_success ' update-ref -d is not confused by self-reference' '
217
223
git symbolic-ref refs/heads/self refs/heads/self &&
218
224
test_when_finished "rm -f .git/refs/heads/self" &&
@@ -226,25 +232,25 @@ test_expect_success 'update-ref --no-deref -d can delete self-reference' '
226
232
test_when_finished "rm -f .git/refs/heads/self" &&
227
233
test_path_is_file .git/refs/heads/self &&
228
234
git update-ref --no-deref -d refs/heads/self &&
229
- test_path_is_missing . git/ refs/heads/self
235
+ test_must_fail git show-ref --verify -q refs/heads/self
230
236
'
231
237
232
238
test_expect_success ' update-ref --no-deref -d can delete reference to bad ref' '
233
239
>.git/refs/heads/bad &&
234
240
test_when_finished "rm -f .git/refs/heads/bad" &&
235
241
git symbolic-ref refs/heads/ref-to-bad refs/heads/bad &&
236
- test_when_finished "rm -f .git/ refs/heads/ref-to-bad" &&
242
+ test_when_finished "git update-ref -d refs/heads/ref-to-bad" &&
237
243
test_path_is_file .git/refs/heads/ref-to-bad &&
238
244
git update-ref --no-deref -d refs/heads/ref-to-bad &&
239
- test_path_is_missing . git/ refs/heads/ref-to-bad
245
+ test_must_fail git show-ref --verify -q refs/heads/ref-to-bad
240
246
'
241
247
242
248
test_expect_success ' (not) create HEAD with old sha1' '
243
249
test_must_fail git update-ref HEAD $A $B
244
250
'
245
251
test_expect_success " (not) prior created .git/$m " '
246
- test_when_finished "rm -f .git/ $m" &&
247
- test_path_is_missing . git/ $m
252
+ test_when_finished "git update-ref -d $m" &&
253
+ test_must_fail git show-ref --verify -q $m
248
254
'
249
255
250
256
test_expect_success ' create HEAD' '
@@ -254,7 +260,7 @@ test_expect_success '(not) change HEAD with wrong SHA1' '
254
260
test_must_fail git update-ref HEAD $B $Z
255
261
'
256
262
test_expect_success " (not) changed .git/$m " '
257
- test_when_finished "rm -f .git/ $m" &&
263
+ test_when_finished "git update-ref -d $m" &&
258
264
! test $B = $(git show-ref -s --verify $m)
259
265
'
260
266
@@ -284,8 +290,8 @@ test_expect_success 'empty directory removal' '
284
290
test_path_is_file .git/refs/heads/d1/d2/r1 &&
285
291
test_path_is_file .git/logs/refs/heads/d1/d2/r1 &&
286
292
git branch -d d1/d2/r1 &&
287
- test_path_is_missing . git/ refs/heads/d1/d2 &&
288
- test_path_is_missing . git/ logs/refs/heads/d1/d2 &&
293
+ test_must_fail git show-ref --verify -q refs/heads/d1/d2 &&
294
+ test_must_fail git show-ref --verify -q logs/refs/heads/d1/d2 &&
289
295
test_path_is_file .git/refs/heads/d1/r2 &&
290
296
test_path_is_file .git/logs/refs/heads/d1/r2
291
297
'
@@ -298,8 +304,8 @@ test_expect_success 'symref empty directory removal' '
298
304
test_path_is_file .git/refs/heads/e1/e2/r1 &&
299
305
test_path_is_file .git/logs/refs/heads/e1/e2/r1 &&
300
306
git update-ref -d HEAD &&
301
- test_path_is_missing . git/ refs/heads/e1/e2 &&
302
- test_path_is_missing . git/ logs/refs/heads/e1/e2 &&
307
+ test_must_fail git show-ref --verify -q refs/heads/e1/e2 &&
308
+ test_must_fail git show-ref --verify -q logs/refs/heads/e1/e2 &&
303
309
test_path_is_file .git/refs/heads/e1/r2 &&
304
310
test_path_is_file .git/logs/refs/heads/e1/r2 &&
305
311
test_path_is_file .git/logs/HEAD
@@ -1388,7 +1394,8 @@ test_expect_success 'handle per-worktree refs in refs/bisect' '
1388
1394
git rev-parse refs/bisect/something >../worktree-head &&
1389
1395
git for-each-ref | grep refs/bisect/something
1390
1396
) &&
1391
- test_path_is_missing .git/refs/bisect &&
1397
+ git show-ref >actual &&
1398
+ ! grep ' refs/bisect' actual &&
1392
1399
test_must_fail git rev-parse refs/bisect/something &&
1393
1400
git update-ref refs/bisect/something HEAD &&
1394
1401
git rev-parse refs/bisect/something >main-head &&
@@ -1500,7 +1507,7 @@ test_expect_success 'transaction can handle abort' '
1500
1507
git update-ref --stdin <stdin >actual &&
1501
1508
printf "%s: ok\n" start abort >expect &&
1502
1509
test_cmp expect actual &&
1503
- test_path_is_missing . git/ $b
1510
+ test_must_fail git show-ref --verify -q $b
1504
1511
'
1505
1512
1506
1513
test_expect_success ' transaction aborts by default' '
@@ -1511,7 +1518,7 @@ test_expect_success 'transaction aborts by default' '
1511
1518
git update-ref --stdin <stdin >actual &&
1512
1519
printf "%s: ok\n" start >expect &&
1513
1520
test_cmp expect actual &&
1514
- test_path_is_missing . git/ $b
1521
+ test_must_fail git show-ref --verify -q $b
1515
1522
'
1516
1523
1517
1524
test_expect_success ' transaction with prepare aborts by default' '
@@ -1523,7 +1530,68 @@ test_expect_success 'transaction with prepare aborts by default' '
1523
1530
git update-ref --stdin <stdin >actual &&
1524
1531
printf "%s: ok\n" start prepare >expect &&
1525
1532
test_cmp expect actual &&
1526
- test_path_is_missing .git/$b
1533
+ test_must_fail git show-ref --verify -q $b
1534
+ '
1535
+
1536
+ test_expect_success ' transaction can commit multiple times' '
1537
+ cat >stdin <<-EOF &&
1538
+ start
1539
+ create refs/heads/branch-1 $A
1540
+ commit
1541
+ start
1542
+ create refs/heads/branch-2 $B
1543
+ commit
1544
+ EOF
1545
+ git update-ref --stdin <stdin >actual &&
1546
+ printf "%s: ok\n" start commit start commit >expect &&
1547
+ test_cmp expect actual &&
1548
+ echo "$A" >expect &&
1549
+ git rev-parse refs/heads/branch-1 >actual &&
1550
+ test_cmp expect actual &&
1551
+ echo "$B" >expect &&
1552
+ git rev-parse refs/heads/branch-2 >actual &&
1553
+ test_cmp expect actual
1554
+ '
1555
+
1556
+ test_expect_success ' transaction can create and delete' '
1557
+ cat >stdin <<-EOF &&
1558
+ start
1559
+ create refs/heads/create-and-delete $A
1560
+ commit
1561
+ start
1562
+ delete refs/heads/create-and-delete $A
1563
+ commit
1564
+ EOF
1565
+ git update-ref --stdin <stdin >actual &&
1566
+ printf "%s: ok\n" start commit start commit >expect &&
1567
+ test_must_fail git show-ref --verify refs/heads/create-and-delete
1568
+ '
1569
+
1570
+ test_expect_success ' transaction can commit after abort' '
1571
+ cat >stdin <<-EOF &&
1572
+ start
1573
+ create refs/heads/abort $A
1574
+ abort
1575
+ start
1576
+ create refs/heads/abort $A
1577
+ commit
1578
+ EOF
1579
+ git update-ref --stdin <stdin >actual &&
1580
+ printf "%s: ok\n" start abort start commit >expect &&
1581
+ echo "$A" >expect &&
1582
+ git rev-parse refs/heads/abort >actual &&
1583
+ test_cmp expect actual
1584
+ '
1585
+
1586
+ test_expect_success ' transaction cannot restart ongoing transaction' '
1587
+ cat >stdin <<-EOF &&
1588
+ start
1589
+ create refs/heads/restart $A
1590
+ start
1591
+ commit
1592
+ EOF
1593
+ test_must_fail git update-ref --stdin <stdin >actual &&
1594
+ test_must_fail git show-ref --verify refs/heads/restart
1527
1595
'
1528
1596
1529
1597
test_done
0 commit comments