Code

init, clone: support --separate-git-dir for .git file
[git.git] / builtin / clone.c
index 2ee1fa984620de4fad79ce94d4f993f5e83a053d..097beca3ab4675be9fb324d6624be92b5330c816 100644 (file)
@@ -42,6 +42,7 @@ static int option_local, option_no_hardlinks, option_shared, option_recursive;
 static char *option_template, *option_reference, *option_depth;
 static char *option_origin = NULL;
 static char *option_branch = NULL;
+static const char *real_git_dir;
 static char *option_upload_pack = "git-upload-pack";
 static int option_verbosity;
 static int option_progress;
@@ -80,6 +81,8 @@ 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",
+                  "separate git dir from working tree"),
 
        OPT_END()
 };
@@ -100,7 +103,7 @@ static char *get_repo_path(const char *repo, int *is_bundle)
                path = mkpath("%s%s", repo, suffix[i]);
                if (is_directory(path)) {
                        *is_bundle = 0;
-                       return xstrdup(make_nonrelative_path(path));
+                       return xstrdup(absolute_path(path));
                }
        }
 
@@ -109,7 +112,7 @@ static char *get_repo_path(const char *repo, int *is_bundle)
                path = mkpath("%s%s", repo, bundle_suffix[i]);
                if (!stat(path, &st) && S_ISREG(st.st_mode)) {
                        *is_bundle = 1;
-                       return xstrdup(make_nonrelative_path(path));
+                       return xstrdup(absolute_path(path));
                }
        }
 
@@ -203,7 +206,7 @@ static void setup_reference(const char *repo)
        struct transport *transport;
        const struct ref *extra;
 
-       ref_git = make_absolute_path(option_reference);
+       ref_git = real_path(option_reference);
 
        if (is_directory(mkpath("%s/.git/objects", ref_git)))
                ref_git = mkpath("%s/.git", ref_git);
@@ -411,7 +414,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
        path = get_repo_path(repo_name, &is_bundle);
        if (path)
-               repo = xstrdup(make_nonrelative_path(repo_name));
+               repo = xstrdup(absolute_path(repo_name));
        else if (!strchr(repo_name, ':'))
                die("repository '%s' does not exist", repo_name);
        else
@@ -466,7 +469,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
        if (safe_create_leading_directories_const(git_dir) < 0)
                die("could not create leading directories of '%s'", git_dir);
-       set_git_dir(make_absolute_path(git_dir));
+
+       set_git_dir_init(git_dir, real_git_dir, 0);
+       if (real_git_dir)
+               git_dir = real_git_dir;
 
        if (0 <= option_verbosity)
                printf("Cloning into %s%s...\n",