Code

clone: allow to clone from .git file
[git.git] / builtin / clone.c
index 4144bcf5ca320057b5ef1f5dac9c2df19aba250b..ec57f3dbe4a629b502f7c9e60f89244ef446af4f 100644 (file)
@@ -81,7 +81,7 @@ static struct option builtin_clone_options[] = {
                   "path to git-upload-pack on the remote"),
        OPT_STRING(0, "depth", &option_depth, "depth",
                    "create a shallow clone of that depth"),
-       OPT_STRING('L', "separate-git-dir", &real_git_dir, "gitdir",
+       OPT_STRING(0, "separate-git-dir", &real_git_dir, "gitdir",
                   "separate git dir from working tree"),
 
        OPT_END()
@@ -101,9 +101,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));
+                       }
                }
        }
 
@@ -417,7 +434,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        if (path)
                repo = xstrdup(absolute_path(repo_name));
        else if (!strchr(repo_name, ':'))
-               die("repository '%s' does not exist", repo_name);
+               die(_("repository '%s' does not exist"), repo_name);
        else
                repo = repo_name;
        is_local = path && !is_bundle;