add_packed_ref(): add a files_ref_store argument
[git.git] / t / t1404-update-ref-df-conflicts.sh
blob6d869d1285fbb3f687750978db468291c636fd61
1 #!/bin/sh
3 test_description='Test git update-ref with D/F conflicts'
4 . ./test-lib.sh
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
26 Q="'"
28 test_expect_success 'setup' '
30 git commit --allow-empty -m Initial &&
31 C=$(git rev-parse HEAD) &&
32 git commit --allow-empty -m Second &&
33 D=$(git rev-parse HEAD)
37 test_expect_success 'existing loose ref is a simple prefix of new' '
39 prefix=refs/1l &&
40 test_update_rejected $prefix "a c e" false "b c/x d" \
41 "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q"
45 test_expect_success 'existing packed ref is a simple prefix of new' '
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"
53 test_expect_success 'existing loose ref is a deeper prefix of new' '
55 prefix=refs/2l &&
56 test_update_rejected $prefix "a c e" false "b c/x/y d" \
57 "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q"
61 test_expect_success 'existing packed ref is a deeper prefix of new' '
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"
69 test_expect_success 'new ref is a simple prefix of existing loose' '
71 prefix=refs/3l &&
72 test_update_rejected $prefix "a c/x e" false "b c d" \
73 "$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q"
77 test_expect_success 'new ref is a simple prefix of existing packed' '
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"
85 test_expect_success 'new ref is a deeper prefix of existing loose' '
87 prefix=refs/4l &&
88 test_update_rejected $prefix "a c/x/y e" false "b c d" \
89 "$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q"
93 test_expect_success 'new ref is a deeper prefix of existing packed' '
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"
101 test_expect_success 'one new ref is a simple prefix of another' '
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"
109 test_expect_success '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
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
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
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
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
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
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
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
181 test_done