提交 72183cb2 编写于 作者: S SZEDER Gábor 提交者: Junio C Hamano

Fix gitdir detection when in subdir of gitdir

If the current working directory is a subdirectory of the gitdir (e.g.
<repo>/.git/refs/), then setup_git_directory_gently() will climb its
parent directories until it finds itself in a gitdir.  However, no
matter how many parent directories it climbs, it sets
'GIT_DIR_ENVIRONMENT' to ".", which is obviously wrong.

This behaviour affected at least 'git rev-parse --git-dir' and hence
caused some errors in bash completion (e.g. customized command prompt
when on a detached head and completion of refs).

To fix this, we set the absolute path of the found gitdir instead.
Signed-off-by: NSZEDER Gábor <szeder@ira.uka.de>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 bf474e24
...@@ -456,6 +456,10 @@ const char *setup_git_directory_gently(int *nongit_ok) ...@@ -456,6 +456,10 @@ const char *setup_git_directory_gently(int *nongit_ok)
inside_git_dir = 1; inside_git_dir = 1;
if (!work_tree_env) if (!work_tree_env)
inside_work_tree = 0; inside_work_tree = 0;
if (offset != len) {
cwd[offset] = '\0';
setenv(GIT_DIR_ENVIRONMENT, cwd, 1);
} else
setenv(GIT_DIR_ENVIRONMENT, ".", 1); setenv(GIT_DIR_ENVIRONMENT, ".", 1);
check_repository_format_gently(nongit_ok); check_repository_format_gently(nongit_ok);
return NULL; return NULL;
......
...@@ -92,6 +92,13 @@ cd sub/dir || exit 1 ...@@ -92,6 +92,13 @@ cd sub/dir || exit 1
test_rev_parse 'in repo.git/sub/dir' false true true sub/dir/ test_rev_parse 'in repo.git/sub/dir' false true true sub/dir/
cd ../../../.. || exit 1 cd ../../../.. || exit 1
test_expect_success 'detecting gitdir when cwd is in a subdir of gitdir' '
(expected=$(pwd)/repo.git &&
cd repo.git/refs &&
unset GIT_DIR &&
test "$expected" = "$(git rev-parse --git-dir)")
'
test_expect_success 'repo finds its work tree' ' test_expect_success 'repo finds its work tree' '
(cd repo.git && (cd repo.git &&
: > work/sub/dir/untracked && : > work/sub/dir/untracked &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册