Skip to content

Commit ee0be85

Browse files
committed
safe.directory: setting safe.directory="." allows the "current" directory
When "git daemon" enters a repository, it chdir's to the requested repository and then uses "." (the curent directory) to consult the "is this repository considered safe?" when it is not owned by the same owner as the process. Make sure this access will be allowed by setting safe.directory to ".", as that was once advertised on the list as a valid workaround to the overly tight safe.directory settings introduced by 2.45.1 (cf. <[email protected]>). Also add simlar test to show what happens in the same setting if the safe.directory is set to "*" instead of "."; in short, "." is a bit tighter (as it is custom designed for git-daemon situation) than "anything goes" settings given by "*". Signed-off-by: Junio C Hamano <[email protected]>
1 parent dc0edbb commit ee0be85

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

t/t0033-safe-directory.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,68 @@ test_expect_success SYMLINKS 'configured leading paths are normalized' '
233233
git -C repo/s/.git/ for-each-ref
234234
'
235235

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+
236300
test_done

0 commit comments

Comments
 (0)