git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Erik Faye-Lund <kusmabite@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Johannes Sixt <j.sixt@viscovery.net>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: git checkout creates strange '(null)'-branch
Date: Thu, 10 May 2012 16:22:47 +0200	[thread overview]
Message-ID: <CABPQNSbBwpVJUx9BSSO2nqAnPxUESZBz-GEqOPPEyqvdcutb6w@mail.gmail.com> (raw)
In-Reply-To: <7vd36ey70y.fsf@alter.siamese.dyndns.org>

On Tue, May 8, 2012 at 6:25 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Erik Faye-Lund <kusmabite@gmail.com> writes:
>
>> But if I apply the following patch, the test passes. I'm not saying
>> it's the right thing to do, though.
>>
>> (Warning: white-space damaged because of copying diffs between terminals)
>>
>> diff --git a/builtin/checkout.c b/builtin/checkout.c
>> index 23fc56d..d70e819 100644
>> --- a/builtin/checkout.c
>> +++ b/builtin/checkout.c
>> @@ -1096,8 +1096,11 @@ int cmd_checkout(int argc, const char **argv,
>> const char *prefix)
>>                 int flag;
>>
>>                 if (!read_ref_full("HEAD", rev, 0, &flag) &&
>> -                   (flag & REF_ISSYMREF) && is_null_sha1(rev))
>> +                   (flag & REF_ISSYMREF) && is_null_sha1(rev)) {
>> +                       if (!opts.new_branch)
>> +                               return 0;
>>                         return switch_unborn_to_new_branch(&opts);
>> +               }
>>         }
>>         return switch_branches(&opts, &new);
>>  }
>
> This patch, if we ignore submodules for a while, actually makes sense to
> me.  If you have a commit, you are on that commit and you haven't done
> anything since you have checked out that commit, "git checkout" (no other
> parameters) would be a no-op.  If you "git init" a repository, and you
> haven't done anything since then, the above makes "git checkout" (no other
> parameters) a no-op.

I agree. It does seem to make sense.

> Am I missing some corner cases that we _should_ error out, perhaps for the
> sake of safety?

I don't know, and I was kind of hoping someone would jump in and
enlighten me of something, but that didn't happen (yet).

I have a slight preference for this operation, though I'm not
religious; it simply seem more consistent with other "git checkout"
operation.

Do you want me to prepare a proper patch including a variation of the
test-case from the other patch?

  reply	other threads:[~2012-05-10 14:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-08 11:24 git checkout creates strange '(null)'-branch Erik Faye-Lund
2012-05-08 11:34 ` Johannes Sixt
2012-05-08 11:50   ` Erik Faye-Lund
2012-05-08 12:10     ` Andreas Schwab
2012-05-08 16:25     ` Junio C Hamano
2012-05-10 14:22       ` Erik Faye-Lund [this message]
2012-05-10 16:49         ` Junio C Hamano
2012-05-08 15:09   ` Junio C Hamano
2012-05-08 15:05 ` Junio C Hamano
2012-05-08 15:19 ` Junio C Hamano
2012-05-08 16:04   ` Erik Faye-Lund
2012-05-08 16:22     ` Junio C Hamano

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=CABPQNSbBwpVJUx9BSSO2nqAnPxUESZBz-GEqOPPEyqvdcutb6w@mail.gmail.com \
    --to=kusmabite@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.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).