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

Re: fatal: bad revision 'HEAD'

From
Jeff King <peff@peff.net>
Date
Aug 12, 2009, 07:58 UTC
Message-ID
<20090812075833.GF15152@coredump.intra.peff.net>
In-Reply-To
<7v7hx98otz.fsf@alter.siamese.dyndns.org>
On Wed, Aug 12, 2009 at 12:37:44AM -0700, Junio C Hamano wrote:
> But just like we twisted the definition of merge to mean "merging
> something into nothing yields that something", we could twist the
> definition of rebase to mean "rebasing nothing on top of something result
> in that something".  It sort of makes sense in a twisted way.
I dunno. It doesn't seem all that twisted to me.

But like many of the "branch to be born" and "initial commit" edge cases we have dealt with, it is not so much about somebody intentionally triggering this as it is about doing something sane when some script _does_ trigger it. And I think the sane thing is obvious and easy to do here, so why not?

>  * Is "rev-parse -q --verify" a safe test to guarantee that HEAD is
>    unborn?  Shouldn't we be checking with "symbolic-ref" or something?

I'm not sure. The test in git-checkout, for example, seems to basically just be looking up HEAD as a commit. If it doesn't work, then the branch is to-be-born (see switch_branches in builtin-checkout.c).

Which is more or less what's happening here (except we don't check that the type is a commit).

With symbolic-ref, I guess we could find out what the ref is, and check to see if _that_ exists. But I can't think of a situation where that would be meaningfully different than just resolving HEAD. Obviously detached HEADs come to mind, but wouldn't you then by definition not be a branch-to-be-born, which is what this rev-parse test would tell you?

Show 13 quoted lines
>  * In such an "unborn branch" case, by definition, a non-empty index won't
>    be based on whatever we are pulling down from the remote.  So how about
>    doing something like the following instead?
> 
> 	if on unborn branch
> 	then
> 		if test -f "$GIT_DIR/index"
>                 then
> 			die "refusing to update; you have a non-empty index"
> 		fi
> 	else
> 		... existing tests against HEAD ...
> 	fi

Yeah, I think that is a better idea. Do you want to tweak the patch, or should I re-submit?

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 11 in “fatal: bad revision 'HEAD'”
  1. Joel MahoneyAug 9, 2009
  2. Jeff KingAug 10, 2009
  3. Jeff KingAug 12, 2009
  4. Junio C HamanoAug 12, 2009
  5. Jeff KingAug 12, 2009
  6. Junio C HamanoAug 12, 2009
  7. Jeff KingAug 13, 2009
  8. Junio C HamanoAug 13, 2009
  9. Jeff KingAug 13, 2009
  10. Joel MahoneyAug 13, 2009
  11. Jeff KingAug 13, 2009

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.