Skip to content

Commit

Permalink
allow suppressing of global and system config
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
peff authored and gitster committed Feb 6, 2008
1 parent b828fef commit ab88c36
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 3 additions & 2 deletions builtin-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ static int get_value(const char* key_, const char* regex_)
local = getenv(CONFIG_LOCAL_ENVIRONMENT);
if (!local)
local = repo_config = xstrdup(git_path("config"));
if (home)
if (git_config_global() && home)
global = xstrdup(mkpath("%s/.gitconfig", home));
system_wide = git_etc_gitconfig();
if (git_config_system())
system_wide = git_etc_gitconfig();
}

key = xstrdup(key_);
Expand Down
3 changes: 3 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ extern int git_config_set_multivar(const char *, const char *, const char *, int
extern int git_config_rename_section(const char *, const char *);
extern const char *git_etc_gitconfig(void);
extern int check_repository_format_version(const char *var, const char *value);
extern int git_env_bool(const char *, int);
extern int git_config_system(void);
extern int git_config_global(void);

#define MAX_GITNAME (1000)
extern char git_default_email[MAX_GITNAME];
Expand Down
20 changes: 18 additions & 2 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -504,15 +520,15 @@ 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);
if (!filename)
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);
Expand Down

0 comments on commit ab88c36

Please sign in to comment.