Merge branch 'sg/safe-directory-tests-and-docs'

New tests for the safe.directory mechanism.

* sg/safe-directory-tests-and-docs:
  safe.directory: document and check that it's ignored in the environment
  t0033-safe-directory: check when 'safe.directory' is ignored
  t0033-safe-directory: check the error message without matching the trash dir
maint
Junio C Hamano 2022-05-20 15:26:52 -07:00
commit 1256a25ecd
2 changed files with 31 additions and 3 deletions

View File

@ -13,8 +13,8 @@ override any such directories specified in the system config), add a
`safe.directory` entry with an empty value.
+
This config setting is only respected when specified in a system or global
config, not when it is specified in a repository config or via the command
line option `-c safe.directory=<path>`.
config, not when it is specified in a repository config, via the command
line option `-c safe.directory=<path>`, or in environment variables.
+
The value of this setting is interpolated, i.e. `~/<path>` expands to a
path relative to the home directory and `%(prefix)/<path>` expands to a

View File

@ -9,13 +9,41 @@ export GIT_TEST_ASSUME_DIFFERENT_OWNER

expect_rejected_dir () {
test_must_fail git status 2>err &&
grep "safe.directory" err
grep "unsafe repository" err
}

test_expect_success 'safe.directory is not set' '
expect_rejected_dir
'

test_expect_success 'ignoring safe.directory on the command line' '
test_must_fail git -c safe.directory="$(pwd)" status 2>err &&
grep "unsafe repository" err
'

test_expect_success 'ignoring safe.directory in the environment' '
test_must_fail env GIT_CONFIG_COUNT=1 \
GIT_CONFIG_KEY_0="safe.directory" \
GIT_CONFIG_VALUE_0="$(pwd)" \
git status 2>err &&
grep "unsafe repository" err
'

test_expect_success 'ignoring safe.directory in GIT_CONFIG_PARAMETERS' '
test_must_fail env \
GIT_CONFIG_PARAMETERS="${SQ}safe.directory${SQ}=${SQ}$(pwd)${SQ}" \
git status 2>err &&
grep "unsafe repository" err
'

test_expect_success 'ignoring safe.directory in repo config' '
(
unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
git config safe.directory "$(pwd)"
) &&
expect_rejected_dir
'

test_expect_success 'safe.directory does not match' '
git config --global safe.directory bogus &&
expect_rejected_dir