{"thread":{"id":"4570","subject":"[PATCH] Fix setting config variables with an alternative GIT_CONFIG","startedAt":"2006-06-19T22:51:58Z","lastAt":"2006-06-19T23:46:33Z","messageCount":2,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"22079","messageId":"Pine.LNX.4.63.0606200050150.26329@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4570","inReplyTo":null,"subject":"[PATCH] Fix setting config variables with an alternative GIT_CONFIG","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-06-19T22:51:58Z","receivedAt":"2006-06-19T22:51:58Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nWhen setting a config variable, git_config_set() ignored the variables\nGIT_CONFIG and GIT_CONFIG_LOCAL. Now, when GIT_CONFIG_LOCAL is set, it\nwill write to that file. If not, GIT_CONFIG is checked, and only as a\nfallback, the change is written to $GIT_DIR/config.\n\nAdd a test for it, and also future-proof the test for the upcoming\n$HOME/.gitconfig support.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n---\n config.c               |   15 ++++++++++++---\n t/Makefile             |    2 +-\n t/t1300-repo-config.sh |   24 ++++++++++++++++++++++++\n 3 files changed, 37 insertions(+), 4 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex d46eb6d..69aa05f 100644\n--- a/config.c\n+++ b/config.c\n@@ -500,10 +500,19 @@ int git_config_set_multivar(const char* \n \tint i, dot;\n \tint fd = -1, in_fd;\n \tint ret;\n-\tchar* config_filename = strdup(git_path(\"config\"));\n-\tchar* lock_file = strdup(git_path(\"config.lock\"));\n+\tchar* config_filename;\n+\tchar* lock_file;\n \tconst char* last_dot = strrchr(key, '.');\n \n+\tconfig_filename = getenv(\"GIT_CONFIG_LOCAL\");\n+\tif (!config_filename) {\n+\t\tconfig_filename = getenv(\"GIT_CONFIG\");\n+\t\tif (!config_filename)\n+\t\t\tconfig_filename  = git_path(\"config\");\n+\t}\n+\tconfig_filename = strdup(config_filename);\n+\tlock_file = strdup(mkpath(\"%s.lock\", config_filename));\n+\n \t/*\n \t * Since \"key\" actually contains the section name and the real\n \t * key name separated by a dot, we have to know where the dot is.\n@@ -610,7 +619,7 @@ int git_config_set_multivar(const char* \n \t\t * As a side effect, we make sure to transform only a valid\n \t\t * existing config file.\n \t\t */\n-\t\tif (git_config(store_aux)) {\n+\t\tif (git_config_from_file(store_aux, config_filename)) {\n \t\t\tfprintf(stderr, \"invalid config file\\n\");\n \t\t\tfree(store.key);\n \t\t\tif (store.value_regex != NULL) {\ndiff --git a/t/Makefile b/t/Makefile\nindex 5495985..632c55f 100644\n--- a/t/Makefile\n+++ b/t/Makefile\n@@ -19,7 +19,7 @@ endif\n all: $(T) clean\n \n $(T):\n-\t@echo \"*** $@ ***\"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)\n+\t@echo \"*** $@ ***\"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)\n \n clean:\n \trm -fr trash\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex 8260d57..0de2497 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -309,5 +309,29 @@ EOF\n \n test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'\n \n+cat > other-config << EOF\n+[ein]\n+\tbahn = strasse\n+EOF\n+\n+cat > expect << EOF\n+ein.bahn=strasse\n+EOF\n+\n+GIT_CONFIG=other-config git-repo-config -l > output\n+\n+test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'\n+\n+GIT_CONFIG=other-config git-repo-config anwohner.park ausweis\n+\n+cat > expect << EOF\n+[ein]\n+\tbahn = strasse\n+[anwohner]\n+\tpark = ausweis\n+EOF\n+\n+test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect'\n+\n test_done\n \n-- \n1.4.0.g275f-dirty\n"},{"id":"22082","messageId":"Pine.LNX.4.63.0606200145310.26329@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4570","inReplyTo":"Pine.LNX.4.63.0606200050150.26329@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Fix setting config variables with an alternative GIT_CONFIG","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-06-19T23:46:33Z","receivedAt":"2006-06-19T23:46:33Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 20 Jun 2006, Johannes Schindelin wrote:\n\n> +\tconfig_filename = getenv(\"GIT_CONFIG_LOCAL\");\n> +\tif (!config_filename) {\n> +\t\tconfig_filename = getenv(\"GIT_CONFIG\");\n\nOops. At the other places, GIT_CONFIG overrides GIT_CONFIG_LOCAL, so these \ntwo must be exchanged in the patch.\n\nSorry,\nDscho\n"}]}