X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=config.c;fp=config.c;h=4080264d7bc5f11582513d101e2caaa201de9295;hb=c7d30f8e865ad728f1b7bc487bbbdd3a49537653;hp=c47497001e172060abdcd08e4a606bec89303232;hpb=ada5853c98c5c0ad84a990cc6ee7365a14555c0f;p=git.git diff --git a/config.c b/config.c index c4749700..4080264d 100644 --- a/config.c +++ b/config.c @@ -10,6 +10,7 @@ #define MAXNAME (256) +int git_ignore_local_config = 0; static FILE *config_file; static const char *config_file_name; static int config_linenr; @@ -317,7 +318,19 @@ 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; + } + + if (!git_ignore_local_config) + ret += git_config_from_file(fn, git_path("config")); + return ret; } /* @@ -490,10 +503,20 @@ 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, *lock_file; const char* last_dot = strrchr(key, '.'); + if (git_ignore_local_config) { + const char *home = getenv("HOME"); + if (!home) + die("No home?"); + config_filename = strdup(mkpath("%s/.gitconfig", home)); + lock_file = strdup(mkpath("%s/.gitconfig.lock", home)); + } else { + config_filename = strdup(git_path("config")); + lock_file = strdup(git_path("config.lock")); + } + /* * Since "key" actually contains the section name and the real * key name separated by a dot, we have to know where the dot is. @@ -600,8 +623,9 @@ 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)) { - fprintf(stderr, "invalid config file\n"); + if (git_config_from_file(store_aux, config_filename)) { + fprintf(stderr, "invalid config file: %s\n", + config_filename); free(store.key); if (store.value_regex != NULL) { regfree(store.value_regex);