git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] clone: fix ref selection in --single-branch --branch=xxx
Date: Fri, 22 Jun 2012 16:35:47 +0700	[thread overview]
Message-ID: <1340357747-31711-1-git-send-email-pclouds@gmail.com> (raw)

 - do not fetch HEAD
 - do not also fetch refs following "xxx"

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 On Tue, Jun 12, 2012 at 4:14 AM, Jeff King <peff@peff.net> wrote:
 > [1] It looks like "--single-branch" does not actually work, and still
 >    fetches master. I think this is a bug in the implementation of
 >    single-branch (it looks like it fetches HEAD unconditionally).
 >    +cc Duy.

 Yep, my bad.

 builtin/clone.c       | 7 +++++--
 t/t5500-fetch-pack.sh | 7 ++++++-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index 7f3b982..d3b7fdc 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -433,8 +433,11 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
 
 		if (!option_branch)
 			remote_head = guess_remote_head(head, refs, 0);
-		else
-			remote_head = find_remote_branch(refs, option_branch);
+		else {
+			local_refs = NULL;
+			tail = &local_refs;
+			remote_head = copy_ref(find_remote_branch(refs, option_branch));
+		}
 
 		if (!remote_head && option_branch)
 			warning(_("Could not find remote branch %s to clone."),
diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index 1d1ca98..e80a2af 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -125,6 +125,11 @@ test_expect_success 'single branch object count' '
 	test_cmp expected count.singlebranch
 '
 
+test_expect_success 'single given branch clone' '
+	git clone --single-branch --branch A "file://$(pwd)/." branch-a &&
+	test_must_fail git --git-dir=branch-a/.git rev-parse origin/B
+'
+
 test_expect_success 'clone shallow' '
 	git clone --no-single-branch --depth 2 "file://$(pwd)/." shallow
 '
@@ -276,7 +281,7 @@ test_expect_success 'clone shallow with --branch' '
 '
 
 test_expect_success 'clone shallow object count' '
-	echo "in-pack: 12" > count3.expected &&
+	echo "in-pack: 6" > count3.expected &&
 	GIT_DIR=shallow3/.git git count-objects -v |
 		grep "^in-pack" > count3.actual &&
 	test_cmp count3.expected count3.actual
-- 
1.7.11.rc1.185.g281ad67

                 reply	other threads:[~2012-06-22  9:36 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=1340357747-31711-1-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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).