summaryrefslogtreecommitdiff
path: root/builtin/clone.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-08-29 04:20:28 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-08-29 04:20:28 (GMT)
commit2730f55527143d3476c159cebbdb63d5e6a5c2a8 (patch)
treec57fde5c543baa16074b1167dbd4d646734e5b8c /builtin/clone.c
parent1da6d98a9acd2db3902bf432a097771c76f4fd44 (diff)
parent9b0ebc722cfc12bd14934aab5cf77ebe654e36e6 (diff)
downloadgit-2730f55527143d3476c159cebbdb63d5e6a5c2a8.zip
git-2730f55527143d3476c159cebbdb63d5e6a5c2a8.tar.gz
git-2730f55527143d3476c159cebbdb63d5e6a5c2a8.tar.bz2
Merge branch 'nd/maint-clone-gitdir'
* nd/maint-clone-gitdir: clone: allow to clone from .git file read_gitfile_gently(): rename misnamed function to read_gitfile()
Diffstat (limited to 'builtin/clone.c')
-rw-r--r--builtin/clone.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/builtin/clone.c b/builtin/clone.c
index 4d66a7f..488f48e 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -113,9 +113,26 @@ static char *get_repo_path(const char *repo, int *is_bundle)
for (i = 0; i < ARRAY_SIZE(suffix); i++) {
const char *path;
path = mkpath("%s%s", repo, suffix[i]);
- if (is_directory(path)) {
+ if (stat(path, &st))
+ continue;
+ if (S_ISDIR(st.st_mode)) {
*is_bundle = 0;
return xstrdup(absolute_path(path));
+ } else if (S_ISREG(st.st_mode) && st.st_size > 8) {
+ /* Is it a "gitfile"? */
+ char signature[8];
+ int len, fd = open(path, O_RDONLY);
+ if (fd < 0)
+ continue;
+ len = read_in_full(fd, signature, 8);
+ close(fd);
+ if (len != 8 || strncmp(signature, "gitdir: ", 8))
+ continue;
+ path = read_gitfile(path);
+ if (path) {
+ *is_bundle = 0;
+ return xstrdup(absolute_path(path));
+ }
}
}