allow suppressing of global and system config

The GIT_CONFIG_NOGLOBAL and GIT_CONFIG_NOSYSTEM environment
variables are magic undocumented switches that can be used
to ensure a totally clean environment. This is necessary for
running reliable tests, since those config files may contain
settings that change the outcome of tests.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King
2008-02-06 05:11:18 -05:00
committed by Junio C Hamano
parent b828fef678
commit ab88c36321
3 changed files with 24 additions and 4 deletions

View File

@ -492,6 +492,22 @@ const char *git_etc_gitconfig(void)
return system_wide;
}
int git_env_bool(const char *k, int def)
{
const char *v = getenv(k);
return v ? git_config_bool(k, v) : def;
}
int git_config_system(void)
{
return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0);
}
int git_config_global(void)
{
return !git_env_bool("GIT_CONFIG_NOGLOBAL", 0);
}
int git_config(config_fn_t fn)
{
int ret = 0;
@ -504,7 +520,7 @@ int git_config(config_fn_t fn)
* config file otherwise. */
filename = getenv(CONFIG_ENVIRONMENT);
if (!filename) {
if (!access(git_etc_gitconfig(), R_OK))
if (git_config_system() && !access(git_etc_gitconfig(), R_OK))
ret += git_config_from_file(fn, git_etc_gitconfig());
home = getenv("HOME");
filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
@ -512,7 +528,7 @@ int git_config(config_fn_t fn)
filename = repo_config = xstrdup(git_path("config"));
}
if (home) {
if (git_config_global() && home) {
char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
if (!access(user_config, R_OK))
ret = git_config_from_file(fn, user_config);