summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorBrandon Williams <bmwill@google.com>2017-06-14 11:07:37 -0700
committerJunio C Hamano <gitster@pobox.com>2017-06-15 12:56:22 -0700
commitd3fb71b3cb36971608a46744261e6b5f8802e784 (patch)
tree809de18f72641a2fd76a3ce00c5a7207a4afc3e9 /config.c
parentb2141fc1d20e659810245ec6ca1c143c60e033ec (diff)
downloadgit-d3fb71b3cb36971608a46744261e6b5f8802e784.tar.gz
setup: teach discover_git_directory to respect the commondir
Currently 'discover_git_directory' only looks at the gitdir to determine if a git directory was discovered. This causes a problem in the event that the gitdir which was discovered was in fact a per-worktree git directory and not the common git directory. This is because the repository config, which is checked to verify the repository's format, is stored in the commondir and not in the per-worktree gitdir. Correct this behavior by checking the config stored in the commondir. It will also be of use for callers to have access to the commondir, so lets also return that upon successfully discovering a git directory. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/config.c b/config.c
index eec7613e04..e8dbf9e64a 100644
--- 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);