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

Re: [BUG] Git clone of a bundle fails, but works (somewhat) when run with strace

From
BGBram Geron <bgeron@bgeron.nl>
Date
May 28, 2014, 15:59 UTC
Message-ID
<loom.20140528T171956-380@post.gmane.org>
In-Reply-To
<20130216040109.GA31630@sigill.intra.peff.net>
Jeff King <peff <at> peff.net> writes:
Show 12 quoted lines
> [..]
> Secondly, I do get the same warning about HEAD:
> 
>   $ git clone repo.bundle repofrombundle
>   Cloning into 'repofrombundle'...
>   Receiving objects: 100% (3/3), done.
>   warning: remote HEAD refers to nonexistent ref, unable to checkout.
> 
> but that warning makes sense. You did not create a bundle that contains
> HEAD, therefore when we clone it, we do not know what to point HEAD to.
> You probably wanted "git bundle create ../repo.bundle --all" which
> includes both "master" and "HEAD".

I'd like to revive this discussion and submit a patch, as I just spent significant time wondering why git clone failed. It's been a while, so I'll summarize: when you make a git bundle without including HEAD explicitly, then clone from that bundle, Git throws a warning and leaves you with a broken HEAD.

I do not agree that the warning makes sense. It implies that HEAD exists but is invalid. In reality, no ref is referred to by HEAD in the first place. Furthermore, .git/HEAD in the clone is "autocorrected" to be refs/heads/master, so the error message is even more misleading.

It's like saying "Our CEO's guitar is actually an air guitar", then explaining where he stores his guitar, when I don't work in a company in the first place.

Show 5 quoted lines
> It would be slightly more accurate to say "the remote HEAD does not
> exist", rather than "refers to nonexistent ref".  It would perhaps be
> nicer still for "git clone" to make a guess about the correct HEAD when
> one is not present (especially in the single-branch case, it is easy to
> make the right guess).

Seems sensible at first sight, though it seems orthogonal to the warning message.

> Patches welcome. In the meantime, you can clone with "-b master" to tell
> it explicitly, or you can "git checkout master" inside the newly-cloned
> repository.
Alright :) See below.
Cheers, Bram
>From bc799b12b659d7ab20df7fe420d5f1f1c90450aa Mon Sep 17 00:00:00 2001
From: Bram Geron <bgeron@bgeron.nl>
Date: Wed, 28 May 2014 15:54:37 +0100
Subject: [PATCH] Clearer error message when cloning a bundle without a HEAD
 ref.
---
 builtin/clone.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 9b3c04d..e3c1447 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -623,7 +623,7 @@ static int checkout(void)
 
 	head = resolve_refdup("HEAD", sha1, 1, NULL);
 	if (!head) {
-		warning(_("remote HEAD refers to nonexistent ref, "
+		warning(_("no HEAD in remote or HEAD refers to nonexistent ref, "
 			  "unable to checkout.\n"));
 		return 0;
 	}
-- 
1.9.1
Previous: Junio C Hamano
Message 9 of 9 in “[BUG] Git clone of a bundle fails, but works (somewhat) when run with strace”
  1. Alain KalkerFeb 15, 2013
  2. Alain KalkerFeb 15, 2013
  3. Alain KalkerFeb 16, 2013
  4. Junio C HamanoFeb 16, 2013
  5. Jeff KingFeb 16, 2013
  6. Alain KalkerFeb 17, 2013
  7. Philip OakleyFeb 17, 2013
  8. Junio C HamanoFeb 25, 2013
  9. Bram GeronMay 28, 2014

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.