path: implement common_dir handling in git_pathdup_submodule()
When submodule is a linked worktree, "git diff --submodule" and other calls which directly access the submodule's object database do not correctly calculate its path. Fix it by changing the git_pathdup_submodule() behavior, to use either common or per-worktree directory. Do it similarly as for parent repository, but ignore the GIT_COMMON_DIR environment variable, because it would mean common directory for the parent repository and does not make sense for submodule. Also add test for functionality which uses this call. Signed-off-by: Max Kirillov <max@max630.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
35fb4d2e3d
commit
11f9dd7191
17
setup.c
17
setup.c
@ -228,15 +228,22 @@ void verify_non_filename(const char *prefix, const char *arg)
|
||||
}
|
||||
|
||||
int get_common_dir(struct strbuf *sb, const char *gitdir)
|
||||
{
|
||||
const char *git_env_common_dir = getenv(GIT_COMMON_DIR_ENVIRONMENT);
|
||||
if (git_env_common_dir) {
|
||||
strbuf_addstr(sb, git_env_common_dir);
|
||||
return 1;
|
||||
} else {
|
||||
return get_common_dir_noenv(sb, gitdir);
|
||||
}
|
||||
}
|
||||
|
||||
int get_common_dir_noenv(struct strbuf *sb, const char *gitdir)
|
||||
{
|
||||
struct strbuf data = STRBUF_INIT;
|
||||
struct strbuf path = STRBUF_INIT;
|
||||
const char *git_common_dir = getenv(GIT_COMMON_DIR_ENVIRONMENT);
|
||||
int ret = 0;
|
||||
if (git_common_dir) {
|
||||
strbuf_addstr(sb, git_common_dir);
|
||||
return 1;
|
||||
}
|
||||
|
||||
strbuf_addf(&path, "%s/commondir", gitdir);
|
||||
if (file_exists(path.buf)) {
|
||||
if (strbuf_read_file(&data, path.buf, 0) <= 0)
|
||||
|
||||
Reference in New Issue
Block a user