config: respect includes in protected config
Protected config is implemented by reading a fixed set of paths, which ignores config [include]-s. Replace this implementation with a call to config_with_options(), which handles [include]-s and saves us from duplicating the logic of 1) identifying which paths to read and 2) reading command line config. As a result, git_configset_add_parameters() is unused, so remove it. It was introduced alongside protected config in 5b3c650777 (config: learn `git_protected_config()`, 2022-07-14) as a way to handle command line config. Signed-off-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Glen Choo committed
Oct 13, 2022 at 17:43 UTC
ecec57b3c9731cf81cd1b9d515334168c2c68f5b
3 files changed
+26
-22
config.c
+8
-22
@@ -2391,11 +2391,6 @@ int git_configset_add_file(struct config_set *cs, const char *filename)
2391
return git_config_from_file(config_set_callback, filename, cs);
2392
}
2393
2394
-int git_configset_add_parameters(struct config_set *cs)
2395
-{
2396
- return git_config_from_parameters(config_set_callback, cs);
2397
-}
2398
-
2394
int git_configset_get_value(struct config_set *cs, const char *key, const char **value)
2395
{
2396
const struct string_list *values = NULL;
@@ -2640,24 +2635,15 @@ int repo_config_get_pathname(struct repository *repo,
2635
/* Read values into protected_config. */
2636
static void read_protected_config(void)
2637
{
2643
- char *xdg_config = NULL, *user_config = NULL, *system_config = NULL;
2644
-
2638
+ struct config_options opts = {
2639
+ .respect_includes = 1,
2640
+ .ignore_repo = 1,
2641
+ .ignore_worktree = 1,
2642
+ .system_gently = 1,
2643
+ };
2644
git_configset_init(&protected_config);
2646
-
2647
- system_config = git_system_config();
2648
- git_global_config(&user_config, &xdg_config);
2649
-
2650
- if (system_config)
2651
- git_configset_add_file(&protected_config, system_config);
2652
- if (xdg_config)
2653
- git_configset_add_file(&protected_config, xdg_config);
2654
- if (user_config)
2655
- git_configset_add_file(&protected_config, user_config);
2656
- git_configset_add_parameters(&protected_config);
2657
-
2658
- free(system_config);
2659
- free(xdg_config);
2660
- free(user_config);
2645
+ config_with_options(config_set_callback, &protected_config,
2646
+ NULL, &opts);
2647
}
2648
2649
void git_protected_config(config_fn_t fn, void *data)
t/t0033-safe-directory.sh
+9
@@ -70,4 +70,13 @@ test_expect_success 'safe.directory=*, but is reset' '
70
expect_rejected_dir
71
'
72
73
+test_expect_success 'safe.directory in included file' '
74
+ cat >gitconfig-include <<-EOF &&
75
+ [safe]
76
+ directory = "$(pwd)"
77
+ EOF
78
+ git config --global --add include.path "$(pwd)/gitconfig-include" &&
79
+ git status
80
+'
81
+
82
test_done
t/t0035-safe-bare-repository.sh
+9
@@ -51,4 +51,13 @@ test_expect_success 'safe.bareRepository on the command line' '
51
-c safe.bareRepository=all
52
'
53
54
+test_expect_success 'safe.bareRepository in included file' '
55
+ cat >gitconfig-include <<-\EOF &&
56
+ [safe]
57
+ bareRepository = explicit
58
+ EOF
59
+ git config --global --add include.path "$(pwd)/gitconfig-include" &&
60
+ expect_rejected -C outer-repo/bare-repo
61
+'
62
+
63
test_done