Skip to content

Commit 486fcbc

Browse files
committed
Merge branch 'jk/clone-local'
"git clone --local $path" started its life as an experiment to optionally use link/copy when cloning a repository on the disk, but we didn't deprecate it after we made the option a no-op to always use the optimization. The command learns "--no-local" option to turn this off, as a more explicit alternative over use of file:// URL. * jk/clone-local: clone: allow --no-local to turn off local optimizations docs/clone: mention that --local may be ignored
2 parents cf5c75d + 189260b commit 486fcbc

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

Documentation/git-clone.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,18 @@ OPTIONS
4646
mechanism and clones the repository by making a copy of
4747
HEAD and everything under objects and refs directories.
4848
The files under `.git/objects/` directory are hardlinked
49-
to save space when possible. This is now the default when
50-
the source repository is specified with `/path/to/repo`
51-
syntax, so it essentially is a no-op option. To force
52-
copying instead of hardlinking (which may be desirable
53-
if you are trying to make a back-up of your repository),
54-
but still avoid the usual "git aware" transport
55-
mechanism, `--no-hardlinks` can be used.
49+
to save space when possible.
50+
+
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). 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
60+
usual "git aware" transport mechanism, `--no-hardlinks` can be used.
5661

5762
--no-hardlinks::
5863
Optimize the cloning process from a repository on a

builtin/clone.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static const char * const builtin_clone_usage[] = {
3838
};
3939

4040
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;
4242
static char *option_template, *option_depth;
4343
static char *option_origin = NULL;
4444
static char *option_branch = NULL;
@@ -70,8 +70,8 @@ static struct option builtin_clone_options[] = {
7070
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
7171
OPT_BOOLEAN(0, "mirror", &option_mirror,
7272
"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"),
7575
OPT_BOOLEAN(0, "no-hardlinks", &option_no_hardlinks,
7676
"don't use local hardlinks, always copy"),
7777
OPT_BOOLEAN('s', "shared", &option_shared,
@@ -342,7 +342,7 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,
342342
if (!option_no_hardlinks) {
343343
if (!link(src->buf, dest->buf))
344344
continue;
345-
if (option_local)
345+
if (option_local > 0)
346346
die_errno(_("failed to create link '%s'"), dest->buf);
347347
option_no_hardlinks = 1;
348348
}
@@ -668,7 +668,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
668668
die(_("repository '%s' does not exist"), repo_name);
669669
else
670670
repo = repo_name;
671-
is_local = path && !is_bundle;
671+
is_local = option_local != 0 && path && !is_bundle;
672672
if (is_local && option_depth)
673673
warning(_("--depth is ignored in local clones; use file:// instead."));
674674

t/t5701-clone-local.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,14 @@ test_expect_success 'cloning non-git directory fails' '
124124
test_must_fail git clone not-a-git-repo not-a-git-repo-clone
125125
'
126126

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+
127137
test_done

0 commit comments

Comments
 (0)