The safe way to use `--reference` is to add in the recent
`--dissociate` option, which optimizes the initial clone,
but does not create any obligation to avoid pruning or
deleting the reference repository. However, it can be rather
tricky to explain why two options are necessary, and why
using `--reference` alone is unsafe.

This patch introduces a single option, `--seed`, which does
the right thing; we can steer users towards it rather than
explaining the complexities. It also provides a natural
interface if we later want to allow seeding from non-local
repositories.

Note that git-repack cannot selectively dissociate from
particular alternates. Therefore using `--reference` and
`--seed` together will dissociate from _all_ referenced
repositories. We issue a warning to the user in this case.

Signed-off-by: Jeff King <p...@peff.net>
---
 Documentation/git-clone.txt |  3 +++
 builtin/clone.c             | 12 +++++++++++-
 t/t5700-clone-reference.sh  |  6 ++++--
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt
index f1f2a3f..ffeb03b 100644
--- a/Documentation/git-clone.txt
+++ b/Documentation/git-clone.txt
@@ -107,6 +107,9 @@ objects from the source repository into a pack in the 
cloned repository.
        transfer and stop borrowing from them after a clone is made
        by making necessary local copies of borrowed objects.
 
+--seed <repository>::
+       A convenient shorthand for `--dissociate --reference=<repository>`.
+
 --quiet::
 -q::
        Operate quietly.  Progress is not reported to the standard
diff --git a/builtin/clone.c b/builtin/clone.c
index a0ec1a9..dd53bbd 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -49,6 +49,7 @@ static int option_verbosity;
 static int option_progress = -1;
 static struct string_list option_config;
 static struct string_list option_reference;
+static struct string_list option_seed;
 static int option_dissociate;
 
 static struct option builtin_clone_options[] = {
@@ -78,6 +79,8 @@ static struct option builtin_clone_options[] = {
                        N_("reference repository")),
        OPT_BOOL(0, "dissociate", &option_dissociate,
                 N_("use --reference only while cloning")),
+       OPT_STRING_LIST(0, "seed", &option_seed, N_("repo"),
+                       N_("reference and dissociate from repo")),
        OPT_STRING('o', "origin", &option_origin, N_("name"),
                   N_("use <name> instead of 'origin' to track upstream")),
        OPT_STRING('b', "branch", &option_branch, N_("branch"),
@@ -263,6 +266,7 @@ static int add_one_reference(struct string_list_item *item, 
void *cb_data)
 static void setup_reference(void)
 {
        for_each_string_list(&option_reference, add_one_reference, NULL);
+       for_each_string_list(&option_seed, add_one_reference, NULL);
 }
 
 static void copy_alternates(struct strbuf *src, struct strbuf *dst,
@@ -884,7 +888,13 @@ int cmd_clone(int argc, const char **argv, const char 
*prefix)
        git_config_set(key.buf, repo);
        strbuf_reset(&key);
 
-       if (option_reference.nr)
+       if (option_seed.nr) {
+               if (option_reference.nr)
+                       warning(_("--seed and --reference used together implies 
--dissociate"));
+               option_dissociate = 1;
+       }
+
+       if (option_reference.nr || option_seed.nr)
                setup_reference();
        else if (option_dissociate) {
                warning(_("--dissociate given, but there is no --reference"));
diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh
index 3e783fc..80a794c 100755
--- a/t/t5700-clone-reference.sh
+++ b/t/t5700-clone-reference.sh
@@ -209,10 +209,12 @@ test_expect_success 'clone and dissociate from reference' 
'
        ) &&
        git clone --no-local --reference=P Q R &&
        git clone --no-local --reference=P --dissociate Q S &&
-       # removing the reference P would corrupt R but not S
+       git clone --no-local --seed=P Q T &&
+       # removing the reference P would corrupt R but not S or T
        rm -fr P &&
        test_must_fail git -C R fsck &&
-       git -C S fsck
+       git -C S fsck &&
+       git -C T fsck
 '
 
 test_done
-- 
2.4.1.528.g00591e3
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to