clone: allow to clone from .git file
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
Aug 21, 2011 at 18:58 UTC
9b0ebc722cfc12bd14934aab5cf77ebe654e36e6
2 files changed
+22
-1
builtin/clone.c
+18
-1
@@ -101,9 +101,26 @@ static char *get_repo_path(const char *repo, int *is_bundle)
101
for (i = 0; i < ARRAY_SIZE(suffix); i++) {
102
const char *path;
103
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)) {
107
*is_bundle = 0;
108
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
+ }
124
}
125
}
126
t/t5601-clone.sh
+4
@@ -202,6 +202,10 @@ test_expect_success 'clone separate gitdir: output' '
202
test_cmp expected dst/.git
203
'
204
205
+test_expect_success 'clone from .git file' '
206
+ git clone dst/.git dst2
207
+'
208
+
209
test_expect_success 'clone separate gitdir where target already exists' '
210
rm -rf dst &&
211
test_must_fail git clone --separate-git-dir realgitdir src dst