aboutsummaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2006-06-20 00:51:58 +0200
committerJunio C Hamano <junkio@cox.net>2006-06-19 17:30:34 -0700
commit9c3796fc0474ac6fc77da4886a246a37a7fbe856 (patch)
tree7baefcb350040242e902861ae07b72a26421038a /config.c
parent7f29f7a95c906250c9c99d08242c2c4084c48d24 (diff)
downloadgit-9c3796fc0474ac6fc77da4886a246a37a7fbe856.tar.gz
git-9c3796fc0474ac6fc77da4886a246a37a7fbe856.tar.xz
Fix setting config variables with an alternative GIT_CONFIG
When setting a config variable, git_config_set() ignored the variables GIT_CONFIG and GIT_CONFIG_LOCAL. Now, when GIT_CONFIG_LOCAL is set, it will write to that file. If not, GIT_CONFIG is checked, and only as a fallback, the change is written to $GIT_DIR/config. Add a test for it, and also future-proof the test for the upcoming $HOME/.gitconfig support. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'config.c')
-rw-r--r--config.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/config.c b/config.c
index d46eb6d82..37862d429 100644
--- a/config.c
+++ b/config.c
@@ -500,10 +500,19 @@ int git_config_set_multivar(const char* key, const char* value,
int i, dot;
int fd = -1, in_fd;
int ret;
- char* config_filename = strdup(git_path("config"));
- char* lock_file = strdup(git_path("config.lock"));
+ char* config_filename;
+ char* lock_file;
const char* last_dot = strrchr(key, '.');
+ config_filename = getenv("GIT_CONFIG");
+ if (!config_filename) {
+ config_filename = getenv("GIT_CONFIG_LOCAL");
+ if (!config_filename)
+ config_filename = git_path("config");
+ }
+ config_filename = strdup(config_filename);
+ lock_file = strdup(mkpath("%s.lock", config_filename));
+
/*
* Since "key" actually contains the section name and the real
* key name separated by a dot, we have to know where the dot is.
@@ -610,7 +619,7 @@ int git_config_set_multivar(const char* key, const char* value,
* As a side effect, we make sure to transform only a valid
* existing config file.
*/
- if (git_config(store_aux)) {
+ if (git_config_from_file(store_aux, config_filename)) {
fprintf(stderr, "invalid config file\n");
free(store.key);
if (store.value_regex != NULL) {