Skip to content

Commit 777f548

Browse files
committed
Merge branch 'gc/bare-repo-discovery'
Allow configuration files in "protected" scopes to include other configuration files. * gc/bare-repo-discovery: config: respect includes in protected config
2 parents b988427 + ecec57b commit 777f548

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
@@ -2392,11 +2392,6 @@ int git_configset_add_file(struct config_set *cs, const char *filename)
23922392
return git_config_from_file(config_set_callback, filename, cs);
23932393
}
23942394

2395-
int git_configset_add_parameters(struct config_set *cs)
2396-
{
2397-
return git_config_from_parameters(config_set_callback, cs);
2398-
}
2399-
24002395
int git_configset_get_value(struct config_set *cs, const char *key, const char **value)
24012396
{
24022397
const struct string_list *values = NULL;
@@ -2641,24 +2636,15 @@ int repo_config_get_pathname(struct repository *repo,
26412636
/* Read values into protected_config. */
26422637
static void read_protected_config(void)
26432638
{
2644-
char *xdg_config = NULL, *user_config = NULL, *system_config = NULL;
2645-
2639+
struct config_options opts = {
2640+
.respect_includes = 1,
2641+
.ignore_repo = 1,
2642+
.ignore_worktree = 1,
2643+
.system_gently = 1,
2644+
};
26462645
git_configset_init(&protected_config);
2647-
2648-
system_config = git_system_config();
2649-
git_global_config(&user_config, &xdg_config);
2650-
2651-
if (system_config)
2652-
git_configset_add_file(&protected_config, system_config);
2653-
if (xdg_config)
2654-
git_configset_add_file(&protected_config, xdg_config);
2655-
if (user_config)
2656-
git_configset_add_file(&protected_config, user_config);
2657-
git_configset_add_parameters(&protected_config);
2658-
2659-
free(system_config);
2660-
free(xdg_config);
2661-
free(user_config);
2646+
config_with_options(config_set_callback, &protected_config,
2647+
NULL, &opts);
26622648
}
26632649

26642650
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
@@ -71,4 +71,13 @@ test_expect_success 'safe.directory=*, but is reset' '
7171
expect_rejected_dir
7272
'
7373

74+
test_expect_success 'safe.directory in included file' '
75+
cat >gitconfig-include <<-EOF &&
76+
[safe]
77+
directory = "$(pwd)"
78+
EOF
79+
git config --global --add include.path "$(pwd)/gitconfig-include" &&
80+
git status
81+
'
82+
7483
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)