clone: allow --no-local to turn off local optimizations

This is basically the same as using "file://", but is a little less subtle for the end user. It also allows relative paths to be specified. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 30, 2012 at 07:10 UTC 189260b190be845f0e24ede93f9ac539627d72fa
3 files changed +18 -6
Documentation/git-clone.txt
+3 -1
@@ -51,7 +51,9 @@ OPTIONS
51 If the repository is specified as a local path (e.g., `/path/to/repo`),
52 this is the default, and --local is essentially a no-op. If the
53 repository is specified as a URL, then this flag is ignored (and we
54 -never use the local optimizations).
54 +never use the local optimizations). Specifying `--no-local` will
55 +override the default when `/path/to/repo` is given, using the regular
56 +git transport instead.
57 +
58 To force copying instead of hardlinking (which may be desirable if you
59 are trying to make a back-up of your repository), but still avoid the
builtin/clone.c
+5 -5
@@ -38,7 +38,7 @@ static const char * const builtin_clone_usage[] = {
38 };
39
40 static int option_no_checkout, option_bare, option_mirror, option_single_branch = -1;
41 -static int option_local, option_no_hardlinks, option_shared, option_recursive;
41 +static int option_local = -1, option_no_hardlinks, option_shared, option_recursive;
42 static char *option_template, *option_depth;
43 static char *option_origin = NULL;
44 static char *option_branch = NULL;
@@ -70,8 +70,8 @@ static struct option builtin_clone_options[] = {
70 PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
71 OPT_BOOLEAN(0, "mirror", &option_mirror,
72 "create a mirror repository (implies bare)"),
73 - OPT_BOOLEAN('l', "local", &option_local,
74 - "to clone from a local repository"),
73 + OPT_BOOL('l', "local", &option_local,
74 + "to clone from a local repository"),
75 OPT_BOOLEAN(0, "no-hardlinks", &option_no_hardlinks,
76 "don't use local hardlinks, always copy"),
77 OPT_BOOLEAN('s', "shared", &option_shared,
@@ -342,7 +342,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,
342 if (!option_no_hardlinks) {
343 if (!link(src->buf, dest->buf))
344 continue;
345 - if (option_local)
345 + if (option_local > 0)
346 die_errno(_("failed to create link '%s'"), dest->buf);
347 option_no_hardlinks = 1;
348 }
@@ -668,7 +668,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
668 die(_("repository '%s' does not exist"), repo_name);
669 else
670 repo = repo_name;
671 - is_local = path && !is_bundle;
671 + is_local = option_local != 0 && path && !is_bundle;
672 if (is_local && option_depth)
673 warning(_("--depth is ignored in local clones; use file:// instead."));
674
t/t5701-clone-local.sh
+10
@@ -124,4 +124,14 @@ test_expect_success 'cloning non-git directory fails' '
124 test_must_fail git clone not-a-git-repo not-a-git-repo-clone
125 '
126
127 +test_expect_success 'cloning file:// does not hardlink' '
128 + git clone --bare file://"$(pwd)"/a non-local &&
129 + ! repo_is_hardlinked non-local
130 +'
131 +
132 +test_expect_success 'cloning a local path with --no-local does not hardlink' '
133 + git clone --bare --no-local a force-nonlocal &&
134 + ! repo_is_hardlinked force-nonlocal
135 +'
136 +
137 test_done