233
git -C repo/s/.git/ for-each-ref
234
'
235
236
+test_expect_success 'safe.directory set to a dot' '
237
+ test_when_finished "rm -rf repository" &&
238
+ (
239
+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
240
+ git config --global --unset-all safe.directory
241
+ ) &&
242
+ mkdir -p repository/subdir &&
243
+ git init repository &&
244
+ (
245
+ cd repository &&
246
+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
247
+ test_commit sample
248
+ ) &&
249
+
250
+ (
251
+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
252
+ git config --global safe.directory "."
253
+ ) &&
254
+ git -C repository for-each-ref &&
255
+ git -C repository/ for-each-ref &&
256
+ git -C repository/.git for-each-ref &&
257
+ git -C repository/.git/ for-each-ref &&
258
+
259
+ # What is allowed is repository/subdir but the repository
260
+ # path is repository.
261
+ test_must_fail git -C repository/subdir for-each-ref &&
262
+
263
+ # Likewise, repository .git/refs is allowed with "." but
264
+ # repository/.git that is accessed is not allowed.
265
+ test_must_fail git -C repository/.git/refs for-each-ref
266
+'
267
+
268
+test_expect_success 'safe.directory set to asterisk' '
269
+ test_when_finished "rm -rf repository" &&
270
+ (
271
+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
272
+ git config --global --unset-all safe.directory
273
+ ) &&
274
+ mkdir -p repository/subdir &&
275
+ git init repository &&
276
+ (
277
+ cd repository &&
278
+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
279
+ test_commit sample
280
+ ) &&
281
+
282
+ (
283
+ sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
284
+ git config --global safe.directory "*"
285
+ ) &&
286
+ # these are trivial
287
+ git -C repository for-each-ref &&
288
+ git -C repository/ for-each-ref &&
289
+ git -C repository/.git for-each-ref &&
290
+ git -C repository/.git/ for-each-ref &&
291
+
292
+ # With "*", everything is allowed, and the repository is
293
+ # discovered, which is different behaviour from "." above.
294
+ git -C repository/subdir for-each-ref &&
295
+
296
+ # Likewise.
297
+ git -C repository/.git/refs for-each-ref
298
+'
299
+
300
test_done