enter_repo: avoid duplicating logic, use is_git_directory() instead

It matters for linked checkouts where 'refs' directory won't be
available in $GIT_DIR. is_git_directory() knows about $GIT_COMMON_DIR
and can handle this case.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2015-09-28 20:06:13 +07:00 committed by Junio C Hamano
parent 31041209fe
commit 0f64cc407f
2 changed files with 15 additions and 2 deletions

3
path.c
View File

@ -441,8 +441,7 @@ const char *enter_repo(const char *path, int strict)
else if (chdir(path))
return NULL;
if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 &&
validate_headref("HEAD") == 0) {
if (is_git_directory(".")) {
set_git_dir(".");
check_repository_format();
return path;

View File

@ -134,4 +134,18 @@ test_expect_success 'enter_repo non-strict mode' '
test_cmp expected actual
'
test_expect_success 'enter_repo linked checkout' '
(
cd enter_repo &&
git worktree add ../foo refs/tags/foo
) &&
git ls-remote foo >actual &&
cat >expected <<-\EOF &&
946e985ab20de757ca5b872b16d64e92ff3803a9 HEAD
946e985ab20de757ca5b872b16d64e92ff3803a9 refs/heads/master
946e985ab20de757ca5b872b16d64e92ff3803a9 refs/tags/foo
EOF
test_cmp expected actual
'
test_done