From: Johannes Schindelin Date: Thu, 8 Jun 2006 11:31:12 +0000 (+0200) Subject: Read configuration also from ~/.gitconfig X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ea71d197c3d265f32aae225a5fd17f4ef617c216;p=git.git Read configuration also from ~/.gitconfig This patch is based on Pasky's, with three notable differences: - I did not yet update the documentation - I named it .gitconfig, not .gitrc - git-repo-config does not barf when a unique key is overridden locally The last means that if you have something like [alias] l = log --stat -M in ~/.gitconfig, and [alias] l = log --stat -M next.. in $GIT_DIR/config, then git-repo-config alias.l returns only one value, namely the value from $GIT_DIR/config. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- diff --git a/config.c b/config.c index c4749700..bbd3ff29 100644 --- a/config.c +++ b/config.c @@ -317,7 +317,18 @@ int git_config_from_file(config_fn_t fn, const char *filename) int git_config(config_fn_t fn) { - return git_config_from_file(fn, git_path("config")); + int ret = 0; + const char *home = getenv("HOME"); + + if (home) { + ret = git_config_from_file(fn, mkpath("%s/.gitconfig", home)); + /* ignore if global config does not exist */ + if (ret < 0) + ret = 0; + } + + ret += git_config_from_file(fn, git_path("config")); + return ret; } /* diff --git a/repo-config.c b/repo-config.c index 08fc4cc5..59c2bfbf 100644 --- a/repo-config.c +++ b/repo-config.c @@ -65,6 +65,8 @@ static int show_config(const char* key_, const char* value_) static int get_value(const char* key_, const char* regex_) { char *tl; + const char *home = getenv("HOME"); + const char *global = (home ? mkpath("%s/.gitconfig", home) : NULL); key = strdup(key_); for (tl=key+strlen(key)-1; tl >= key && *tl != '.'; --tl) @@ -93,7 +95,12 @@ static int get_value(const char* key_, const char* regex_) } } - git_config(show_config); + if (do_all && global) + git_config_from_file(show_config, global); + git_config_from_file(show_config, git_path("config")); + if (!do_all && !seen) + git_config_from_file(show_config, global); + free(key); if (regexp) { regfree(regexp); diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 8260d57b..ce36c505 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -254,8 +254,9 @@ nextsection.nonewline=wow2 for me version.1.2.3eX.alpha=beta EOF +# "HOME=." is there to avoid reading ~/.gitconfig test_expect_success 'working --list' \ - 'git-repo-config --list > output && cmp output expect' + 'HOME=. git-repo-config --list > output && cmp output expect' cat > expect << EOF beta.noindent sillyValue