git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org, junkio@cox.net
Subject: Re: [PATCH] git-clone-pack: do not silently overwrite an existing branch 'origin'
Date: Thu, 22 Dec 2005 13:12:08 -0800	[thread overview]
Message-ID: <7vu0d0hm53.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <Pine.LNX.4.63.0512221859110.20025@wbgn013.biozentrum.uni-wuerzburg.de> (Johannes Schindelin's message of "Thu, 22 Dec 2005 18:59:30 +0100 (CET)")

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> When cloning a repository which already contains a branch called 'origin',
> do not silently overwrite it with the remote 'master' ref.

If we consider the "origin is special and is used to track
upstream" convention pretty much ingrained, then unconditionally
overwriting origin without saying anything is the right
approach.  After all, you do not care what upstream your
upstream is keeping track of, and you would want to use 'origin'
for the usual purpose of keeping track of upstream.

Otherwise, if we do not treat "origin" specially, we could
do something like this.  If "origin" exists, then we do not
overwrite upon clone, nor subsequent fetch.

I have a mild aversion to this change, though.  I'd much prefer
the third approach I am too lazy to code, which lets you say
what local branch name instead of 'origin' to keep track of
upstream from 'git clone' command line.

---

diff --git a/git-clone.sh b/git-clone.sh
index 280cc2e..edebee7 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -206,17 +206,22 @@ then
 	refs/heads/*)
 		head_points_at=`expr "$head_points_at" : 'refs/heads/\(.*\)'`
 		mkdir -p .git/remotes &&
-		echo >.git/remotes/origin \
-		"URL: $repo
-Pull: $head_points_at:origin" &&
-		cp ".git/refs/heads/$head_points_at" .git/refs/heads/origin &&
+		echo "URL: $repo" >.git/remotes/origin &&
+		if test -f ".git/refs/heads/origin"
+		then
+		    echo "Pull: $head_points_at:"
+		else
+		    echo "Pull: $head_points_at:origin"
+		    cp ".git/refs/heads/$head_points_at" \
+		        .git/refs/heads/origin &&
+		fi >>.git/remotes/origin &&
 		find .git/refs/heads -type f -print |
 		while read ref
 		do
-			head=`expr "$ref" : '.git/refs/heads/\(.*\)'` &&
-			test "$head_points_at" = "$head" ||
-			test "origin" = "$head" ||
-			echo "Pull: ${head}:${head}"
+		    head=`expr "$ref" : '.git/refs/heads/\(.*\)'` &&
+		    test "$head_points_at" = "$head" ||
+		    test "origin" = "$head" ||
+		    echo "Pull: ${head}:${head}"
 		done >>.git/remotes/origin
 	esac
 

  reply	other threads:[~2005-12-22 21:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-22 17:59 [PATCH] git-clone-pack: do not silently overwrite an existing branch 'origin' Johannes Schindelin
2005-12-22 21:12 ` Junio C Hamano [this message]
2005-12-22 22:37   ` Johannes Schindelin

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=7vu0d0hm53.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=Johannes.Schindelin@gmx.de \
    --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).