summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorBrandon Williams <bmwill@google.com>2017-06-14 18:07:37 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-06-15 19:56:22 (GMT)
commitd3fb71b3cb36971608a46744261e6b5f8802e784 (patch)
tree809de18f72641a2fd76a3ce00c5a7207a4afc3e9 /setup.c
parentb2141fc1d20e659810245ec6ca1c143c60e033ec (diff)
downloadgit-d3fb71b3cb36971608a46744261e6b5f8802e784.zip
git-d3fb71b3cb36971608a46744261e6b5f8802e784.tar.gz
git-d3fb71b3cb36971608a46744261e6b5f8802e784.tar.bz2
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 'setup.c')
-rw-r--r--setup.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/setup.c b/setup.c
index c45443f..4e38cf2 100644
--- a/setup.c
+++ b/setup.c
@@ -941,19 +941,21 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
}
}
-const char *discover_git_directory(struct strbuf *gitdir)
+int discover_git_directory(struct strbuf *commondir,
+ struct strbuf *gitdir)
{
struct strbuf dir = STRBUF_INIT, err = STRBUF_INIT;
size_t gitdir_offset = gitdir->len, cwd_len;
+ size_t commondir_offset = commondir->len;
struct repository_format candidate;
if (strbuf_getcwd(&dir))
- return NULL;
+ return -1;
cwd_len = dir.len;
if (setup_git_directory_gently_1(&dir, gitdir, 0) <= 0) {
strbuf_release(&dir);
- return NULL;
+ return -1;
}
/*
@@ -969,8 +971,10 @@ const char *discover_git_directory(struct strbuf *gitdir)
strbuf_insert(gitdir, gitdir_offset, dir.buf, dir.len);
}
+ get_common_dir(commondir, gitdir->buf + gitdir_offset);
+
strbuf_reset(&dir);
- strbuf_addf(&dir, "%s/config", gitdir->buf + gitdir_offset);
+ strbuf_addf(&dir, "%s/config", commondir->buf + commondir_offset);
read_repository_format(&candidate, dir.buf);
strbuf_release(&dir);
@@ -978,11 +982,12 @@ const char *discover_git_directory(struct strbuf *gitdir)
warning("ignoring git dir '%s': %s",
gitdir->buf + gitdir_offset, err.buf);
strbuf_release(&err);
+ strbuf_setlen(commondir, commondir_offset);
strbuf_setlen(gitdir, gitdir_offset);
- return NULL;
+ return -1;
}
- return gitdir->buf + gitdir_offset;
+ return 0;
}
const char *setup_git_directory_gently(int *nongit_ok)