Skip to contentSkip to conversation

soften warning message after cloning "void"

Discuss Junio C Hamano 3 participants 9 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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(-)
builtin/clone.c +2 -2
index 9572467..c7f1bf2 100644
@@ -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")) {
#1 lore raw
Quoted 10 lines · Junio C Hamano

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.

Quoted 20 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(-)
builtin/clone.c +0 -0
index 9572467..c7f1bf2 100644

builtin/clone.c static int checkout(void) · line 629

Quoted 7 lines
builtin/clone.c +2 -2
@@ -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

builtin/clone.c static int checkout(void)

Quoted 4 lines
builtin/clone.c +2 -2
-               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)

#2 lore raw
Quoted 8 lines · Stefan Beller

builtin/clone.c static int checkout(void) · line 629

Quoted 2 lines
builtin/clone.c +2 -0
+               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

Quoted 8 lines

builtin/clone.c static int checkout(void)

Quoted 4 lines
builtin/clone.c +2 -2
-               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.

#3 lore raw
Quoted 14 lines · Junio C Hamano
Quoted 13 lines · Stefan Beller

builtin/clone.c static int checkout(void) · line 629

Quoted 2 lines
builtin/clone.c +2 -0
+               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

Quoted 4 lines
builtin/clone.c +2 -2
-               warning(_("remote HEAD refers to nonexistent ref, "
-                         "unable to checkout.\n"));
+               warning(_("remote HEAD refers to nonexistent ref; "
+                         "Checking out $branch instead.\n"));
Quoted 6 lines
Quoted 3 lines

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)
Quoted 2 lines

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.

Quoted 2 lines

Create some history
that is worth sharing, and then push into an empty repository.

I am not sure what you mean here.

#4 lore raw
In reply to Junio C Hamano
Quoted 4 lines · Junio C Hamano

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.

#5 lore raw
Quoted 18 lines · Shawn Pearce
Quoted 4 lines · Junio C Hamano

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

Quoted 8 lines

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.

#6 lore raw
In reply to Shawn Pearce
Quoted 5 lines · Shawn Pearce

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 ;-).

#7 lore raw
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Shawn Pearce

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.

Quoted 5 lines

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?

#8 lore raw
Quoted 10 lines · Stefan Beller
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · Shawn Pearce

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?

Quoted 7 lines
Quoted 3 lines

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?