Skip to content

Commit 9b0ebc7

Browse files
pcloudsgitster
authored andcommitted
clone: allow to clone from .git file
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 13d6ec9 commit 9b0ebc7

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

builtin/clone.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,26 @@ static char *get_repo_path(const char *repo, int *is_bundle)
101101
for (i = 0; i < ARRAY_SIZE(suffix); i++) {
102102
const char *path;
103103
path = mkpath("%s%s", repo, suffix[i]);
104-
if (is_directory(path)) {
104+
if (stat(path, &st))
105+
continue;
106+
if (S_ISDIR(st.st_mode)) {
105107
*is_bundle = 0;
106108
return xstrdup(absolute_path(path));
109+
} else if (S_ISREG(st.st_mode) && st.st_size > 8) {
110+
/* Is it a "gitfile"? */
111+
char signature[8];
112+
int len, fd = open(path, O_RDONLY);
113+
if (fd < 0)
114+
continue;
115+
len = read_in_full(fd, signature, 8);
116+
close(fd);
117+
if (len != 8 || strncmp(signature, "gitdir: ", 8))
118+
continue;
119+
path = read_gitfile(path);
120+
if (path) {
121+
*is_bundle = 0;
122+
return xstrdup(absolute_path(path));
123+
}
107124
}
108125
}
109126

t/t5601-clone.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ test_expect_success 'clone separate gitdir: output' '
202202
test_cmp expected dst/.git
203203
'
204204

205+
test_expect_success 'clone from .git file' '
206+
git clone dst/.git dst2
207+
'
208+
205209
test_expect_success 'clone separate gitdir where target already exists' '
206210
rm -rf dst &&
207211
test_must_fail git clone --separate-git-dir realgitdir src dst

0 commit comments

Comments
 (0)