mailmap: plug memory leak in read_mailmap_blob()
[git/gitster.git] / t / t0033-safe-directory.sh
blob5fe61f129129efce671b1c3889a92a59af9be4da
1 #!/bin/sh
3 test_description='verify safe.directory checks'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
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' '
17 expect_rejected_dir
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)" \
28 git status
31 test_expect_success 'safe.directory in GIT_CONFIG_PARAMETERS' '
32 env GIT_CONFIG_PARAMETERS="${SQ}safe.directory${SQ}=${SQ}$(pwd)${SQ}" \
33 git status
36 test_expect_success 'ignoring safe.directory in repo config' '
38 unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
39 git config safe.directory "$(pwd)"
40 ) &&
41 expect_rejected_dir
44 test_expect_success 'safe.directory does not match' '
45 git config --global safe.directory bogus &&
46 expect_rejected_dir
49 test_expect_success 'path exist as different key' '
50 git config --global foo.bar "$(pwd)" &&
51 expect_rejected_dir
54 test_expect_success 'safe.directory matches' '
55 git config --global --add safe.directory "$(pwd)" &&
56 git status
59 test_expect_success 'safe.directory matches, but is reset' '
60 git config --global --add safe.directory "" &&
61 expect_rejected_dir
64 test_expect_success 'safe.directory=*' '
65 git config --global --add safe.directory "*" &&
66 git status
69 test_expect_success 'safe.directory=*, but is reset' '
70 git config --global --add safe.directory "" &&
71 expect_rejected_dir
74 test_expect_success 'safe.directory with matching glob' '
75 git config --global --unset-all safe.directory &&
76 p=$(pwd) &&
77 git config --global safe.directory "${p%/*}/*" &&
78 git status
81 test_expect_success 'safe.directory with unmatching glob' '
82 git config --global --unset-all safe.directory &&
83 p=$(pwd) &&
84 git config --global safe.directory "${p%/*}no/*" &&
85 expect_rejected_dir
88 test_expect_success 'safe.directory in included file' '
89 git config --global --unset-all safe.directory &&
90 cat >gitconfig-include <<-EOF &&
91 [safe]
92 directory = "$(pwd)"
93 EOF
94 git config --global --add include.path "$(pwd)/gitconfig-include" &&
95 git status
98 test_expect_success 'local clone of unowned repo refused in unsafe directory' '
99 test_when_finished "rm -rf source" &&
100 git init source &&
102 sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
103 test_commit -C source initial
104 ) &&
105 test_must_fail git clone --local source target &&
106 test_path_is_missing target
109 test_expect_success 'local clone of unowned repo accepted in safe directory' '
110 test_when_finished "rm -rf source" &&
111 git init source &&
113 sane_unset GIT_TEST_ASSUME_DIFFERENT_OWNER &&
114 test_commit -C source initial
115 ) &&
116 test_must_fail git clone --local source target &&
117 git config --global --add safe.directory "$(pwd)/source/.git" &&
118 git clone --local source target &&
119 test_path_is_dir target
122 test_done