{"thread":{"id":"35063","subject":"Bug: Segmentation fault (core dumped)","startedAt":"2013-10-04T13:54:30Z","lastAt":"2013-10-14T19:08:38Z","messageCount":9,"participants":["Robert Mitwicki","Stefan Beller","Duy Nguyen","Ralf Thielow"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"228558","messageId":"524EC896.3050703@opensoftware.pl","threadId":"35063","inReplyTo":null,"subject":"Bug: Segmentation fault (core dumped)","fromName":"Robert Mitwicki","fromEmail":"robert.mitwicki@opensoftware.pl","sentAt":"2013-10-04T13:54:30Z","receivedAt":"2013-10-04T13:54:30Z","isPatch":false,"sender":{"key":"robert.mitwicki@opensoftware.pl","avatar":null},"body":"Hi,\n\nWhen I am trying to clone an empty repository and I will use together\n--depth 1 and -b branch_name (branch does not exist) then I get\nSegmentation fault (repo seems to be cloned correctly).\n\nPlease see attachment for more details.\nBest regards\nRobert Mitwicki\n\n\n>  git clone --depth 1 -b test https://github.com/mitfik/coredump.git /tmp/coredump.git\nCloning into '/tmp/coredump.git'...\nwarning: You appear to have cloned an empty repository.\nSegmentation fault (core dumped)\nUnexpected end of command stream\n\n> git --version\ngit version 1.8.4\n\n(gdb) info registers\nrax            0x0      0\nrbx            0x0      0\nrcx            0x0      0\nrdx            0x72     114\nrsi            0x519d04 5348612\nrdi            0x58     88\nrbp            0x7d9680 0x7d9680\nrsp            0x7fffffffd8f8   0x7fffffffd8f8\nr8             0x7fffffffe30b   140737488347915\nr9             0x58     88\nr10            0x7fffffffd6c0   140737488344768\nr11            0x7ffff72c1d50   140737340251472\nr12            0x0      0\nr13            0x1      1\nr14            0x58     88\nr15            0x0      0\nrip            0x7ffff72c1d68   0x7ffff72c1d68\neflags         0x10206  [ PF IF RF ]\ncs             0x33     51\nss             0x2b     43\nds             0x0      0\nes             0x0      0\nfs             0x0      0\ngs             0x0      0\n\n\n\n(gdb) bt\n#0  0x00007ffff72c1d68 in ?? () from /lib/x86_64-linux-gnu/libc.so.6\n#1  0x00000000004204a0 in ?? ()\n#2  0x0000000000405b84 in ?? ()\n#3  0x0000000000404f6d in ?? ()\n#4  0x00007ffff71af76d in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6\n#5  0x00000000004053b9 in ?? ()\n#6  0x00007fffffffe078 in ?? ()\n#7  0x000000000000001c in ?? ()\n#8  0x0000000000000008 in ?? ()\n#9  0x00007fffffffe2eb in ?? ()\n#10 0x00007fffffffe310 in ?? ()\n#11 0x00007fffffffe337 in ?? ()\n#12 0x0000000000000000 in ?? ()\n\n\n(gdb)  x/60x $sp\n0x7fffffffd8f8: 0x00000000      0x00000000      0x007d9680      0x00000000\n0x7fffffffd908: 0x00000000      0x00000000      0x00000001      0x00000000\n0x7fffffffd918: 0x00000058      0x00000000      0x00000000      0x00000000\n0x7fffffffd928: 0x004204a0      0x00000000      0xffffe30b      0x00007fff\n0x7fffffffd938: 0xf7fdcd20      0x00007fff      0x007d1fd0      0x00000000\n0x7fffffffd948: 0x00000000      0x00000000      0xffffdd60      0x00007fff\n0x7fffffffd958: 0xffffdad0      0x00000000      0x00000000      0x00000000\n0x7fffffffd968: 0x00000000      0x00000000      0x00000000      0x00000000\n0x7fffffffd978: 0xf7fdb630      0x00007fff      0x00000001      0x00007fff\n0x7fffffffd988: 0x00000000      0x00000000      0x00000001      0xffffefbd\n0x7fffffffd998: 0xf7fdc9c8      0x00007fff      0x003b4700      0x00000000\n0x7fffffffd9a8: 0x003b4700      0x00000000      0x00003900      0x00000000\n0x7fffffffd9b8: 0xffffddd0      0x00007fff      0xffffde50      0x00007fff\n0x7fffffffd9c8: 0xf7ffa4c8      0x00007fff      0x00000000      0x00000000\n0x7fffffffd9d8: 0xf7fdcd20      0x00007fff      0xffffdb30      0x00000001\n"},{"id":"228561","messageId":"1380896459-6451-1-git-send-email-stefanbeller@googlemail.com","threadId":"35063","inReplyTo":"524EC896.3050703@opensoftware.pl","subject":"[PATCH] clone: do not segfault when specifying a nonexistent branch","fromName":"Stefan Beller","fromEmail":"stefanbeller@googlemail.com","sentAt":"2013-10-04T14:20:59Z","receivedAt":"2013-10-04T14:20:59Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"I think we should emit a warning additionally?\n\nSigned-off-by: Stefan Beller <stefanbeller@googlemail.com>\n---\n builtin/clone.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 0aff974..b764ad0 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -688,7 +688,7 @@ static void write_refspec_config(const char* src_ref_prefix,\n \n \tif (option_mirror || !option_bare) {\n \t\tif (option_single_branch && !option_mirror) {\n-\t\t\tif (option_branch) {\n+\t\t\tif (option_branch && our_head_points_at) {\n \t\t\t\tif (strstr(our_head_points_at->name, \"refs/tags/\"))\n \t\t\t\t\tstrbuf_addf(&value, \"+%s:%s\", our_head_points_at->name,\n \t\t\t\t\t\tour_head_points_at->name);\n-- \n1.8.4.1.469.gb38b9db\n"},{"id":"228566","messageId":"CACsJy8BX_fWdsCGa4jnh4CbkSMxp7btOFjwzB9K0eRtjUR_F-Q@mail.gmail.com","threadId":"35063","inReplyTo":"1380896459-6451-1-git-send-email-stefanbeller@googlemail.com","subject":"Re: [PATCH] clone: do not segfault when specifying a nonexistent branch","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-10-04T23:55:30Z","receivedAt":"2013-10-04T23:55:30Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, Oct 4, 2013 at 9:20 PM, Stefan Beller\n<stefanbeller@googlemail.com> wrote:\n> I think we should emit a warning additionally?\n>\n> Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>\n\nI think it's nice to credit Robert for reporting the fault in the\ncommit message (something like \"reported-by:\" or \"noticed-by:\"...)\n\n> ---\n>  builtin/clone.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/builtin/clone.c b/builtin/clone.c\n> index 0aff974..b764ad0 100644\n> --- a/builtin/clone.c\n> +++ b/builtin/clone.c\n> @@ -688,7 +688,7 @@ static void write_refspec_config(const char* src_ref_prefix,\n>\n>         if (option_mirror || !option_bare) {\n>                 if (option_single_branch && !option_mirror) {\n> -                       if (option_branch) {\n> +                       if (option_branch && our_head_points_at) {\n>                                 if (strstr(our_head_points_at->name, \"refs/tags/\"))\n>                                         strbuf_addf(&value, \"+%s:%s\", our_head_points_at->name,\n>                                                 our_head_points_at->name);\n\nThis prevents the segfault, but what about remote.*.fetch? Should we\nsetup standard refspec for fetch or..?\n-- \nDuy\n"},{"id":"228577","messageId":"52512CF8.2070205@googlemail.com","threadId":"35063","inReplyTo":"CACsJy8BX_fWdsCGa4jnh4CbkSMxp7btOFjwzB9K0eRtjUR_F-Q@mail.gmail.com","subject":"Re: [PATCH] clone: do not segfault when specifying a nonexistent branch","fromName":"Stefan Beller","fromEmail":"stefanbeller@googlemail.com","sentAt":"2013-10-06T09:27:20Z","receivedAt":"2013-10-06T09:27:20Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On 10/05/2013 01:55 AM, Duy Nguyen wrote:\n> On Fri, Oct 4, 2013 at 9:20 PM, Stefan Beller\n> <stefanbeller@googlemail.com> wrote:\n>> I think we should emit a warning additionally?\n>>\n>> Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>\n> \n> I think it's nice to credit Robert for reporting the fault in the\n> commit message (something like \"reported-by:\" or \"noticed-by:\"...)\n\nI'll do so in a resend.\n\n> \n>> ---\n>>  builtin/clone.c | 2 +-\n>>  1 file changed, 1 insertion(+), 1 deletion(-)\n>>\n>> diff --git a/builtin/clone.c b/builtin/clone.c\n>> index 0aff974..b764ad0 100644\n>> --- a/builtin/clone.c\n>> +++ b/builtin/clone.c\n>> @@ -688,7 +688,7 @@ static void write_refspec_config(const char* src_ref_prefix,\n>>\n>>         if (option_mirror || !option_bare) {\n>>                 if (option_single_branch && !option_mirror) {\n>> -                       if (option_branch) {\n>> +                       if (option_branch && our_head_points_at) {\n>>                                 if (strstr(our_head_points_at->name, \"refs/tags/\"))\n>>                                         strbuf_addf(&value, \"+%s:%s\", our_head_points_at->name,\n>>                                                 our_head_points_at->name);\n> \n> This prevents the segfault, but what about remote.*.fetch? Should we\n> setup standard refspec for fetch or..?\n> \n\nLooking at the code a few lines below, this comment comes up:\n\n\t/*\n\t * otherwise, the next \"git fetch\" will\n\t * simply fetch from HEAD without updating\n\t * any remote-tracking branch, which is what\n\t * we want.\n\t */\n\nThis behavior was good for the case (!option_branch && !remote_head_points_at)\nNow we extend that behavior doing nothing to\n\t ((!option_branch || !our_head_points_at) &&  !remote_head_points_at)\n\nI am not sure how to handle that case best. The user has given a non existing branch,\nso it doesn't make sense to track that branch, but only have that \nregistered as a remote*.fetch?\n\nReading the documentation enhancements of 31b808a \n(2012-09-20, clone --single: limit the fetch refspec to fetched branch), doesn't \ntalk about this corner case. So maybe the remote.*.fetch shall be set, but no branch\nshould be checked out, when running \ngit clone --depth 1 -b test https://github.com/mitfik/coredump.git /tmp/coredump.git\n\nDoes that make sense?\n\nStefan\n"},{"id":"228595","messageId":"CACsJy8D+a=agXppSRT0C_w_9a5nGwomDp=8tiN5GPWtrpCKHRQ@mail.gmail.com","threadId":"35063","inReplyTo":"52512CF8.2070205@googlemail.com","subject":"Re: [PATCH] clone: do not segfault when specifying a nonexistent branch","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-10-07T10:46:23Z","receivedAt":"2013-10-07T10:46:23Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Oct 6, 2013 at 4:27 PM, Stefan Beller\n<stefanbeller@googlemail.com> wrote:\n>>> @@ -688,7 +688,7 @@ static void write_refspec_config(const char* src_ref_prefix,\n>>>\n>>>         if (option_mirror || !option_bare) {\n>>>                 if (option_single_branch && !option_mirror) {\n>>> -                       if (option_branch) {\n>>> +                       if (option_branch && our_head_points_at) {\n>>>                                 if (strstr(our_head_points_at->name, \"refs/tags/\"))\n>>>                                         strbuf_addf(&value, \"+%s:%s\", our_head_points_at->name,\n>>>                                                 our_head_points_at->name);\n>>\n>> This prevents the segfault, but what about remote.*.fetch? Should we\n>> setup standard refspec for fetch or..?\n>>\n>\n> Looking at the code a few lines below, this comment comes up:\n>\n>         /*\n>          * otherwise, the next \"git fetch\" will\n>          * simply fetch from HEAD without updating\n>          * any remote-tracking branch, which is what\n>          * we want.\n>          */\n>\n> This behavior was good for the case (!option_branch && !remote_head_points_at)\n> Now we extend that behavior doing nothing to\n>          ((!option_branch || !our_head_points_at) &&  !remote_head_points_at)\n>\n> I am not sure how to handle that case best. The user has given a non existing branch,\n> so it doesn't make sense to track that branch, but only have that\n> registered as a remote*.fetch?\n>\n> Reading the documentation enhancements of 31b808a\n> (2012-09-20, clone --single: limit the fetch refspec to fetched branch), doesn't\n> talk about this corner case. So maybe the remote.*.fetch shall be set, but no branch\n> should be checked out, when running\n> git clone --depth 1 -b test https://github.com/mitfik/coredump.git /tmp/coredump.git\n>\n> Does that make sense?\n\nLooking further back to 86ac751 (Allow cloning an empty repository -\n2009-01-23), the reason to allow cloning an empty repository is so\nthat the user does not have do manual configuration, so I agree with\nyour \"maybe\". git-clone.txt should have a short description about this\ntoo in case somebody runs into this and cares enough to check the\ndocument before heading to Stack Overflow.\n-- \nDuy\n"},{"id":"228605","messageId":"1381226765-19390-1-git-send-email-stefanbeller@googlemail.com","threadId":"35063","inReplyTo":"CACsJy8D+a=agXppSRT0C_w_9a5nGwomDp=8tiN5GPWtrpCKHRQ@mail.gmail.com","subject":"[PATCH] clone: do not segfault when specifying a nonexistent branch","fromName":"Stefan Beller","fromEmail":"stefanbeller@googlemail.com","sentAt":"2013-10-08T10:06:05Z","receivedAt":"2013-10-08T10:06:05Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Actually I only wanted to change one line to prevent a crash, when you\nspecify a non existing branch when cloning:\n-\t\t\tif (option_branch) {\n+\t\t\tif (option_branch && our_head_points_at) {\n\nHowever it turns out this is not a good idea as we still want to setup\n'remote.*.fetch', which previously depended the string buffer 'value'\nbeing non empty.\nTherefore I added a local variable 'set_remote', which determines whether\nwe want to setup 'remote.*.fetch'.\n\n\nWhile staring at the code, I also think it is a good idea to restructure\nthe if clauses a little as previously we had\n\tif (option_mirror || !option_bare) {\n\t\tif (option_single_branch && !option_mirror) {\nThe 'option_mirror' is part of both ifs, but opposing each other.\nThis is not yet done in this patch, as it still needs some thinking how to\nremove the nesting of the if clauses in a nice way.\n\nReported-by: Robert Mitwicki <robert.mitwicki@opensoftware.pl>\nSigned-off-by: Stefan Beller <stefanbeller@googlemail.com>\n---\n builtin/clone.c | 50 ++++++++++++++++++++++++++++----------------------\n 1 file changed, 28 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 0aff974..8b9a78a 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -686,40 +686,46 @@ static void write_refspec_config(const char* src_ref_prefix,\n \tstruct strbuf key = STRBUF_INIT;\n \tstruct strbuf value = STRBUF_INIT;\n \n+\tint set_remote = 0;\n \tif (option_mirror || !option_bare) {\n+\t\tset_remote = 1;\n \t\tif (option_single_branch && !option_mirror) {\n \t\t\tif (option_branch) {\n-\t\t\t\tif (strstr(our_head_points_at->name, \"refs/tags/\"))\n-\t\t\t\t\tstrbuf_addf(&value, \"+%s:%s\", our_head_points_at->name,\n-\t\t\t\t\t\tour_head_points_at->name);\n-\t\t\t\telse\n-\t\t\t\t\tstrbuf_addf(&value, \"+%s:%s%s\", our_head_points_at->name,\n-\t\t\t\t\t\tbranch_top->buf, option_branch);\n+\t\t\t\tif (our_head_points_at) {\n+\t\t\t\t\tif (strstr(our_head_points_at->name, \"refs/tags/\"))\n+\t\t\t\t\t\tstrbuf_addf(&value, \"+%s:%s\", our_head_points_at->name,\n+\t\t\t\t\t\t\tour_head_points_at->name);\n+\t\t\t\t\telse\n+\t\t\t\t\t\tstrbuf_addf(&value, \"+%s:%s%s\", our_head_points_at->name,\n+\t\t\t\t\t\t\tbranch_top->buf, option_branch);\n+\t\t\t\t}\n \t\t\t} else if (remote_head_points_at) {\n \t\t\t\tstrbuf_addf(&value, \"+%s:%s%s\", remote_head_points_at->name,\n \t\t\t\t\t\tbranch_top->buf,\n \t\t\t\t\t\tskip_prefix(remote_head_points_at->name, \"refs/heads/\"));\n+\t\t\t} else {\n+\t\t\t\t/*\n+\t\t\t\t * otherwise, the next \"git fetch\" will\n+\t\t\t\t * simply fetch from HEAD without updating\n+\t\t\t\t * any remote-tracking branch, which is what\n+\t\t\t\t * we want.\n+\t\t\t\t */\n+\t\t\t\tset_remote = 0;\n \t\t\t}\n-\t\t\t/*\n-\t\t\t * otherwise, the next \"git fetch\" will\n-\t\t\t * simply fetch from HEAD without updating\n-\t\t\t * any remote-tracking branch, which is what\n-\t\t\t * we want.\n-\t\t\t */\n \t\t} else {\n \t\t\tstrbuf_addf(&value, \"+%s*:%s*\", src_ref_prefix, branch_top->buf);\n \t\t}\n-\t\t/* Configure the remote */\n-\t\tif (value.len) {\n-\t\t\tstrbuf_addf(&key, \"remote.%s.fetch\", option_origin);\n-\t\t\tgit_config_set_multivar(key.buf, value.buf, \"^$\", 0);\n-\t\t\tstrbuf_reset(&key);\n+\t}\n+\t/* Configure the remote */\n+\tif (set_remote) {\n+\t\tstrbuf_addf(&key, \"remote.%s.fetch\", option_origin);\n+\t\tgit_config_set_multivar(key.buf, value.buf, \"^$\", 0);\n+\t\tstrbuf_reset(&key);\n \n-\t\t\tif (option_mirror) {\n-\t\t\t\tstrbuf_addf(&key, \"remote.%s.mirror\", option_origin);\n-\t\t\t\tgit_config_set(key.buf, \"true\");\n-\t\t\t\tstrbuf_reset(&key);\n-\t\t\t}\n+\t\tif (option_mirror) {\n+\t\t\tstrbuf_addf(&key, \"remote.%s.mirror\", option_origin);\n+\t\t\tgit_config_set(key.buf, \"true\");\n+\t\t\tstrbuf_reset(&key);\n \t\t}\n \t}\n \n-- \n1.8.4.1.469.gb38b9db\n"},{"id":"228662","messageId":"CAN0XMOLRt=kJPNhNDSfY_oMV90Xp=_wY=yf0OhiAcaShhWLCnA@mail.gmail.com","threadId":"35063","inReplyTo":"CACsJy8BX_fWdsCGa4jnh4CbkSMxp7btOFjwzB9K0eRtjUR_F-Q@mail.gmail.com","subject":"Re: [PATCH] clone: do not segfault when specifying a nonexistent branch","fromName":"Ralf Thielow","fromEmail":"ralf.thielow@gmail.com","sentAt":"2013-10-09T16:38:02Z","receivedAt":"2013-10-09T16:38:02Z","isPatch":true,"sender":{"key":"ralf.thielow@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1275832?v=4"},"body":"On Sat, Oct 5, 2013 at 1:55 AM, Duy Nguyen <pclouds@gmail.com> wrote:\n> On Fri, Oct 4, 2013 at 9:20 PM, Stefan Beller\n> <stefanbeller@googlemail.com> wrote:\n>> I think we should emit a warning additionally?\n>>\n>> Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>\n>\n> I think it's nice to credit Robert for reporting the fault in the\n> commit message (something like \"reported-by:\" or \"noticed-by:\"...)\n>\n>> ---\n>>  builtin/clone.c | 2 +-\n>>  1 file changed, 1 insertion(+), 1 deletion(-)\n>>\n>> diff --git a/builtin/clone.c b/builtin/clone.c\n>> index 0aff974..b764ad0 100644\n>> --- a/builtin/clone.c\n>> +++ b/builtin/clone.c\n>> @@ -688,7 +688,7 @@ static void write_refspec_config(const char* src_ref_prefix,\n>>\n>>         if (option_mirror || !option_bare) {\n>>                 if (option_single_branch && !option_mirror) {\n>> -                       if (option_branch) {\n>> +                       if (option_branch && our_head_points_at) {\n>>                                 if (strstr(our_head_points_at->name, \"refs/tags/\"))\n>>                                         strbuf_addf(&value, \"+%s:%s\", our_head_points_at->name,\n>>                                                 our_head_points_at->name);\n>\n> This prevents the segfault, but what about remote.*.fetch? Should we\n> setup standard refspec for fetch or..?\n> --\n> Duy\n\nThis segfault only happens when cloning an empty repository and only with option\n\"--single-branch\". Or do I miss something?\n\nIf we call \"git clone\" for a non-empty repository with a non-existing branch\nusing \"[--single-branch] --branch foo\" then Git will abort with a message that\nthe branch doesn't exist in upstream.\n\nIn an empty upstream repo the branch doesn't exist, either. So why not\nabort with\nthe same message? That would be consistent. Otherwise I'd just\noverride the options\n\"--single-branch\" and \"--branch\" to \"not set\".\n\nRalf\n"},{"id":"228743","messageId":"1381510142-3026-1-git-send-email-ralf.thielow@gmail.com","threadId":"35063","inReplyTo":"CAN0XMOLRt=kJPNhNDSfY_oMV90Xp=_wY=yf0OhiAcaShhWLCnA@mail.gmail.com","subject":"[PATCH] clone --branch: refuse to clone if upstream repo is empty","fromName":"Ralf Thielow","fromEmail":"ralf.thielow@gmail.com","sentAt":"2013-10-11T16:49:02Z","receivedAt":"2013-10-11T16:49:02Z","isPatch":true,"sender":{"key":"ralf.thielow@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1275832?v=4"},"body":"Since 920b691 (clone: refuse to clone if --branch\npoints to bogus ref) we refuse to clone with option\n\"-b\" if the specified branch does not exist in the\n(non-empty) upstream. If the upstream repository is empty,\nthe branch doesn't exist, either. So refuse the clone too.\n\nSigned-off-by: Ralf Thielow <ralf.thielow@gmail.com>\n---\n builtin/clone.c         | 4 ++++\n t/t5706-clone-branch.sh | 8 +++++++-\n 2 files changed, 11 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex ca3eb68..5af386e 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -945,6 +945,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \t\t\tour_head_points_at = remote_head_points_at;\n \t}\n \telse {\n+\t\tif (option_branch)\n+\t\t\tdie(_(\"Remote branch %s not found in upstream %s\"),\n+\t\t\t\t\toption_branch, option_origin);\n+\n \t\twarning(_(\"You appear to have cloned an empty repository.\"));\n \t\tmapped_refs = NULL;\n \t\tour_head_points_at = NULL;\ndiff --git a/t/t5706-clone-branch.sh b/t/t5706-clone-branch.sh\nindex 56be67e..6e7a7be 100755\n--- a/t/t5706-clone-branch.sh\n+++ b/t/t5706-clone-branch.sh\n@@ -20,7 +20,9 @@ test_expect_success 'setup' '\n \t echo one >file && git add file && git commit -m one &&\n \t git checkout -b two &&\n \t echo two >file && git add file && git commit -m two &&\n-\t git checkout master)\n+\t git checkout master) &&\n+\tmkdir empty &&\n+\t(cd empty && git init)\n '\n \n test_expect_success 'vanilla clone chooses HEAD' '\n@@ -61,4 +63,8 @@ test_expect_success 'clone -b with bogus branch' '\n \ttest_must_fail git clone -b bogus parent clone-bogus\n '\n \n+test_expect_success 'clone -b not allowed with empty repos' '\n+\ttest_must_fail git clone -b branch empty clone-branch-empty\n+'\n+\n test_done\n-- \n1.8.4.652.g0d6e0ce\n"},{"id":"228941","messageId":"CACsJy8AgU89=s4P+28Smp5Vysbc06GhaN-o0Rw3N-OEOVbhLRA@mail.gmail.com","threadId":"35063","inReplyTo":"1381510142-3026-1-git-send-email-ralf.thielow@gmail.com","subject":"Re: [PATCH] clone --branch: refuse to clone if upstream repo is empty","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-10-14T19:08:38Z","receivedAt":"2013-10-14T19:08:38Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, Oct 11, 2013 at 11:49 PM, Ralf Thielow <ralf.thielow@gmail.com> wrote:\n> Since 920b691 (clone: refuse to clone if --branch\n> points to bogus ref) we refuse to clone with option\n> \"-b\" if the specified branch does not exist in the\n> (non-empty) upstream. If the upstream repository is empty,\n> the branch doesn't exist, either. So refuse the clone too.\n\nYeah, much simpler approach :)\n\n> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>\n> ---\n>  builtin/clone.c         | 4 ++++\n>  t/t5706-clone-branch.sh | 8 +++++++-\n>  2 files changed, 11 insertions(+), 1 deletion(-)\n>\n> diff --git a/builtin/clone.c b/builtin/clone.c\n> index ca3eb68..5af386e 100644\n> --- a/builtin/clone.c\n> +++ b/builtin/clone.c\n> @@ -945,6 +945,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n>                         our_head_points_at = remote_head_points_at;\n>         }\n>         else {\n> +               if (option_branch)\n> +                       die(_(\"Remote branch %s not found in upstream %s\"),\n> +                                       option_branch, option_origin);\n> +\n>                 warning(_(\"You appear to have cloned an empty repository.\"));\n>                 mapped_refs = NULL;\n>                 our_head_points_at = NULL;\n> diff --git a/t/t5706-clone-branch.sh b/t/t5706-clone-branch.sh\n> index 56be67e..6e7a7be 100755\n> --- a/t/t5706-clone-branch.sh\n> +++ b/t/t5706-clone-branch.sh\n> @@ -20,7 +20,9 @@ test_expect_success 'setup' '\n>          echo one >file && git add file && git commit -m one &&\n>          git checkout -b two &&\n>          echo two >file && git add file && git commit -m two &&\n> -        git checkout master)\n> +        git checkout master) &&\n> +       mkdir empty &&\n> +       (cd empty && git init)\n>  '\n>\n>  test_expect_success 'vanilla clone chooses HEAD' '\n> @@ -61,4 +63,8 @@ test_expect_success 'clone -b with bogus branch' '\n>         test_must_fail git clone -b bogus parent clone-bogus\n>  '\n>\n> +test_expect_success 'clone -b not allowed with empty repos' '\n> +       test_must_fail git clone -b branch empty clone-branch-empty\n> +'\n> +\n>  test_done\n> --\n> 1.8.4.652.g0d6e0ce\n>\n\n\n\n-- \nDuy\n"}]}