diff options
| author | Junio C Hamano <gitster@pobox.com> | 2022-05-20 15:26:52 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2022-05-20 15:26:52 -0700 |
| commit | 1256a25ecd5df8fb418a537d856bf442da984c17 (patch) | |
| tree | 60b62f20d3e6fae8d36267bc7655797fe9c4a1c7 | |
| parent | 277cf0bc36094f6dc4297d8c9cef79df045b735d (diff) | |
| parent | 756d15923bf6806f94484054873e284728a89c4b (diff) | |
| download | git-1256a25ecd5df8fb418a537d856bf442da984c17.tar.xz | |
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
| -rw-r--r-- | Documentation/config/safe.txt | 4 | ||||
| -rwxr-xr-x | t/t0033-safe-directory.sh | 30 |
2 files changed, 31 insertions, 3 deletions
diff --git a/Documentation/config/safe.txt b/Documentation/config/safe.txt index 6d764fe0cc..ae0e2e3bdb 100644 --- a/Documentation/config/safe.txt +++ b/Documentation/config/safe.txt @@ -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 diff --git a/t/t0033-safe-directory.sh b/t/t0033-safe-directory.sh index 239d93f4d2..238b25f91a 100755 --- a/t/t0033-safe-directory.sh +++ b/t/t0033-safe-directory.sh @@ -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 |
