threads / discuss / 38596

[Discuss] soften warning message after cloning "void"

Subject: [Discuss] soften warning message after cloning "void"

## tl;dr

9 messages between Feb 18, 2015 and Feb 21, 2015.

replies: 8people: 3as markdown or json

Junio C Hamano· Feb 18, 2015, 23:24 UTC · lore
If you did this:
    $ git init void &&
      git -C void commit --allow-empty -m initial &&
      git -C void symbolic-ref HEAD refs/heads/nosuch
    $ git clone --no-local void new
you would get
    warning: remote HEAD refers to nonexistent ref, unable to checkout.

While it is correct that we are unable to perform the normal "checkout" of their primary branch that their HEAD points at, it was reported that some users find this message unnecessarily alarming.

Rephrase by saying what we decided to do, instead of only stating what led us to that decision without telling what that decision is. That is, "(because we cannot checkout), we left the HEAD pointing at an unborn branch."

---
 builtin/clone.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 9572467..c7f1bf2 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -625,8 +625,8 @@ static int checkout(void)
 
 	head = resolve_refdup("HEAD", RESOLVE_REF_READING, sha1, NULL);
 	if (!head) {
-		warning(_("remote HEAD refers to nonexistent ref, "
-			  "unable to checkout.\n"));
+		warning(_("remote HEAD refers to nonexistent ref; "
+			  "leaving the current branch unborn.\n"));
 		return 0;
 	}
 	if (!strcmp(head, "HEAD")) {
Stefan Beller· Feb 19, 2015, 00:13 UTC · re: Junio C Hamano · lore

Re: [Discuss] soften warning message after cloning "void"

On Wed, Feb 18, 2015 at 3:24 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 10 quoted lines
> If you did this:
>
>     $ git init void &&
>       git -C void commit --allow-empty -m initial &&
>       git -C void symbolic-ref HEAD refs/heads/nosuch
>     $ git clone --no-local void new
>
> you would get
>
>     warning: remote HEAD refers to nonexistent ref, unable to checkout.

I think there is another problem. $ git status On branch master

Initial commit
which makes no sense.
So after playing around I found:
$ git init void &&
   git -C void commit --allow-empty -m initial &&
   touch void/asdf
   git -C void add asdf
   git -C void commit -a -m "add a file"
   git -C void symbolic-ref HEAD refs/heads/nosuch
   git clone --no-local void new

This yields the warning as above and git status still tells us we're on master. Though ls new shows an empty directory/repository. After a `git checkout master` we can see the file and all is good to go.

How did we know we are on the master branch in the first place? (and not on foo/bar, HEAD is pointing at nonsense!) So what is the `current branch` of your new error message referring to?

Why did git status claim to be on branch master, but the repository state was not in masters state, but in the unborn state?

These questions asked, would it make sense to either add a git checkout `current branch` at the end of clone? (I suppose that is what HEAD is good for actually).

Also it would make sense to have it's own HEAD pointing to 0{40} or equivalent (just nothing) instead of having the master branch available.

Show 27 quoted lines
>
> While it is correct that we are unable to perform the normal
> "checkout" of their primary branch that their HEAD points at,
> it was reported that some users find this message unnecessarily
> alarming.
>
> Rephrase by saying what we decided to do, instead of only stating
> what led us to that decision without telling what that decision is.
> That is, "(because we cannot checkout), we left the HEAD pointing at
> an unborn branch."
>
> ---
>  builtin/clone.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/clone.c b/builtin/clone.c
> index 9572467..c7f1bf2 100644
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -625,8 +625,8 @@ static int checkout(void)
>
>         head = resolve_refdup("HEAD", RESOLVE_REF_READING, sha1, NULL);
>         if (!head) {
> -               warning(_("remote HEAD refers to nonexistent ref, "
> -                         "unable to checkout.\n"));
> +               warning(_("remote HEAD refers to nonexistent ref; "
> +                         "leaving the current branch unborn.\n"));

Personally I find that more confusing, because I have an idea of what checkout may refer to. The notion of an unborn branch is not clear to me. Maybe

> -               warning(_("remote HEAD refers to nonexistent ref, "
> -                         "unable to checkout.\n"));
> +               warning(_("remote HEAD refers to nonexistent ref; "
> +                         "Checking out $branch instead.\n"));

with $branch being master in the example above. I'd have no idea how to come up with a good heuristic which branch to checkout. (It would need to match current behavior)

Junio C Hamano· Feb 19, 2015, 00:25 UTC · re: Stefan Beller · lore

Re: [Discuss] soften warning message after cloning "void"

On Wed, Feb 18, 2015 at 4:13 PM, Stefan Beller <sbeller@google.com> wrote:
Show 16 quoted lines
>> +               warning(_("remote HEAD refers to nonexistent ref; "
>> +                         "leaving the current branch unborn.\n"));
>
> Personally I find that more confusing, because I have an idea of
> what checkout may refer to. The notion of an unborn branch is not
> clear to me.
> Maybe
>
>> -               warning(_("remote HEAD refers to nonexistent ref, "
>> -                         "unable to checkout.\n"));
>> +               warning(_("remote HEAD refers to nonexistent ref; "
>> +                         "Checking out $branch instead.\n"));
>
> with $branch being master in the example above. I'd have no idea
> how to come up with a good heuristic which branch to checkout.
> (It would need to match current behavior)

Checking out a random branch is absolutely the worst thing you can do. Personally, I would think that the best thing you can do is to educate your users not to clone from a void. Create some history that is worth sharing, and then push into an empty repository.

Shawn Pearce· Feb 19, 2015, 00:43 UTC · re: Junio C Hamano · lore

Re: [Discuss] soften warning message after cloning "void"

On Wed, Feb 18, 2015 at 4:25 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Checking out a random branch is absolutely the worst thing you can
> do. Personally, I would think that the best thing you can do is to
> educate your users not to clone from a void. Create some history
> that is worth sharing, and then push into an empty repository.
Users are dumb.

Consider a website like GitHub where you create a repository on a a remote server. It is initialized as an empty repo. They now want to clone that empty repo to work with it:

  git clone https://example.com/foo
  cd foo
  .... hack hack
  git commit -a -m "Foo is awesome!"
  git push

This works from git-core servers because the ref advertisement tells the client its an empty repo and its OK to checkout HEAD from nothing and its all fine.

This fails from a JGit server because the ref advertisement for an empty repository differs and disagrees with the format used by git-core. The result is a confused client spewing an odd checkout message.

Shawn Pearce· Feb 19, 2015, 00:46 UTC · re: Shawn Pearce · lore

Re: [Discuss] soften warning message after cloning "void"

On Wed, Feb 18, 2015 at 4:43 PM, Shawn Pearce <spearce@spearce.org> wrote:
Show 26 quoted lines
> On Wed, Feb 18, 2015 at 4:25 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Checking out a random branch is absolutely the worst thing you can
>> do. Personally, I would think that the best thing you can do is to
>> educate your users not to clone from a void. Create some history
>> that is worth sharing, and then push into an empty repository.
>
> Users are dumb.
>
> Consider a website like GitHub where you create a repository on a a
> remote server. It is initialized as an empty repo. They now want to
> clone that empty repo to work with it:
>
>   git clone https://example.com/foo
>   cd foo
>   .... hack hack
>   git commit -a -m "Foo is awesome!"
>   git push
>
> This works from git-core servers because the ref advertisement tells
> the client its an empty repo and its OK to checkout HEAD from nothing
> and its all fine.
>
> This fails from a JGit server because the ref advertisement for an
> empty repository differs and disagrees with the format used by
> git-core. The result is a confused client spewing an odd checkout
> message.

The difference in JGit is intentional. Our cross data center consistency system at $DAY_JOB depends on being able to fetch from one empty repository to another empty repository using the want any object capability, and side-band-64k. The JGit client and server code that speaks the wire protocol needs to send and see the capability lines for that to work, but with no refs there are no lines to send.

So we send capabilities^{} like receive-pack does. But git-core hates all over that during clone of an empty repo.

Junio C Hamano· Feb 19, 2015, 02:54 UTC · re: Shawn Pearce · lore

Re: [Discuss] soften warning message after cloning "void"

On Wed, Feb 18, 2015 at 4:43 PM, Shawn Pearce <spearce@spearce.org> wrote:
Show 5 quoted lines
>
> This fails from a JGit server because the ref advertisement for an
> empty repository differs and disagrees with the format used by
> git-core. The result is a confused client spewing an odd checkout
> message.
That is exactly why the rephrasing was brought up, wasn't it?

As the Subject: line says, this thread is for people who want to help those users with un-odd message, so discuss away and come up with a final applicable patch ;-).

Stefan Beller· Feb 19, 2015, 05:12 UTC · re: Junio C Hamano · lore

Re: [Discuss] soften warning message after cloning "void"

On Wed, Feb 18, 2015 at 6:54 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
> On Wed, Feb 18, 2015 at 4:43 PM, Shawn Pearce <spearce@spearce.org> wrote:
>>
>> This fails from a JGit server because the ref advertisement for an
>> empty repository differs and disagrees with the format used by
>> git-core. The result is a confused client spewing an odd checkout
>> message.
>
> That is exactly why the rephrasing was brought up, wasn't it?
>
> As the Subject: line says, this thread is for people who want to
> help those users with un-odd message, so discuss away
> and come up with a final applicable patch ;-).
"warning: remote HEAD does not exist, not checking out any branch."

would then be the correct answer. Are we able to detect between the two cases of a HEAD pointing to refs/heads/void and HEAD just not existing?

Junio C Hamano· Feb 21, 2015, 05:58 UTC · re: Stefan Beller · lore

Re: [Discuss] soften warning message after cloning "void"

Stefan Beller <sbeller@google.com> writes:
Show 17 quoted lines
> On Wed, Feb 18, 2015 at 6:54 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> On Wed, Feb 18, 2015 at 4:43 PM, Shawn Pearce <spearce@spearce.org> wrote:
>>>
>>> This fails from a JGit server because the ref advertisement for an
>>> empty repository differs and disagrees with the format used by
>>> git-core. The result is a confused client spewing an odd checkout
>>> message.
>>
>> That is exactly why the rephrasing was brought up, wasn't it?
>>
>> As the Subject: line says, this thread is for people who want to
>> help those users with un-odd message, so discuss away
>> and come up with a final applicable patch ;-).
>
> "warning: remote HEAD does not exist, not checking out any branch."
>
> would then be the correct answer.

Technically speaking, that is incorrect because HEAD already points at 'master'. We DO check out a 'master' branch. What is unusual is that the branch has not been born yet, and that is exactly the same state after 'git init' created an empty directory. I.e.

	$ git init new
        $ cd new
        $ git remote add origin $URL
	$ git symbolic-ref HEAD
        refs/heads/master

would be exactly the same place where you are when you see that message.

What we are not doing is not "not checking out". What we are not doing is to fast-forwarding the void to any of the branches the remote has, because we do not know which branch the remote wants us to start our history from by default.

So, "warning: not starting history of 'master' from any of the remote's branches, as their HEAD does not point to a valid branch" or something like that?

Stefan Beller· Feb 19, 2015, 00:47 UTC · re: Junio C Hamano · lore

Re: [Discuss] soften warning message after cloning "void"

On Wed, Feb 18, 2015 at 4:25 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 20 quoted lines
> On Wed, Feb 18, 2015 at 4:13 PM, Stefan Beller <sbeller@google.com> wrote:
>>> +               warning(_("remote HEAD refers to nonexistent ref; "
>>> +                         "leaving the current branch unborn.\n"));
>>
>> Personally I find that more confusing, because I have an idea of
>> what checkout may refer to. The notion of an unborn branch is not
>> clear to me.
>> Maybe
>>
>>> -               warning(_("remote HEAD refers to nonexistent ref, "
>>> -                         "unable to checkout.\n"));
>>> +               warning(_("remote HEAD refers to nonexistent ref; "
>>> +                         "Checking out $branch instead.\n"));
>>
>> with $branch being master in the example above. I'd have no idea
>> how to come up with a good heuristic which branch to checkout.
>> (It would need to match current behavior)
>
> Checking out a random branch is absolutely the worst thing you can
> do.

I agree on that, but why did I see the master branch checked out? (There was just one branch, so it's obvious which to checkout instead) But HEAD being broken, I would have expected

$ git clone ... remote HEAD refers to nonexistent ref, checking out nothing $ git status HEAD detached at (nothing)

> Personally, I would think that the best thing you can do is to
> educate your users not to clone from a void.

I disagree on that. The repository may be broken by tinkering (why would you run git -C void symbolic-ref HEAD refs/heads/nosuch anywazy?) and people want to clone it nevertheless.

> Create some history
> that is worth sharing, and then push into an empty repository.
I am not sure what you mean here.

← back to recent threads