Re: [PATCH] clone: do not segfault when specifying a nonexistent branch
- From
Stefan Beller <stefanbeller@googlemail.com>
- Date
- Oct 6, 2013, 09:27 UTC
- Message-ID
- <52512CF8.2070205@googlemail.com>
- In-Reply-To
- <CACsJy8BX_fWdsCGa4jnh4CbkSMxp7btOFjwzB9K0eRtjUR_F-Q@mail.gmail.com>
On 10/05/2013 01:55 AM, Duy Nguyen wrote:
Show 8 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:"...)
I'll do so in a resend.
Show 22 quoted lines
>
>> ---
>> 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..?
> Looking at the code a few lines below, this comment comes up:
/* * otherwise, the next "git fetch" will * simply fetch from HEAD without updating * any remote-tracking branch, which is what * we want. */
This behavior was good for the case (!option_branch && !remote_head_points_at) Now we extend that behavior doing nothing to ((!option_branch || !our_head_points_at) && !remote_head_points_at)
I am not sure how to handle that case best. The user has given a non existing branch, so it doesn't make sense to track that branch, but only have that registered as a remote*.fetch?
Reading the documentation enhancements of 31b808a (2012-09-20, clone --single: limit the fetch refspec to fetched branch), doesn't talk about this corner case. So maybe the remote.*.fetch shall be set, but no branch should be checked out, when running git clone --depth 1 -b test https://github.com/mitfik/coredump.git /tmp/coredump.git
Does that make sense?
Stefan