From 90b4fd31cda88325bdebf89b7d407491b176f853 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 19 Apr 2021 14:19:37 -0700 Subject: [PATCH] Revert "Merge branch 'ps/config-global-override' into next" This reverts commit 60a58d74abd3e576af6bbb8c27132cd425a7abde, reversing changes made to 41f303ef9b439e9d9973d7ebc90287513492962d, as it regresses the use of traditional GIT_CONFIG_NOSYSTEM environment variable. --- Documentation/git-config.txt | 5 --- Documentation/git.txt | 10 ----- builtin/config.c | 6 +-- config.c | 41 ++++++--------------- config.h | 4 +- t/t1300-config.sh | 71 ------------------------------------ 6 files changed, 16 insertions(+), 121 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 5cddadafd2..4b4cc5c5e8 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -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. diff --git a/Documentation/git.txt b/Documentation/git.txt index 380422a6a9..3a9c44987f 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -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 diff --git a/builtin/config.c b/builtin/config.c index 865fddd6ce..f71fa39b38 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -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"); diff --git a/config.c b/config.c index e5c2d509eb..870d9534de 100644 --- a/config.c +++ b/config.c @@ -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); diff --git a/config.h b/config.h index 9038538ffd..19a9adbaa9 100644 --- a/config.h +++ b/config.h @@ -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); diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 17f1b78c01..e0dd5d65ce 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -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 <