aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-02-16 17:56:51 -0800
committerJunio C Hamano <gitster@pobox.com>2008-02-16 17:56:51 -0800
commitfef1c4c0a0766b83cfacaf6276d7bd0d1aa9a2e4 (patch)
treea3c4cf94132da5755e874ef44bd8072d679ba0c8
parent093d50e0d226b879e24753ce18f4eb4b754807c6 (diff)
parent8bfa6bd6473b086ab2c5781daa08a7b5417c3d1f (diff)
downloadgit-fef1c4c0a0766b83cfacaf6276d7bd0d1aa9a2e4.tar.gz
git-fef1c4c0a0766b83cfacaf6276d7bd0d1aa9a2e4.tar.xz
Merge branch 'jk/noetcconfig'
* jk/noetcconfig: fix config reading in tests allow suppressing of global and system config Conflicts: cache.h
-rw-r--r--builtin-config.c5
-rw-r--r--cache.h3
-rw-r--r--config.c20
-rwxr-xr-xt/t1500-rev-parse.sh4
-rw-r--r--t/test-lib.sh7
5 files changed, 31 insertions, 8 deletions
diff --git a/builtin-config.c b/builtin-config.c
index 077d8ef2d..2b9a4261d 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -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_);
diff --git a/cache.h b/cache.h
index cdcabe92b..efd31d856 100644
--- a/cache.h
+++ b/cache.h
@@ -631,6 +631,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);
extern int config_error_nonbool(const char *);
#define MAX_GITNAME (1000)
diff --git a/config.c b/config.c
index ad47dc34f..7881bbc77 100644
--- a/config.c
+++ b/config.c
@@ -493,6 +493,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;
@@ -505,7 +521,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);
@@ -513,7 +529,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);
diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh
index e474b3f1d..38a2bf09a 100755
--- a/t/t1500-rev-parse.sh
+++ b/t/t1500-rev-parse.sh
@@ -33,9 +33,9 @@ test_rev_parse() {
test_rev_parse toplevel false false true ''
cd .git || exit 1
-test_rev_parse .git/ true true false ''
+test_rev_parse .git/ false true false ''
cd objects || exit 1
-test_rev_parse .git/objects/ true true false ''
+test_rev_parse .git/objects/ false true false ''
cd ../.. || exit 1
mkdir -p sub/dir || exit 1
diff --git a/t/test-lib.sh b/t/test-lib.sh
index da47bd7c9..83889c4f4 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -324,8 +324,11 @@ test_done () {
PATH=$(pwd)/..:$PATH
GIT_EXEC_PATH=$(pwd)/..
GIT_TEMPLATE_DIR=$(pwd)/../templates/blt
-GIT_CONFIG=.git/config
-export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG
+unset GIT_CONFIG
+unset GIT_CONFIG_LOCAL
+GIT_CONFIG_NOSYSTEM=1
+GIT_CONFIG_NOGLOBAL=1
+export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOBAL
GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git
export GITPERLLIB