safe.directory: document and check that it's ignored in the environment
The description of 'safe.directory' mentions that it's respected in the system and global configs, and ignored in the repository config and on the command line, but it doesn't mention whether it's respected or ignored when specified via environment variables (nor does the commit message adding 'safe.directory' [1]). Clarify that 'safe.directory' is ignored when specified in the environment, and add tests to make sure that it remains so. [1] 8959555cee (setup_git_directory(): add an owner check for the top-level directory, 2022-03-02) Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
SZEDER Gábor committed
Apr 27, 2022 at 19:06 UTC
756d15923bf6806f94484054873e284728a89c4b
2 files changed
+17
-2
Documentation/config/safe.txt
+2
-2
@@ -13,8 +13,8 @@ override any such directories specified in the system config), add a
13
`safe.directory` entry with an empty value.
14
+
15
This config setting is only respected when specified in a system or global
16
-config, not when it is specified in a repository config or via the command
17
-line option `-c safe.directory=<path>`.
16
+config, not when it is specified in a repository config, via the command
17
+line option `-c safe.directory=<path>`, or in environment variables.
18
+
19
The value of this setting is interpolated, i.e. `~/<path>` expands to a
20
path relative to the home directory and `%(prefix)/<path>` expands to a
t/t0033-safe-directory.sh
+15
@@ -21,6 +21,21 @@ test_expect_success 'ignoring safe.directory on the command line' '
21
grep "unsafe repository" err
22
'
23
24
+test_expect_success 'ignoring safe.directory in the environment' '
25
+ test_must_fail env GIT_CONFIG_COUNT=1 \
26
+ GIT_CONFIG_KEY_0="safe.directory" \
27
+ GIT_CONFIG_VALUE_0="$(pwd)" \
28
+ git status 2>err &&
29
+ grep "unsafe repository" err
30
+'
31
+
32
+test_expect_success 'ignoring safe.directory in GIT_CONFIG_PARAMETERS' '
33
+ test_must_fail env \
34
+ GIT_CONFIG_PARAMETERS="${SQ}safe.directory${SQ}=${SQ}$(pwd)${SQ}" \
35
+ git status 2>err &&
36
+ grep "unsafe repository" err
37
+'
38
+
39
test_expect_success 'ignoring safe.directory in repo config' '
40
(
41
unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&