enter_repo: allow .git files in strict mode
Strict mode is about not guessing where .git is. If the user points to a .git file, we know exactly where the target .git dir will be. This makes it possible to serve .git files as repository on the server side. This may be needed even in local clone case because transport.c code uses upload-pack for fetching remote refs. But right now the clone/transport code goes with non-strict. 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
1f5fbe1fe2d04f6386cf8febc1ce308bcf815592
2 files changed
+17
-2
path.c
+7
-2
@@ -438,8 +438,13 @@ const char *enter_repo(const char *path, int strict)
438
return NULL;
439
path = validated_path;
440
}
441
- else if (chdir(path))
442
- return NULL;
441
+ else {
442
+ const char *gitfile = read_gitfile(path);
443
+ if (gitfile)
444
+ path = gitfile;
445
+ if (chdir(path))
446
+ return NULL;
447
+ }
448
449
if (is_git_directory(".")) {
450
set_git_dir(".");
t/t0002-gitfile.sh
+10
@@ -148,4 +148,14 @@ test_expect_success 'enter_repo linked checkout' '
148
test_cmp expected actual
149
'
150
151
+test_expect_success 'enter_repo strict mode' '
152
+ git ls-remote --upload-pack="git upload-pack --strict" foo/.git >actual &&
153
+ cat >expected <<-\EOF &&
154
+ 946e985ab20de757ca5b872b16d64e92ff3803a9 HEAD
155
+ 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/heads/master
156
+ 946e985ab20de757ca5b872b16d64e92ff3803a9 refs/tags/foo
157
+ EOF
158
+ test_cmp expected actual
159
+'
160
+
161
test_done