{"thread":{"id":"4435","subject":"[PATCH 1/2] Read configuration also from ~/.gitconfig","startedAt":"2006-06-08T11:31:12Z","lastAt":"2006-06-08T11:31:12Z","messageCount":1,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"21419","messageId":"Pine.LNX.4.63.0606081330380.11910@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4435","inReplyTo":null,"subject":"[PATCH 1/2] Read configuration also from ~/.gitconfig","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-06-08T11:31:12Z","receivedAt":"2006-06-08T11:31:12Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThis patch is based on Pasky's, with three notable differences:\n\n- I did not yet update the documentation\n- I named it .gitconfig, not .gitrc\n- git-repo-config does not barf when a unique key is overridden locally\n\nThe last means that if you have something like\n\n\t[alias]\n\t\tl = log --stat -M\n\nin ~/.gitconfig, and\n\n\t[alias]\n\t\tl = log --stat -M next..\n\nin $GIT_DIR/config, then\n\n\tgit-repo-config alias.l\n\nreturns only one value, namely the value from $GIT_DIR/config.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n---\n config.c               |   13 ++++++++++++-\n repo-config.c          |    9 ++++++++-\n t/t1300-repo-config.sh |    3 ++-\n 3 files changed, 22 insertions(+), 3 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 2ae6153..0987943 100644\n--- a/config.c\n+++ b/config.c\n@@ -317,7 +317,18 @@ int git_config_from_file(config_fn_t fn,\n \n int git_config(config_fn_t fn)\n {\n-\treturn git_config_from_file(fn, git_path(\"config\"));\n+\tint ret = 0;\n+\tconst char *home = getenv(\"HOME\");\n+\n+\tif (home) {\n+\t\tret = git_config_from_file(fn, mkpath(\"%s/.gitconfig\", home));\n+\t\t/* ignore if global config does not exist */\n+\t\tif (ret < 0)\n+\t\t\tret = 0;\n+\t}\n+\n+\tret += git_config_from_file(fn, git_path(\"config\"));\n+\treturn ret;\n }\n \n /*\ndiff --git a/repo-config.c b/repo-config.c\nindex 08fc4cc..59c2bfb 100644\n--- a/repo-config.c\n+++ b/repo-config.c\n@@ -65,6 +65,8 @@ static int show_config(const char* key_,\n static int get_value(const char* key_, const char* regex_)\n {\n \tchar *tl;\n+\tconst char *home = getenv(\"HOME\");\n+\tconst char *global =  (home ? mkpath(\"%s/.gitconfig\", home) : NULL);\n \n \tkey = strdup(key_);\n \tfor (tl=key+strlen(key)-1; tl >= key && *tl != '.'; --tl)\n@@ -93,7 +95,12 @@ static int get_value(const char* key_, c\n \t\t}\n \t}\n \n-\tgit_config(show_config);\n+\tif (do_all && global)\n+\t\tgit_config_from_file(show_config, global);\n+\tgit_config_from_file(show_config, git_path(\"config\"));\n+\tif (!do_all && !seen)\n+\t\tgit_config_from_file(show_config, global);\n+\n \tfree(key);\n \tif (regexp) {\n \t\tregfree(regexp);\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex 8260d57..ce36c50 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -254,8 +254,9 @@ nextsection.nonewline=wow2 for me\n version.1.2.3eX.alpha=beta\n EOF\n \n+# \"HOME=.\" is there to avoid reading ~/.gitconfig\n test_expect_success 'working --list' \\\n-\t'git-repo-config --list > output && cmp output expect'\n+\t'HOME=. git-repo-config --list > output && cmp output expect'\n \n cat > expect << EOF\n beta.noindent sillyValue\n-- \n1.4.0.rc1.g2f47-dirty\n"}]}