git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] clone: add `--seed` shorthand

From
Jeff King <peff@peff.net>
Date
May 21, 2015, 04:16 UTC
Message-ID
<20150521041619.GC5196@peff.net>
In-Reply-To
<20150521041435.GA18978@peff.net>

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 <peff@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
Previous: Jeff KingNext: Johannes Schindelin
Message 4 of 16 in “--seed as an alias for --dissociate --reference”
  1. 0/3 --seed as an alias for --dissociate --referenceJeff King, May 21, 2015
  2. 1/3 clone: use OPT_STRING_LIST for --referenceJeff King, May 21, 2015
  3. 2/3 clone: reorder --dissociate and --reference optionsJeff King, May 21, 2015
  4. 3/3 clone: add `--seed` shorthandJeff King, May 21, 2015
  5. Johannes SchindelinMay 21, 2015
  6. Philip OakleyMay 21, 2015
  7. Johannes SchindelinMay 22, 2015
  8. Jeff KingMay 22, 2015
  9. Junio C HamanoMay 24, 2015
  10. Jeff KingMay 27, 2015
  11. Junio C HamanoMay 27, 2015
  12. Jeff KingMay 22, 2015
  13. Junio C HamanoMay 21, 2015
  14. Jeff KingMay 21, 2015
  15. Junio C HamanoMay 21, 2015
  16. Michael HaggertyMay 24, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.