setup: teach discover_git_directory to respect the commondir
[gitweb.git] / config.c
index eec7613e0494a05b5cfe486d04562a287803aacb..e8dbf9e64a36ab77b4814403d291bd95e1c94843 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1639,7 +1639,8 @@ 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 config_options opts = {0};
-       struct strbuf buf = STRBUF_INIT;
+       struct strbuf commondir = STRBUF_INIT;
+       struct strbuf gitdir = STRBUF_INIT;
 
        opts.respect_includes = 1;
 
@@ -1653,12 +1654,13 @@ void read_early_config(config_fn_t cb, void *data)
         * notably, the current working directory is still the same after the
         * call).
         */
-       else if (discover_git_directory(&buf))
-               opts.git_dir = buf.buf;
+       else if (!discover_git_directory(&commondir, &gitdir))
+               opts.git_dir = gitdir.buf;
 
        git_config_with_options(cb, data, NULL, &opts);
 
-       strbuf_release(&buf);
+       strbuf_release(&commondir);
+       strbuf_release(&gitdir);
 }
 
 static void git_config_check_init(void);