]>
Commit | Line | Data |
---|---|---|
433efcad MH |
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 && | |
19dd7d06 MH |
31 | C=$(git rev-parse HEAD) && |
32 | git commit --allow-empty -m Second && | |
33 | D=$(git rev-parse HEAD) | |
433efcad MH |
34 | |
35 | ' | |
36 | ||
37 | test_expect_success 'existing loose ref is a simple prefix of new' ' | |
38 | ||
39 | prefix=refs/1l && | |
40 | test_update_rejected $prefix "a c e" false "b c/x d" \ | |
5b2d8d6f | 41 | "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q" |
433efcad MH |
42 | |
43 | ' | |
44 | ||
45 | test_expect_success 'existing packed ref is a simple prefix of new' ' | |
46 | ||
47 | prefix=refs/1p && | |
48 | test_update_rejected $prefix "a c e" true "b c/x d" \ | |
49 | "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q" | |
50 | ||
51 | ' | |
52 | ||
53 | test_expect_success 'existing loose ref is a deeper prefix of new' ' | |
54 | ||
55 | prefix=refs/2l && | |
56 | test_update_rejected $prefix "a c e" false "b c/x/y d" \ | |
5b2d8d6f | 57 | "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q" |
433efcad MH |
58 | |
59 | ' | |
60 | ||
61 | test_expect_success 'existing packed ref is a deeper prefix of new' ' | |
62 | ||
63 | prefix=refs/2p && | |
64 | test_update_rejected $prefix "a c e" true "b c/x/y d" \ | |
65 | "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q" | |
66 | ||
67 | ' | |
68 | ||
69 | test_expect_success 'new ref is a simple prefix of existing loose' ' | |
70 | ||
71 | prefix=refs/3l && | |
72 | test_update_rejected $prefix "a c/x e" false "b c d" \ | |
5b2d8d6f | 73 | "$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q" |
433efcad MH |
74 | |
75 | ' | |
76 | ||
77 | test_expect_success 'new ref is a simple prefix of existing packed' ' | |
78 | ||
79 | prefix=refs/3p && | |
80 | test_update_rejected $prefix "a c/x e" true "b c d" \ | |
81 | "$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q" | |
82 | ||
83 | ' | |
84 | ||
85 | test_expect_success 'new ref is a deeper prefix of existing loose' ' | |
86 | ||
87 | prefix=refs/4l && | |
88 | test_update_rejected $prefix "a c/x/y e" false "b c d" \ | |
5b2d8d6f | 89 | "$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q" |
433efcad MH |
90 | |
91 | ' | |
92 | ||
93 | test_expect_success 'new ref is a deeper prefix of existing packed' ' | |
94 | ||
95 | prefix=refs/4p && | |
96 | test_update_rejected $prefix "a c/x/y e" true "b c d" \ | |
97 | "$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q" | |
98 | ||
99 | ' | |
100 | ||
e911104c | 101 | test_expect_success 'one new ref is a simple prefix of another' ' |
433efcad MH |
102 | |
103 | prefix=refs/5 && | |
104 | test_update_rejected $prefix "a e" false "b c c/x d" \ | |
105 | "cannot process $Q$prefix/c$Q and $Q$prefix/c/x$Q at the same time" | |
106 | ||
107 | ' | |
108 | ||
19dd7d06 MH |
109 | test_expect_failure 'empty directory should not fool rev-parse' ' |
110 | prefix=refs/e-rev-parse && | |
111 | git update-ref $prefix/foo $C && | |
112 | git pack-refs --all && | |
113 | mkdir -p .git/$prefix/foo/bar/baz && | |
114 | echo "$C" >expected && | |
115 | git rev-parse $prefix/foo >actual && | |
116 | test_cmp expected actual | |
117 | ' | |
118 | ||
119 | test_expect_success 'empty directory should not fool for-each-ref' ' | |
120 | prefix=refs/e-for-each-ref && | |
121 | git update-ref $prefix/foo $C && | |
122 | git for-each-ref $prefix >expected && | |
123 | git pack-refs --all && | |
124 | mkdir -p .git/$prefix/foo/bar/baz && | |
125 | git for-each-ref $prefix >actual && | |
126 | test_cmp expected actual | |
127 | ' | |
128 | ||
129 | test_expect_success 'empty directory should not fool create' ' | |
130 | prefix=refs/e-create && | |
131 | mkdir -p .git/$prefix/foo/bar/baz && | |
132 | printf "create %s $C\n" $prefix/foo | | |
133 | git update-ref --stdin | |
134 | ' | |
135 | ||
136 | test_expect_success 'empty directory should not fool verify' ' | |
137 | prefix=refs/e-verify && | |
138 | git update-ref $prefix/foo $C && | |
139 | git pack-refs --all && | |
140 | mkdir -p .git/$prefix/foo/bar/baz && | |
141 | printf "verify %s $C\n" $prefix/foo | | |
142 | git update-ref --stdin | |
143 | ' | |
144 | ||
145 | test_expect_success 'empty directory should not fool 1-arg update' ' | |
146 | prefix=refs/e-update-1 && | |
147 | git update-ref $prefix/foo $C && | |
148 | git pack-refs --all && | |
149 | mkdir -p .git/$prefix/foo/bar/baz && | |
150 | printf "update %s $D\n" $prefix/foo | | |
151 | git update-ref --stdin | |
152 | ' | |
153 | ||
154 | test_expect_success 'empty directory should not fool 2-arg update' ' | |
155 | prefix=refs/e-update-2 && | |
156 | git update-ref $prefix/foo $C && | |
157 | git pack-refs --all && | |
158 | mkdir -p .git/$prefix/foo/bar/baz && | |
159 | printf "update %s $D $C\n" $prefix/foo | | |
160 | git update-ref --stdin | |
161 | ' | |
162 | ||
163 | test_expect_success 'empty directory should not fool 0-arg delete' ' | |
164 | prefix=refs/e-delete-0 && | |
165 | git update-ref $prefix/foo $C && | |
166 | git pack-refs --all && | |
167 | mkdir -p .git/$prefix/foo/bar/baz && | |
168 | printf "delete %s\n" $prefix/foo | | |
169 | git update-ref --stdin | |
170 | ' | |
171 | ||
172 | test_expect_success 'empty directory should not fool 1-arg delete' ' | |
173 | prefix=refs/e-delete-1 && | |
174 | git update-ref $prefix/foo $C && | |
175 | git pack-refs --all && | |
176 | mkdir -p .git/$prefix/foo/bar/baz && | |
177 | printf "delete %s $C\n" $prefix/foo | | |
178 | git update-ref --stdin | |
179 | ' | |
180 | ||
433efcad | 181 | test_done |