git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH/RFC] git-clone: add --copy-remotes option
Date: Fri, 9 Feb 2007 03:07:20 -0500	[thread overview]
Message-ID: <20070209080720.GA19750@coredump.intra.peff.net> (raw)

When invoked as

  git clone --copy-remotes origin:grandparent parent child

the repo 'child' will clone and track all branches of the parent's
refs/remotes/origin/*, storing them as refs/remotes/grandparent/*.

---

Since the move to separate remotes, I occasionally have the desire to
"fully" clone a repository, including its remotes. For example, I
sometimes want to work on a topic branch in a fresh working directory,
so I use "git clone -s git topic". However, later on in topic I want to
compare my work against upstream branches, but they may not have been
cloned into 'topic' (e.g., I want to look at Junio's 'next', but there
was no 'next' branch in my 'git' repository, only 'remotes/origin/next',
so it didn't get cloned).

Using this patch, I can do
  git clone -s --copy-remotes origin:junio git topic
and access the resulting branches as 'junio/next'.

Some thoughts:
  - the implementation is a little ugly, but making key/value pairs in
    shell variables is inherently ugly. Suggestions are welcome.
  - The child tracks the remote tracking branches of the parent, which
    is very simple. To solve my problem, I could instead automagically
    copy the remotes config from the parent, and the child could then
    track upstream itself. That seems a bit ugly to me (I end up with
    two repos tracking the same data, potentially downloading it twice).
  - making a mapping of names (origin -> junio) is more complex than I
    would like, but otherwise you run a high risk of collision (remote's
    origin/master becoming your origin/master conflicts with remote's
    master becoming your origin/master).

Are people interested in this?

 git-clone.sh |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/git-clone.sh b/git-clone.sh
index 1bd54de..1f3530b 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -128,6 +128,14 @@ while
 	*,--depth)
 		shift
 		depth="--depth=$1";;
+	1,--copy-remotes) usage ;;
+	*,--copy-remotes)
+		shift
+		from=`echo $1 | cut -d: -f1`
+		to=`echo $1 | cut -d: -f2`
+		eval "copy_remotes_$from=\"$to\""
+		copy_remotes="$copy_remotes $from"
+		;;
 	*,-*) usage ;;
 	*) break ;;
 	esac
@@ -321,6 +329,17 @@ then
 			destname="refs/$branch_top/${name#refs/heads/}" ;;
 		refs/tags/*)
 			destname="refs/$tag_top/${name#refs/tags/}" ;;
+		refs/remotes/*)
+			for i in $copy_remotes; do
+			  case "$name" in
+			    refs/remotes/$i/*)
+			      eval "destremote=\$copy_remotes_$i"
+			      destname="refs/remotes/$destremote/${name#refs/remotes/$i/}"
+			      break
+			      ;;
+			  esac
+			done
+			;;
 		*)
 			continue ;;
 		esac
@@ -383,6 +402,11 @@ then
 		# Set up the mappings to track the remote branches.
 		git-config remote."$origin".fetch \
 			"+refs/heads/*:$remote_top/*" '^$' &&
+		for i in $copy_remotes; do
+			eval "destremote=\$copy_remotes_$i"
+			git-config --add remote."$origin".fetch \
+				"+refs/remotes/$i/*:refs/remotes/$destremote/*"
+		done
 		rm -f "refs/remotes/$origin/HEAD"
 		git-symbolic-ref "refs/remotes/$origin/HEAD" \
 			"refs/remotes/$origin/$head_points_at" &&
-- 
1.5.0.rc4.502.g6a6e-dirty

                 reply	other threads:[~2007-02-09  8:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070209080720.GA19750@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).