3 test_description='Test git update-ref error handling'
6 # Create some references, perhaps run pack-refs --all, then try to
7 # create some more references. Ensure that the second creation fails
8 # with the correct error message.
9 # Usage: test_update_rejected <before> <pack> <create> <error>
10 # <before> is a ws-separated list of refs to create before the test
11 # <pack> (true or false) tells whether to pack the refs before the test
12 # <create> is a list of variables to attempt creating
13 # <error> is a string to look for in the stderr of update-ref.
14 # All references are created in the namespace specified by the current
16 test_update_rejected () {
21 printf "create $prefix/%s $C\n" $before |
22 git update-ref --stdin &&
23 git for-each-ref $prefix >unchanged &&
28 printf "create $prefix/%s $C\n" $create >input &&
29 test_must_fail git update-ref --stdin <input 2>output.err &&
30 grep -F "$error" output.err &&
31 git for-each-ref $prefix >actual &&
32 test_cmp unchanged actual
37 test_expect_success 'setup' '
39 git commit --allow-empty -m Initial &&
40 C=$(git rev-parse HEAD) &&
41 git commit --allow-empty -m Second &&
42 D=$(git rev-parse HEAD)
46 test_expect_success 'existing loose ref is a simple prefix of new' '
49 test_update_rejected "a c e" false "b c/x d" \
50 "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q"
54 test_expect_success 'existing packed ref is a simple prefix of new' '
57 test_update_rejected "a c e" true "b c/x d" \
58 "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x$Q"
62 test_expect_success 'existing loose ref is a deeper prefix of new' '
65 test_update_rejected "a c e" false "b c/x/y d" \
66 "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q"
70 test_expect_success 'existing packed ref is a deeper prefix of new' '
73 test_update_rejected "a c e" true "b c/x/y d" \
74 "$Q$prefix/c$Q exists; cannot create $Q$prefix/c/x/y$Q"
78 test_expect_success 'new ref is a simple prefix of existing loose' '
81 test_update_rejected "a c/x e" false "b c d" \
82 "$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q"
86 test_expect_success 'new ref is a simple prefix of existing packed' '
89 test_update_rejected "a c/x e" true "b c d" \
90 "$Q$prefix/c/x$Q exists; cannot create $Q$prefix/c$Q"
94 test_expect_success 'new ref is a deeper prefix of existing loose' '
97 test_update_rejected "a c/x/y e" false "b c d" \
98 "$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q"
102 test_expect_success 'new ref is a deeper prefix of existing packed' '
105 test_update_rejected "a c/x/y e" true "b c d" \
106 "$Q$prefix/c/x/y$Q exists; cannot create $Q$prefix/c$Q"
110 test_expect_success 'one new ref is a simple prefix of another' '
113 test_update_rejected "a e" false "b c c/x d" \
114 "cannot process $Q$prefix/c$Q and $Q$prefix/c/x$Q at the same time"
118 test_expect_success 'empty directory should not fool rev-parse' '
119 prefix=refs/e-rev-parse &&
120 git update-ref $prefix/foo $C &&
121 git pack-refs --all &&
122 mkdir -p .git/$prefix/foo/bar/baz &&
123 echo "$C" >expected &&
124 git rev-parse $prefix/foo >actual &&
125 test_cmp expected actual
128 test_expect_success 'empty directory should not fool for-each-ref' '
129 prefix=refs/e-for-each-ref &&
130 git update-ref $prefix/foo $C &&
131 git for-each-ref $prefix >expected &&
132 git pack-refs --all &&
133 mkdir -p .git/$prefix/foo/bar/baz &&
134 git for-each-ref $prefix >actual &&
135 test_cmp expected actual
138 test_expect_success 'empty directory should not fool create' '
139 prefix=refs/e-create &&
140 mkdir -p .git/$prefix/foo/bar/baz &&
141 printf "create %s $C\n" $prefix/foo |
142 git update-ref --stdin
145 test_expect_success 'empty directory should not fool verify' '
146 prefix=refs/e-verify &&
147 git update-ref $prefix/foo $C &&
148 git pack-refs --all &&
149 mkdir -p .git/$prefix/foo/bar/baz &&
150 printf "verify %s $C\n" $prefix/foo |
151 git update-ref --stdin
154 test_expect_success 'empty directory should not fool 1-arg update' '
155 prefix=refs/e-update-1 &&
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\n" $prefix/foo |
160 git update-ref --stdin
163 test_expect_success 'empty directory should not fool 2-arg update' '
164 prefix=refs/e-update-2 &&
165 git update-ref $prefix/foo $C &&
166 git pack-refs --all &&
167 mkdir -p .git/$prefix/foo/bar/baz &&
168 printf "update %s $D $C\n" $prefix/foo |
169 git update-ref --stdin
172 test_expect_success 'empty directory should not fool 0-arg delete' '
173 prefix=refs/e-delete-0 &&
174 git update-ref $prefix/foo $C &&
175 git pack-refs --all &&
176 mkdir -p .git/$prefix/foo/bar/baz &&
177 printf "delete %s\n" $prefix/foo |
178 git update-ref --stdin
181 test_expect_success 'empty directory should not fool 1-arg delete' '
182 prefix=refs/e-delete-1 &&
183 git update-ref $prefix/foo $C &&
184 git pack-refs --all &&
185 mkdir -p .git/$prefix/foo/bar/baz &&
186 printf "delete %s $C\n" $prefix/foo |
187 git update-ref --stdin