t1309: test read_early_config()
[gitweb.git] / config.c
index c6b874a7bf763851b425d526f704966aaad129b2..a88df53fdbca9149e23993319fce6255dc3b6764 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1412,6 +1412,31 @@ static void configset_iter(struct config_set *cs, config_fn_t fn, void *data)
        }
 }
 
+void read_early_config(config_fn_t cb, void *data)
+{
+       struct strbuf buf = STRBUF_INIT;
+
+       git_config_with_options(cb, data, NULL, 1);
+
+       /*
+        * When setup_git_directory() was not yet asked to discover the
+        * GIT_DIR, we ask discover_git_directory() to figure out whether there
+        * is any repository config we should use (but unlike
+        * setup_git_directory_gently(), no global state is changed, most
+        * notably, the current working directory is still the same after the
+        * call).
+        */
+       if (!have_git_dir() && discover_git_directory(&buf)) {
+               struct git_config_source repo_config;
+
+               memset(&repo_config, 0, sizeof(repo_config));
+               strbuf_addstr(&buf, "/config");
+               repo_config.file = buf.buf;
+               git_config_with_options(cb, data, &repo_config, 1);
+       }
+       strbuf_release(&buf);
+}
+
 static void git_config_check_init(void);
 
 void git_config(config_fn_t fn, void *data)