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

Re: [PATCH v2] clone: Add an option to set up a mirror

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 2, 2008, 19:39 UTC
Message-ID
<alpine.DEB.1.00.0808022139150.9611@pacific.mpi-cbg.de.mpi-cbg.de>
In-Reply-To
<alpine.DEB.1.00.0808022126270.9611@pacific.mpi-cbg.de.mpi-cbg.de>
The interdiff:
diff --git a/builtin-clone.c b/builtin-clone.c
index a45179c..ecdcefa 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -347,6 +347,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	char branch_top[256], key[256], value[256];
 	struct strbuf reflog_msg;
 	struct transport *transport = NULL;
+	char *src_ref_prefix = "refs/heads/";
 
 	struct refspec refspec;
 
@@ -445,7 +446,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	git_config(git_default_config, NULL);
 
 	if (option_bare) {
-		strcpy(branch_top, "refs/heads/");
+		if (option_mirror)
+			src_ref_prefix = "refs/";
+		strcpy(branch_top, src_ref_prefix);
 
 		git_config_set("core.bare", "true");
 	} else {
@@ -455,18 +458,24 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 	if (option_mirror || !option_bare) {
 		/* Configure the remote */
+		if (option_mirror) {
+			snprintf(key, sizeof(key),
+					"remote.%s.mirror", option_origin);
+			git_config_set(key, "true");
+		}
+
 		snprintf(key, sizeof(key), "remote.%s.url", option_origin);
 		git_config_set(key, repo);
 
 		snprintf(key, sizeof(key), "remote.%s.fetch", option_origin);
 		snprintf(value, sizeof(value),
-				"+refs/heads/*:%s*", branch_top);
+				"+%s*:%s*", src_ref_prefix, branch_top);
 		git_config_set_multivar(key, value, "^$", 0);
 	}
 
 	refspec.force = 0;
 	refspec.pattern = 1;
-	refspec.src = "refs/heads/";
+	refspec.src = src_ref_prefix;
 	refspec.dst = branch_top;
 
 	if (path && !is_bundle)
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index 4b2533f..9cd5ef4 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -76,7 +76,7 @@ test_expect_success 'clone --mirror' '
 	test -f mirror/HEAD &&
 	test ! -f mirror/file &&
 	FETCH="$(cd mirror && git config remote.origin.fetch)" &&
-	test "+refs/heads/*:refs/heads/*" = "$FETCH"
+	test "+refs/*:refs/*" = "$FETCH"
 
 '
 
Previous: Johannes SchindelinNext: Junio C Hamano
Message 8 of 9 in “clone: Add an option to set up a mirror”
  1. 1/2 clone: Add an option to set up a mirrorJohannes Schindelin, Aug 1, 2008
  2. 2/2 clone --bare: Add ".git" suffix to the directory name to clone intoJohannes Schindelin, Aug 1, 2008
  3. Marcus GriepAug 1, 2008
  4. Bert WesargAug 1, 2008
  5. Miklos VajnaAug 1, 2008
  6. Junio C HamanoAug 2, 2008
  7. clone: Add an option to set up a mirrorJohannes Schindelin, Aug 2, 2008
  8. Johannes SchindelinAug 2, 2008
  9. Junio C HamanoAug 2, 2008

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.