{"thread":{"id":"2909","subject":"[PATCH] git-clone-pack: do not silently overwrite an existing branch 'origin'","startedAt":"2005-12-22T17:59:30Z","lastAt":"2005-12-22T22:37:24Z","messageCount":3,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"13949","messageId":"Pine.LNX.4.63.0512221859110.20025@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2909","inReplyTo":null,"subject":"[PATCH] git-clone-pack: do not silently overwrite an existing branch 'origin'","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-22T17:59:30Z","receivedAt":"2005-12-22T17:59:30Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nWhen cloning a repository which already contains a branch called 'origin',\ndo not silently overwrite it with the remote 'master' ref.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n\tThis happened to me with a project I track via git-cvsimport.\n\tThe clone strangely suffered a time warp ;-)\n\n git-clone.sh |    4 ++++\n 1 files changed, 4 insertions(+), 0 deletions(-)\n\nf0d4ef72573488410a1e8eb0198e347630d6e2c9\ndiff --git a/git-clone.sh b/git-clone.sh\nindex 280cc2e..e988964 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -204,6 +204,10 @@ then\n \thead_points_at=`git-symbolic-ref HEAD`\n \tcase \"$head_points_at\" in\n \trefs/heads/*)\n+\t\tif test -e .git/refs/heads/origin; then\n+\t\t\tchmod a-w .git/refs/heads/origin\n+\t\t\techo \"Warning: branch 'origin' exists already\"\n+\t\tfi\n \t\thead_points_at=`expr \"$head_points_at\" : 'refs/heads/\\(.*\\)'`\n \t\tmkdir -p .git/remotes &&\n \t\techo >.git/remotes/origin \\\n-- \n1.0.0\n"},{"id":"13961","messageId":"7vu0d0hm53.fsf@assigned-by-dhcp.cox.net","threadId":"2909","inReplyTo":"Pine.LNX.4.63.0512221859110.20025@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] git-clone-pack: do not silently overwrite an existing branch 'origin'","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-22T21:12:08Z","receivedAt":"2005-12-22T21:12:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> When cloning a repository which already contains a branch called 'origin',\n> do not silently overwrite it with the remote 'master' ref.\n\nIf we consider the \"origin is special and is used to track\nupstream\" convention pretty much ingrained, then unconditionally\noverwriting origin without saying anything is the right\napproach.  After all, you do not care what upstream your\nupstream is keeping track of, and you would want to use 'origin'\nfor the usual purpose of keeping track of upstream.\n\nOtherwise, if we do not treat \"origin\" specially, we could\ndo something like this.  If \"origin\" exists, then we do not\noverwrite upon clone, nor subsequent fetch.\n\nI have a mild aversion to this change, though.  I'd much prefer\nthe third approach I am too lazy to code, which lets you say\nwhat local branch name instead of 'origin' to keep track of\nupstream from 'git clone' command line.\n\n---\n\ndiff --git a/git-clone.sh b/git-clone.sh\nindex 280cc2e..edebee7 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -206,17 +206,22 @@ then\n \trefs/heads/*)\n \t\thead_points_at=`expr \"$head_points_at\" : 'refs/heads/\\(.*\\)'`\n \t\tmkdir -p .git/remotes &&\n-\t\techo >.git/remotes/origin \\\n-\t\t\"URL: $repo\n-Pull: $head_points_at:origin\" &&\n-\t\tcp \".git/refs/heads/$head_points_at\" .git/refs/heads/origin &&\n+\t\techo \"URL: $repo\" >.git/remotes/origin &&\n+\t\tif test -f \".git/refs/heads/origin\"\n+\t\tthen\n+\t\t    echo \"Pull: $head_points_at:\"\n+\t\telse\n+\t\t    echo \"Pull: $head_points_at:origin\"\n+\t\t    cp \".git/refs/heads/$head_points_at\" \\\n+\t\t        .git/refs/heads/origin &&\n+\t\tfi >>.git/remotes/origin &&\n \t\tfind .git/refs/heads -type f -print |\n \t\twhile read ref\n \t\tdo\n-\t\t\thead=`expr \"$ref\" : '.git/refs/heads/\\(.*\\)'` &&\n-\t\t\ttest \"$head_points_at\" = \"$head\" ||\n-\t\t\ttest \"origin\" = \"$head\" ||\n-\t\t\techo \"Pull: ${head}:${head}\"\n+\t\t    head=`expr \"$ref\" : '.git/refs/heads/\\(.*\\)'` &&\n+\t\t    test \"$head_points_at\" = \"$head\" ||\n+\t\t    test \"origin\" = \"$head\" ||\n+\t\t    echo \"Pull: ${head}:${head}\"\n \t\tdone >>.git/remotes/origin\n \tesac\n \n"},{"id":"13965","messageId":"Pine.LNX.4.63.0512222325330.12241@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2909","inReplyTo":"7vu0d0hm53.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-clone-pack: do not silently overwrite an existing branch 'origin'","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-22T22:37:24Z","receivedAt":"2005-12-22T22:37:24Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 22 Dec 2005, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > When cloning a repository which already contains a branch called 'origin',\n> > do not silently overwrite it with the remote 'master' ref.\n> \n> If we consider the \"origin is special and is used to track\n> upstream\" convention pretty much ingrained, then unconditionally\n> overwriting origin without saying anything is the right\n> approach.  After all, you do not care what upstream your\n> upstream is keeping track of, and you would want to use 'origin'\n> for the usual purpose of keeping track of upstream.\n\nAs I said, I use git to keep track of a few CVS projects. I like to fetch \nall branches, one being the upstream branch, so that I can compare what \nchanges not yet in upstream.\n\n> I have a mild aversion to this change, though.\n\nSo don't.\n\n> I'd much prefer the third approach I am too lazy to code, which lets you \n> say what local branch name instead of 'origin' to keep track of upstream \n> from 'git clone' command line.\n\n---\n\n[PATCH] git-clone: Support changing the origin branch with -o\n\nEarlier, git-clone stored upstream's master in the branch named 'origin',\npossibly overwriting an existing such branch.\n\nNow you can change it by calling git-clone with '-o <other_name>'.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n\tTotally untested, but obviously correct :-)\n\n\tIt still overwrites any existing ref of the same name silently.\n\n git-clone.sh |    9 ++++++---\n 1 files changed, 6 insertions(+), 3 deletions(-)\n\ndiff --git a/git-clone.sh b/git-clone.sh\nindex 280cc2e..87ad477 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -67,6 +67,7 @@ use_local=no\n local_shared=no\n no_checkout=\n upload_pack=\n+origin=origin\n while\n \tcase \"$#,$1\" in\n \t0,*) break ;;\n@@ -75,6 +76,8 @@ while\n         *,-s|*,--s|*,--sh|*,--sha|*,--shar|*,--share|*,--shared) \n           local_shared=yes; use_local=yes ;;\n \t*,-q|*,--quiet) quiet=-q ;;\n+\t1,-o) usage;;\n+\t*,-o) origin=\"$2\"; shift;;\n \t1,-u|1,--upload-pack) usage ;;\n \t*,-u|*,--upload-pack)\n \t\tshift\n@@ -208,14 +211,14 @@ then\n \t\tmkdir -p .git/remotes &&\n \t\techo >.git/remotes/origin \\\n \t\t\"URL: $repo\n-Pull: $head_points_at:origin\" &&\n-\t\tcp \".git/refs/heads/$head_points_at\" .git/refs/heads/origin &&\n+Pull: $head_points_at:$origin\" &&\n+\t\tcp \".git/refs/heads/$head_points_at\" .git/refs/heads/$origin &&\n \t\tfind .git/refs/heads -type f -print |\n \t\twhile read ref\n \t\tdo\n \t\t\thead=`expr \"$ref\" : '.git/refs/heads/\\(.*\\)'` &&\n \t\t\ttest \"$head_points_at\" = \"$head\" ||\n-\t\t\ttest \"origin\" = \"$head\" ||\n+\t\t\ttest \"$origin\" = \"$head\" ||\n \t\t\techo \"Pull: ${head}:${head}\"\n \t\tdone >>.git/remotes/origin\n \tesac\n"}]}