Skip to content

Commit 433efca

Browse files
mhaggergitster
authored andcommitted
t1404: new tests of ref D/F conflicts within transactions
Add some tests of reference D/F conflicts (by which I mean the fact that references like "refs/foo" and "refs/foo/bar" are not allowed to coexist) in the context of reference transactions. The test of creating two conflicting references in the same transaction fails, leaving the transaction half-completed. This will be fixed later in this patch series. Please note that the error messages emitted in the case of conflicts are not very user-friendly. In particular, when the conflicts involve loose references, then the errors are reported as error: there are still refs under 'refs/foo' fatal: Cannot lock the ref 'refs/foo'. or error: unable to resolve reference refs/foo/bar: Not a directory fatal: Cannot lock the ref 'refs/foo/bar'. This is because lock_ref_sha1_basic() fails while trying to lock the new reference, before it even gets to the is_refname_available() check. This situation will also be improved later in this patch series. Signed-off-by: Michael Haggerty <[email protected]>
1 parent 3d4a3ff commit 433efca

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

t/t1404-update-ref-df-conflicts.sh

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/bin/sh
2+
3+
test_description='Test git update-ref with D/F conflicts'
4+
. ./test-lib.sh
5+
6+
test_update_rejected () {
7+
prefix="$1" &&
8+
before="$2" &&
9+
pack="$3" &&
10+
create="$4" &&
11+
error="$5" &&
12+
printf "create $prefix/%s $C\n" $before |
13+
git update-ref --stdin &&
14+
git for-each-ref $prefix >unchanged &&
15+
if $pack
16+
then
17+
git pack-refs --all
18+
fi &&
19+
printf "create $prefix/%s $C\n" $create >input &&
20+
test_must_fail git update-ref --stdin <input 2>output.err &&
21+
grep -F "$error" output.err &&
22+
git for-each-ref $prefix >actual &&
23+
test_cmp unchanged actual
24+
}
25+
26+
Q="'"
27+
28+
test_expect_success 'setup' '
29+
30+
git commit --allow-empty -m Initial &&
31+
C=$(git rev-parse HEAD)
32+
33+
'
34+
35+
test_expect_success 'existing loose ref is a simple prefix of new' '
36+
37+
prefix=refs/1l &&
38+
test_update_rejected $prefix "a c e" false "b c/x d" \
39+
"unable to resolve reference $prefix/c/x: Not a directory"
40+
41+
'
42+
43+
test_expect_success 'existing packed ref is a simple prefix of new' '
44+
45+
prefix=refs/1p &&
46+
test_update_rejected $prefix "a c e" true "b c/x d" \
47+
"$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q"
48+
49+
'
50+
51+
test_expect_success 'existing loose ref is a deeper prefix of new' '
52+
53+
prefix=refs/2l &&
54+
test_update_rejected $prefix "a c e" false "b c/x/y d" \
55+
"unable to resolve reference $prefix/c/x/y: Not a directory"
56+
57+
'
58+
59+
test_expect_success 'existing packed ref is a deeper prefix of new' '
60+
61+
prefix=refs/2p &&
62+
test_update_rejected $prefix "a c e" true "b c/x/y d" \
63+
"$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q"
64+
65+
'
66+
67+
test_expect_success 'new ref is a simple prefix of existing loose' '
68+
69+
prefix=refs/3l &&
70+
test_update_rejected $prefix "a c/x e" false "b c d" \
71+
"there are still refs under $Q$prefix/c$Q"
72+
73+
'
74+
75+
test_expect_success 'new ref is a simple prefix of existing packed' '
76+
77+
prefix=refs/3p &&
78+
test_update_rejected $prefix "a c/x e" true "b c d" \
79+
"$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q"
80+
81+
'
82+
83+
test_expect_success 'new ref is a deeper prefix of existing loose' '
84+
85+
prefix=refs/4l &&
86+
test_update_rejected $prefix "a c/x/y e" false "b c d" \
87+
"there are still refs under $Q$prefix/c$Q"
88+
89+
'
90+
91+
test_expect_success 'new ref is a deeper prefix of existing packed' '
92+
93+
prefix=refs/4p &&
94+
test_update_rejected $prefix "a c/x/y e" true "b c d" \
95+
"$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q"
96+
97+
'
98+
99+
test_expect_failure 'one new ref is a simple prefix of another' '
100+
101+
prefix=refs/5 &&
102+
test_update_rejected $prefix "a e" false "b c c/x d" \
103+
"cannot process $Q$prefix/c$Q and $Q$prefix/c/x$Q at the same time"
104+
105+
'
106+
107+
test_done

0 commit comments

Comments
 (0)