summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2021-04-19 21:19:37 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-04-19 21:19:37 (GMT)
commit90b4fd31cda88325bdebf89b7d407491b176f853 (patch)
treea0af5305d361e6aa0a919856d50fcf6d30bdf70f
parent6c1eba8ee3d479405020112ef972871f91ff1798 (diff)
downloadgit-next.zip
git-next.tar.gz
git-next.tar.bz2
Revert "Merge branch 'ps/config-global-override' into next"next
This reverts commit 60a58d74abd3e576af6bbb8c27132cd425a7abde, reversing changes made to 41f303ef9b439e9d9973d7ebc90287513492962d, as it regresses the use of traditional GIT_CONFIG_NOSYSTEM environment variable.
-rw-r--r--Documentation/git-config.txt5
-rw-r--r--Documentation/git.txt10
-rw-r--r--builtin/config.c6
-rw-r--r--config.c41
-rw-r--r--config.h4
-rwxr-xr-xt/t1300-config.sh71
6 files changed, 16 insertions, 121 deletions
diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index 5cddada..4b4cc5c 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 380422a..3a9c449 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 865fddd..f71fa39 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 e5c2d50..870d953 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 9038538..19a9adb 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 17f1b78..e0dd5d6 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 <<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" '