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

[PATCH] Added --mirror-all to git-fetch.

From
Shawn Pearce <spearce@spearce.org>
Date
Sep 19, 2006, 23:28 UTC
Message-ID
<20060919232851.GA12195@spearce.org>

The --mirror-all option to git-fetch can be used to obtain a copy of every available remote ref into the current repository. This can be a rather destructive update as the local repository will have its HEAD ref overwritten, as well as any ref which it shares in common with the remote repository. On the other hand it can be useful if all you want to do is have this repository track another repository, such as if you are providing Git repository hosting and mirroring source repositories on other systems.

Currently local refs are not deleted even if they do not exist in the remote repository. This may be taken as either a feature or a bug.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 pasky was asking about this on #git.  So here it is.
 Documentation/fetch-options.txt |    7 ++++++
 git-fetch.sh                    |   43 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt
index 13f34d3..5ed9b4f 100644
--- a/Documentation/fetch-options.txt
+++ b/Documentation/fetch-options.txt
@@ -30,6 +30,13 @@
 	flag lets all tags and their associated objects be
 	downloaded.
 
+\--mirror-all::
+	All refs and tags on the remote side are downloaded to
+	the local side.  This option is not intendend for user
+	repositories as it will overwrite every local ref,
+	including HEAD.  You probably don't mean to use this
+	option.
+
 -k, \--keep::
 	Keep downloaded pack.
 
diff --git a/git-fetch.sh b/git-fetch.sh
index 09a5d6c..d22c560 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -14,6 +14,7 @@ IFS="$LF"
 rloga=fetch
 no_tags=
 tags=
+mirror_all=
 append=
 force=
 verbose=
@@ -36,6 +37,9 @@ do
 	-f|--f|--fo|--for|--forc|--force)
 		force=t
 		;;
+	--mirror-all)
+		mirror_all=t
+		;;
 	-t|--t|--ta|--tag|--tags)
 		tags=t
 		;;
@@ -216,12 +220,45 @@ case "$update_head_ok" in
 	;;
 esac
 
-# If --tags (and later --heads or --all) is specified, then we are
-# not talking about defaults stored in Pull: line of remotes or
+# If --tags or -mirror_all (and later --heads) is specified, then we
+# are not talking about defaults stored in Pull: line of remotes or
 # branches file, and just fetch those and refspecs explicitly given.
 # Otherwise we do what we always did.
 
-reflist=$(get_remote_refs_for_fetch "$@")
+if test "$mirror_all"
+then
+	tags=0;  # tags are implied in all 
+	reflist=`IFS="	" &&
+		  (
+			git-ls-remote $upload_pack "$remote" ||
+			echo fail ouch
+		  ) |
+	          while read sha1 name
+		  do
+			case "$sha1" in
+			fail)
+				exit 1
+			esac
+			case "$name" in
+			*^*) continue ;;
+			esac
+		  	if git-check-ref-format "$name"
+			then
+			    echo ".+${name}:${name}"
+			else
+				if test "x$name" = xHEAD
+				then
+					echo ".+${name}:${name}"
+				else
+					echo >&2 "warning: malformed ref ${name} ignored"
+				fi
+			fi
+		  done` || exit
+else
+	# Not using all; do what we always have done.
+	reflist=$(get_remote_refs_for_fetch "$@")
+fi
+
 if test "$tags"
 then
 	taglist=`IFS="	" &&
-- 
1.4.2.1.g832e
Next: Petr Baudis
Message 1 of 14 in “Added --mirror-all to git-fetch.”
  1. Added --mirror-all to git-fetch.Shawn Pearce, Sep 19, 2006
  2. Petr BaudisSep 19, 2006
  3. Junio C HamanoSep 20, 2006
  4. Petr BaudisSep 20, 2006
  5. Shawn PearceSep 20, 2006
  6. Junio C HamanoSep 20, 2006
  7. Shawn PearceSep 20, 2006
  8. Junio C HamanoSep 20, 2006
  9. Shawn PearceSep 20, 2006
  10. Junio C HamanoSep 20, 2006
  11. A Large Angry SCMSep 20, 2006
  12. Petr BaudisSep 20, 2006
  13. Junio C HamanoSep 20, 2006
  14. Shawn PearceSep 20, 2006

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.