{"thread":{"id":"30866","subject":"[PATCH] clone: fix ref selection in --single-branch --branch=xxx","startedAt":"2012-06-22T09:35:47Z","lastAt":"2012-06-22T09:35:47Z","messageCount":1,"participants":["Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"194065","messageId":"1340357747-31711-1-git-send-email-pclouds@gmail.com","threadId":"30866","inReplyTo":null,"subject":"[PATCH] clone: fix ref selection in --single-branch --branch=xxx","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2012-06-22T09:35:47Z","receivedAt":"2012-06-22T09:35:47Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":" - do not fetch HEAD\n - do not also fetch refs following \"xxx\"\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n On Tue, Jun 12, 2012 at 4:14 AM, Jeff King <peff@peff.net> wrote:\n > [1] It looks like \"--single-branch\" does not actually work, and still\n >    fetches master. I think this is a bug in the implementation of\n >    single-branch (it looks like it fetches HEAD unconditionally).\n >    +cc Duy.\n\n Yep, my bad.\n\n builtin/clone.c       | 7 +++++--\n t/t5500-fetch-pack.sh | 7 ++++++-\n 2 files changed, 11 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 7f3b982..d3b7fdc 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -433,8 +433,11 @@ static struct ref *wanted_peer_refs(const struct ref *refs,\n \n \t\tif (!option_branch)\n \t\t\tremote_head = guess_remote_head(head, refs, 0);\n-\t\telse\n-\t\t\tremote_head = find_remote_branch(refs, option_branch);\n+\t\telse {\n+\t\t\tlocal_refs = NULL;\n+\t\t\ttail = &local_refs;\n+\t\t\tremote_head = copy_ref(find_remote_branch(refs, option_branch));\n+\t\t}\n \n \t\tif (!remote_head && option_branch)\n \t\t\twarning(_(\"Could not find remote branch %s to clone.\"),\ndiff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh\nindex 1d1ca98..e80a2af 100755\n--- a/t/t5500-fetch-pack.sh\n+++ b/t/t5500-fetch-pack.sh\n@@ -125,6 +125,11 @@ test_expect_success 'single branch object count' '\n \ttest_cmp expected count.singlebranch\n '\n \n+test_expect_success 'single given branch clone' '\n+\tgit clone --single-branch --branch A \"file://$(pwd)/.\" branch-a &&\n+\ttest_must_fail git --git-dir=branch-a/.git rev-parse origin/B\n+'\n+\n test_expect_success 'clone shallow' '\n \tgit clone --no-single-branch --depth 2 \"file://$(pwd)/.\" shallow\n '\n@@ -276,7 +281,7 @@ test_expect_success 'clone shallow with --branch' '\n '\n \n test_expect_success 'clone shallow object count' '\n-\techo \"in-pack: 12\" > count3.expected &&\n+\techo \"in-pack: 6\" > count3.expected &&\n \tGIT_DIR=shallow3/.git git count-objects -v |\n \t\tgrep \"^in-pack\" > count3.actual &&\n \ttest_cmp count3.expected count3.actual\n-- \n1.7.11.rc1.185.g281ad67\n"}]}