repo-config: learn the flag "--no-local"
[git.git] / config.c
index bbd3ff2..4080264 100644 (file)
--- 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;
@@ -327,7 +328,8 @@ int git_config(config_fn_t fn)
                        ret = 0;
        }
 
-       ret += git_config_from_file(fn, git_path("config"));
+       if (!git_ignore_local_config)
+               ret += git_config_from_file(fn, git_path("config"));
        return ret;
 }
 
@@ -501,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.
@@ -611,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);