Skip to content

Commit 0f64cc4

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3104120 commit 0f64cc4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

path.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,7 @@ const char *enter_repo(const char *path, int strict)
441441
else if (chdir(path))
442442
return NULL;
443443

444-
if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 &&
445-
validate_headref("HEAD") == 0) {
444+
if (is_git_directory(".")) {
446445
set_git_dir(".");
447446
check_repository_format();
448447
return path;

t/t0002-gitfile.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,18 @@ test_expect_success 'enter_repo non-strict mode' '
134134
test_cmp expected actual
135135
'
136136

137+
test_expect_success 'enter_repo linked checkout' '
138+
(
139+
cd enter_repo &&
140+
git worktree add ../foo refs/tags/foo
141+
) &&
142+
git ls-remote foo >actual &&
143+
cat >expected <<-\EOF &&
144+
946e985ab20de757ca5b872b16d64e92ff3803a9 HEAD
145+
946e985ab20de757ca5b872b16d64e92ff3803a9 refs/heads/master
146+
946e985ab20de757ca5b872b16d64e92ff3803a9 refs/tags/foo
147+
EOF
148+
test_cmp expected actual
149+
'
150+
137151
test_done

0 commit comments

Comments
 (0)