1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-04-27 23:45:12 +02:00

Revert "Merge branch 'ps/config-global-override' into next"

This reverts commit 60a58d74ab, reversing
changes made to 41f303ef9b, as it regresses
the use of traditional GIT_CONFIG_NOSYSTEM environment variable.
This commit is contained in:
Junio C Hamano 2021-04-19 14:19:37 -07:00
parent 6c1eba8ee3
commit 90b4fd31cd
6 changed files with 16 additions and 121 deletions

View File

@ -340,11 +340,6 @@ GIT_CONFIG::
Using the "--global" option forces this to ~/.gitconfig. Using the
"--system" option forces this to $(prefix)/etc/gitconfig.
GIT_CONFIG_GLOBAL::
GIT_CONFIG_SYSTEM::
Take the configuration from the given files instead from global or
system-level configuration. See linkgit:git[1] for details.
GIT_CONFIG_NOSYSTEM::
Whether to skip reading settings from the system-wide
$(prefix)/etc/gitconfig file. See linkgit:git[1] for details.

View File

@ -670,16 +670,6 @@ for further details.
If this environment variable is set to `0`, git will not prompt
on the terminal (e.g., when asking for HTTP authentication).
`GIT_CONFIG_GLOBAL`::
`GIT_CONFIG_SYSTEM`::
Take the configuration from the given files instead from global or
system-level configuration files. If `GIT_CONFIG_SYSTEM` is set, the
system config file defined at build time (usually `/etc/gitconfig`)
will not be read. Likewise, if `GIT_CONFIG_GLOBAL` is set, neither
`$HOME/.gitconfig` nor `$XDG_CONFIG_HOME/git/config` will be read. Can
be set to `/dev/null` to skip reading configuration files of the
respective level.
`GIT_CONFIG_NOSYSTEM`::
Whether to skip reading settings from the system-wide
`$(prefix)/etc/gitconfig` file. This environment variable can

View File

@ -671,9 +671,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)
}
if (use_global_config) {
char *user_config, *xdg_config;
char *user_config = expand_user_path("~/.gitconfig", 0);
char *xdg_config = xdg_config_home("config");
git_global_config(&user_config, &xdg_config);
if (!user_config)
/*
* It is unknown if HOME/.gitconfig exists, so
@ -695,7 +695,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
}
}
else if (use_system_config) {
given_config_source.file = git_system_config();
given_config_source.file = git_etc_gitconfig();
given_config_source.scope = CONFIG_SCOPE_SYSTEM;
} else if (use_local_config) {
given_config_source.file = git_pathdup("config");

View File

@ -1830,26 +1830,12 @@ static int git_config_from_blob_ref(config_fn_t fn,
return git_config_from_blob_oid(fn, name, &oid, data);
}
char *git_system_config(void)
const char *git_etc_gitconfig(void)
{
char *system_config = xstrdup_or_null(getenv("GIT_CONFIG_SYSTEM"));
if (system_config)
return system_config;
return system_path(ETC_GITCONFIG);
}
void git_global_config(char **user_out, char **xdg_out)
{
char *user_config = xstrdup_or_null(getenv("GIT_CONFIG_GLOBAL"));
char *xdg_config = NULL;
if (!user_config) {
user_config = expand_user_path("~/.gitconfig", 0);
xdg_config = xdg_config_home("config");
}
*user_out = user_config;
*xdg_out = xdg_config;
static const char *system_wide;
if (!system_wide)
system_wide = system_path(ETC_GITCONFIG);
return system_wide;
}
/*
@ -1883,9 +1869,8 @@ static int do_git_config_sequence(const struct config_options *opts,
config_fn_t fn, void *data)
{
int ret = 0;
char *system_config = git_system_config();
char *xdg_config = NULL;
char *user_config = NULL;
char *xdg_config = xdg_config_home("config");
char *user_config = expand_user_path("~/.gitconfig", 0);
char *repo_config;
enum config_scope prev_parsing_scope = current_parsing_scope;
@ -1897,14 +1882,13 @@ static int do_git_config_sequence(const struct config_options *opts,
repo_config = NULL;
current_parsing_scope = CONFIG_SCOPE_SYSTEM;
if (system_config && !access_or_die(system_config, R_OK,
opts->system_gently ?
ACCESS_EACCES_OK : 0))
ret += git_config_from_file(fn, system_config, data);
if (git_config_system() && !access_or_die(git_etc_gitconfig(), R_OK,
opts->system_gently ?
ACCESS_EACCES_OK : 0))
ret += git_config_from_file(fn, git_etc_gitconfig(),
data);
current_parsing_scope = CONFIG_SCOPE_GLOBAL;
git_global_config(&user_config, &xdg_config);
if (xdg_config && !access_or_die(xdg_config, R_OK, ACCESS_EACCES_OK))
ret += git_config_from_file(fn, xdg_config, data);
@ -1929,7 +1913,6 @@ static int do_git_config_sequence(const struct config_options *opts,
die(_("unable to parse command-line config"));
current_parsing_scope = prev_parsing_scope;
free(system_config);
free(xdg_config);
free(user_config);
free(repo_config);

View File

@ -318,6 +318,7 @@ int git_config_rename_section(const char *, const char *);
int git_config_rename_section_in_file(const char *, const char *, const char *);
int git_config_copy_section(const char *, const char *);
int git_config_copy_section_in_file(const char *, const char *, const char *);
const char *git_etc_gitconfig(void);
int git_env_bool(const char *, int);
unsigned long git_env_ulong(const char *, unsigned long);
int git_config_system(void);
@ -326,9 +327,6 @@ int config_error_nonbool(const char *);
#define config_error_nonbool(s) (config_error_nonbool(s), const_error())
#endif
char *git_system_config(void);
void git_global_config(char **user, char **xdg);
int git_config_parse_parameter(const char *, config_fn_t fn, void *data);
enum config_scope current_config_scope(void);

View File

@ -2059,77 +2059,6 @@ test_expect_success '--show-scope with --show-origin' '
test_cmp expect output
'
test_expect_success 'override global and system config' '
test_when_finished rm -f "$HOME"/.config/git &&
cat >"$HOME"/.gitconfig <<-EOF &&
[home]
config = true
EOF
mkdir -p "$HOME"/.config/git &&
cat >"$HOME"/.config/git/config <<-EOF &&
[xdg]
config = true
EOF
cat >.git/config <<-EOF &&
[local]
config = true
EOF
cat >custom-global-config <<-EOF &&
[global]
config = true
EOF
cat >custom-system-config <<-EOF &&
[system]
config = true
EOF
cat >expect <<-EOF &&
global xdg.config=true
global home.config=true
local local.config=true
EOF
git config --show-scope --list >output &&
test_cmp expect output &&
sane_unset GIT_CONFIG_NOSYSTEM &&
cat >expect <<-EOF &&
system system.config=true
global global.config=true
local local.config=true
EOF
GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \
git config --show-scope --list >output &&
test_cmp expect output &&
cat >expect <<-EOF &&
local local.config=true
EOF
GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null git config --show-scope --list >output &&
test_cmp expect output
'
test_expect_success 'override global and system config with missing file' '
sane_unset GIT_CONFIG_NOSYSTEM &&
test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list >actual &&
test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list >actual &&
GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version
'
test_expect_success 'write to overridden global and system config' '
cat >expect <<EOF &&
[config]
key = value
EOF
GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value &&
test_cmp expect write-to-global &&
GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value &&
test_cmp expect write-to-system
'
for opt in --local --worktree
do
test_expect_success "$opt requires a repo" '