3 test_description
='verify safe.directory checks'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 GIT_TEST_ASSUME_DIFFERENT_OWNER
=1
9 export GIT_TEST_ASSUME_DIFFERENT_OWNER
11 expect_rejected_dir
() {
12 test_must_fail git status
2>err
&&
13 grep "dubious ownership" err
16 test_expect_success
'safe.directory is not set' '
20 test_expect_success
'safe.directory on the command line' '
21 git -c safe.directory="$(pwd)" status
24 test_expect_success
'safe.directory in the environment' '
25 env GIT_CONFIG_COUNT=1 \
26 GIT_CONFIG_KEY_0="safe.directory" \
27 GIT_CONFIG_VALUE_0="$(pwd)" \
31 test_expect_success
'safe.directory in GIT_CONFIG_PARAMETERS' '
32 env GIT_CONFIG_PARAMETERS="${SQ}safe.directory${SQ}=${SQ}$(pwd)${SQ}" \
36 test_expect_success
'ignoring safe.directory in repo config' '
38 unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
39 git config safe.directory "$(pwd)"
44 test_expect_success
'safe.directory does not match' '
45 git config --global safe.directory bogus &&
49 test_expect_success
'path exist as different key' '
50 git config --global foo.bar "$(pwd)" &&
54 test_expect_success
'safe.directory matches' '
55 git config --global --add safe.directory "$(pwd)" &&
59 test_expect_success
'safe.directory matches, but is reset' '
60 git config --global --add safe.directory "" &&
64 test_expect_success
'safe.directory=*' '
65 git config --global --add safe.directory "*" &&
69 test_expect_success
'safe.directory=*, but is reset' '
70 git config --global --add safe.directory "" &&
74 test_expect_success
'safe.directory in included file' '
75 cat >gitconfig-include <<-EOF &&
79 git config --global --add include.path "$(pwd)/gitconfig-include" &&
83 test_expect_success
'local clone of unowned repo refused in unsafe directory' '
84 test_when_finished "rm -rf source" &&
87 sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
88 test_commit -C source initial
90 test_must_fail git clone --local source target &&
91 test_path_is_missing target
94 test_expect_success
'local clone of unowned repo accepted in safe directory' '
95 test_when_finished "rm -rf source" &&
98 sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
99 test_commit -C source initial
101 test_must_fail git clone --local source target &&
102 git config --global --add safe.directory "$(pwd)/source/.git" &&
103 git clone --local source target &&
104 test_path_is_dir target