git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] clone: do not segfault when specifying a nonexistent branch

From
Ralf Thielow <ralf.thielow@gmail.com>
Date
Oct 9, 2013, 16:38 UTC
Message-ID
<CAN0XMOLRt=kJPNhNDSfY_oMV90Xp=_wY=yf0OhiAcaShhWLCnA@mail.gmail.com>
In-Reply-To
<CACsJy8BX_fWdsCGa4jnh4CbkSMxp7btOFjwzB9K0eRtjUR_F-Q@mail.gmail.com>
On Sat, Oct 5, 2013 at 1:55 AM, Duy Nguyen <pclouds@gmail.com> wrote:
Show 31 quoted lines
> On Fri, Oct 4, 2013 at 9:20 PM, Stefan Beller
> <stefanbeller@googlemail.com> wrote:
>> I think we should emit a warning additionally?
>>
>> Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>
>
> I think it's nice to credit Robert for reporting the fault in the
> commit message (something like "reported-by:" or "noticed-by:"...)
>
>> ---
>>  builtin/clone.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/builtin/clone.c b/builtin/clone.c
>> index 0aff974..b764ad0 100644
>> --- a/builtin/clone.c
>> +++ b/builtin/clone.c
>> @@ -688,7 +688,7 @@ static void write_refspec_config(const char* src_ref_prefix,
>>
>>         if (option_mirror || !option_bare) {
>>                 if (option_single_branch && !option_mirror) {
>> -                       if (option_branch) {
>> +                       if (option_branch && our_head_points_at) {
>>                                 if (strstr(our_head_points_at->name, "refs/tags/"))
>>                                         strbuf_addf(&value, "+%s:%s", our_head_points_at->name,
>>                                                 our_head_points_at->name);
>
> This prevents the segfault, but what about remote.*.fetch? Should we
> setup standard refspec for fetch or..?
> --
> Duy

This segfault only happens when cloning an empty repository and only with option "--single-branch". Or do I miss something?

If we call "git clone" for a non-empty repository with a non-existing branch using "[--single-branch] --branch foo" then Git will abort with a message that the branch doesn't exist in upstream.

In an empty upstream repo the branch doesn't exist, either. So why not abort with the same message? That would be consistent. Otherwise I'd just override the options "--single-branch" and "--branch" to "not set".

Ralf
Previous: Stefan BellerNext: Ralf Thielow
Message 7 of 9 in “Bug: Segmentation fault (core dumped)”
  1. Robert MitwickiOct 4, 2013
  2. clone: do not segfault when specifying a nonexistent branchStefan Beller, Oct 4, 2013
  3. Duy NguyenOct 4, 2013
  4. Stefan BellerOct 6, 2013
  5. Duy NguyenOct 7, 2013
  6. clone: do not segfault when specifying a nonexistent branchStefan Beller, Oct 8, 2013
  7. Ralf ThielowOct 9, 2013
  8. clone --branch: refuse to clone if upstream repo is emptyRalf Thielow, Oct 11, 2013
  9. Duy NguyenOct 14, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.