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 13, 2009, 02:31 UTC
Message-ID
<20090813023137.GA17358@coredump.intra.peff.net>
In-Reply-To
<7vab24ve97.fsf@alter.siamese.dyndns.org>
On Wed, Aug 12, 2009 at 03:49:56PM -0700, Junio C Hamano wrote:
Show 10 quoted lines
> When doing a "pull --rebase", we check to make sure that the index and
> working tree are clean. The index-clean check compares the index against
> HEAD. The test erroneously reports dirtiness if we don't have a HEAD yet.
> 
> 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, and will lose
> the local change.  Just check if $GIT_DIR/index exists and error out.
> 
> Signed-off-by: Jeff King <peff@peff.net>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Looks sane to me, but see below.
Show 5 quoted lines
> +		# On an unborn branch
> +		if test -f "$GIT_DIR/index"
> +		then
> +			die "updating an unborn branch with changes added to the index"
> +		fi

I had a brief moment where I thought this might not actually be sufficient. That is, can somebody create an unborn branch in an existing repo (e.g., because they want an alternate project root) in such a way that they have an index, but it is empty? In which case we should be actually checking for index emptiness instead of existence.

I.e., I have done in the past (but not frequently):
  git symbolic-ref HEAD refs/heads/to-be-born

in an existing repository to create a new root. But I don't think we really need to worry about that case:

  1. It is somewhat crazy and rare in the first place. Even more crazy
     and rare would be to "git pull --rebase" immediately afterwards.
  2. If you _did_ have an index, either:
     2a. You want to keep it, in which case your check is sane.
     2b. You want to start fresh, in which case your next step would be
         be "rm -f .git/index".
The only way this check would not be OK is is if you did something like:
  git symbolic-ref HEAD refs/heads/new-branch
  git ls-files | xargs git rm --cached
  git pull --rebase ...
which just seems crazy.

So I think I have convinced myself that what you have is fine, but I just wanted a sanity check.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 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.