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>
Nguyễn Thái Ngọc Duy committed
Sep 28, 2015 at 20:06 UTC
0f64cc407f32f979c8bcfa7d3d9b24d8e023df35
2 files changed
+15
-2
path.c
+1
-2
@@ -441,8 +441,7 @@ const char *enter_repo(const char *path, int strict)
441
else if (chdir(path))
442
return NULL;
443
444
- if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 &&
445
- validate_headref("HEAD") == 0) {
444
+ if (is_git_directory(".")) {
445
set_git_dir(".");
446
check_repository_format();
447
return path;
t/t0002-gitfile.sh
+14
@@ -134,4 +134,18 @@ test_expect_success 'enter_repo non-strict mode' '
134
test_cmp expected actual
135
'
136
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
+
151
test_done