@matheusbsbs / matheus-bagliano / commits / ab88c36321
Fork 0

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>

Jeff King committed Feb 6, 2008 at 05:11 UTC ab88c36321df647e17d477f19591cf6ca95de7f0
3 files changed +24 -4
builtin-config.c
+3 -2
@@ -79,9 +79,10 @@ static int get_value(const char* key_, const char* regex_)
79 local = getenv(CONFIG_LOCAL_ENVIRONMENT);
80 if (!local)
81 local = repo_config = xstrdup(git_path("config"));
82 - if (home)
82 + if (git_config_global() && home)
83 global = xstrdup(mkpath("%s/.gitconfig", home));
84 - system_wide = git_etc_gitconfig();
84 + if (git_config_system())
85 + system_wide = git_etc_gitconfig();
86 }
87
88 key = xstrdup(key_);
cache.h
+3
@@ -589,6 +589,9 @@ extern int git_config_set_multivar(const char *, const char *, const char *, int
589 extern int git_config_rename_section(const char *, const char *);
590 extern const char *git_etc_gitconfig(void);
591 extern int check_repository_format_version(const char *var, const char *value);
592 +extern int git_env_bool(const char *, int);
593 +extern int git_config_system(void);
594 +extern int git_config_global(void);
595
596 #define MAX_GITNAME (1000)
597 extern char git_default_email[MAX_GITNAME];
config.c
+18 -2
@@ -492,6 +492,22 @@ const char *git_etc_gitconfig(void)
492 return system_wide;
493 }
494
495 +int git_env_bool(const char *k, int def)
496 +{
497 + const char *v = getenv(k);
498 + return v ? git_config_bool(k, v) : def;
499 +}
500 +
501 +int git_config_system(void)
502 +{
503 + return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0);
504 +}
505 +
506 +int git_config_global(void)
507 +{
508 + return !git_env_bool("GIT_CONFIG_NOGLOBAL", 0);
509 +}
510 +
511 int git_config(config_fn_t fn)
512 {
513 int ret = 0;
@@ -504,7 +520,7 @@ int git_config(config_fn_t fn)
520 * config file otherwise. */
521 filename = getenv(CONFIG_ENVIRONMENT);
522 if (!filename) {
507 - if (!access(git_etc_gitconfig(), R_OK))
523 + if (git_config_system() && !access(git_etc_gitconfig(), R_OK))
524 ret += git_config_from_file(fn, git_etc_gitconfig());
525 home = getenv("HOME");
526 filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
@@ -512,7 +528,7 @@ int git_config(config_fn_t fn)
528 filename = repo_config = xstrdup(git_path("config"));
529 }
530
515 - if (home) {
531 + if (git_config_global() && home) {
532 char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
533 if (!access(user_config, R_OK))
534 ret = git_config_from_file(fn, user_config);