Skip to content

Commit ecec57b

Browse files
chooglengitster
authored andcommitted
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 5b3c650 (config: learn `git_protected_config()`, 2022-07-14) as a way to handle command line config. Signed-off-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 776f184 commit ecec57b

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

config.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,11 +2391,6 @@ int git_configset_add_file(struct config_set *cs, const char *filename)
23912391
return git_config_from_file(config_set_callback, filename, cs);
23922392
}
23932393

2394-
int git_configset_add_parameters(struct config_set *cs)
2395-
{
2396-
return git_config_from_parameters(config_set_callback, cs);
2397-
}
2398-
23992394
int git_configset_get_value(struct config_set *cs, const char *key, const char **value)
24002395
{
24012396
const struct string_list *values = NULL;
@@ -2640,24 +2635,15 @@ int repo_config_get_pathname(struct repository *repo,
26402635
/* Read values into protected_config. */
26412636
static void read_protected_config(void)
26422637
{
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+
};
26452644
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);
26612647
}
26622648

26632649
void git_protected_config(config_fn_t fn, void *data)

t/t0033-safe-directory.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,13 @@ test_expect_success 'safe.directory=*, but is reset' '
7070
expect_rejected_dir
7171
'
7272

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+
7382
test_done

t/t0035-safe-bare-repository.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ test_expect_success 'safe.bareRepository on the command line' '
5151
-c safe.bareRepository=all
5252
'
5353

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+
5463
test_done

0 commit comments

Comments
 (0)