The command line $ git clone --mirror $URL is now a short-hand for $ git clone --bare $URL $ (cd $(basename $URL) && git remote add --mirror origin $URL) Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- Documentation/git-clone.txt | 5 ++++- builtin-clone.c | 9 ++++++++- t/t5601-clone.sh | 10 ++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt index 26fd1b1..0e14e73 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git clone' [--template=<template_directory>] - [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] + [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror] [-o <name>] [-u <upload-pack>] [--reference <repository>] [--depth <depth>] [--] <repository> [<directory>] @@ -106,6 +106,9 @@ then the cloned repository will become corrupt. used, neither remote-tracking branches nor the related configuration variables are created. +--mirror:: + Set up a mirror of the remote repository. This implies --bare. + --origin <name>:: -o <name>:: Instead of using the remote name 'origin' to keep track diff --git a/builtin-clone.c b/builtin-clone.c index e086a40..a45179c 100644 --- a/builtin-clone.c +++ b/builtin-clone.c @@ -33,7 +33,7 @@ static const char * const builtin_clone_usage[] = { NULL }; -static int option_quiet, option_no_checkout, option_bare; +static int option_quiet, option_no_checkout, option_bare, option_mirror; static int option_local, option_no_hardlinks, option_shared; static char *option_template, *option_reference, *option_depth; static char *option_origin = NULL; @@ -45,6 +45,8 @@ static struct option builtin_clone_options[] = { "don't create a checkout"), OPT_BOOLEAN(0, "bare", &option_bare, "create a bare repository"), OPT_BOOLEAN(0, "naked", &option_bare, "create a bare repository"), + OPT_BOOLEAN(0, "mirror", &option_mirror, + "create a mirror repository (implies bare)"), OPT_BOOLEAN('l', "local", &option_local, "to clone from a local repository"), OPT_BOOLEAN(0, "no-hardlinks", &option_no_hardlinks, @@ -359,6 +361,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (option_no_hardlinks) use_local_hardlinks = 0; + if (option_mirror) + option_bare = 1; + if (option_bare) { if (option_origin) die("--bare and --origin %s options are incompatible.", @@ -446,7 +451,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix) } else { snprintf(branch_top, sizeof(branch_top), "refs/remotes/%s/", option_origin); + } + if (option_mirror || !option_bare) { /* Configure the remote */ snprintf(key, sizeof(key), "remote.%s.url", option_origin); git_config_set(key, repo); diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index d785b3d..4b2533f 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -70,4 +70,14 @@ test_expect_success 'clone creates intermediate directories for bare repo' ' ' +test_expect_success 'clone --mirror' ' + + git clone --mirror src mirror && + test -f mirror/HEAD && + test ! -f mirror/file && + FETCH="$(cd mirror && git config remote.origin.fetch)" && + test "+refs/heads/*:refs/heads/*" = "$FETCH" + +' + test_done -- 1.6.0.rc1.46.g279e5 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html