setup: fix safe.directory key not being checked

It seems that nothing is ever checking to make sure the safe directories in the configs actually have the key safe.directory, so some unrelated config that has a value with a certain directory would also make it a safe directory. Signed-off-by: Matheus Valadares <me@m28.io> Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matheus Valadares committed Apr 13, 2022 at 15:32 UTC bb50ec3cc300eeff3aba7a2bea145aabdb477d31
2 files changed +8
setup.c
+3
@@ -1034,6 +1034,9 @@ static int safe_directory_cb(const char *key, const char *value, void *d)
1034 {
1035 struct safe_directory_data *data = d;
1036
1037 + if (strcmp(key, "safe.directory"))
1038 + return 0;
1039 +
1040 if (!value || !*value)
1041 data->is_safe = 0;
1042 else {
t/t0033-safe-directory.sh
+5
@@ -21,6 +21,11 @@ test_expect_success 'safe.directory does not match' '
21 expect_rejected_dir
22 '
23
24 +test_expect_success 'path exist as different key' '
25 + git config --global foo.bar "$(pwd)" &&
26 + expect_rejected_dir
27 +'
28 +
29 test_expect_success 'safe.directory matches' '
30 git config --global --add safe.directory "$(pwd)" &&
31 git status