git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Joel Mahoney <joelmahoney@gmail.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	git@vger.kernel.org
Subject: Re: fatal: bad revision 'HEAD'
Date: Wed, 12 Aug 2009 22:31:37 -0400	[thread overview]
Message-ID: <20090813023137.GA17358@coredump.intra.peff.net> (raw)
In-Reply-To: <7vab24ve97.fsf@alter.siamese.dyndns.org>

On Wed, Aug 12, 2009 at 03:49:56PM -0700, Junio C Hamano wrote:

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

> +		# 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

  reply	other threads:[~2009-08-13  2:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-09 21:15 fatal: bad revision 'HEAD' Joel Mahoney
2009-08-10  1:18 ` Jeff King
     [not found]   ` <09EE2E57-626B-4686-A6DD-3B8DF1BC3FE2@gmail.com>
     [not found]     ` <20090811015615.GA8383@coredump.intra.peff.net>
     [not found]       ` <C44788EB-02BA-4D69-8091-9E97827223A0@gmail.com>
2009-08-12  3:27         ` Jeff King
2009-08-12  7:37           ` Junio C Hamano
2009-08-12  7:58             ` Jeff King
2009-08-12 22:49               ` Junio C Hamano
2009-08-13  2:31                 ` Jeff King [this message]
2009-08-13  4:36                   ` Junio C Hamano
2009-08-13  4:38                     ` Jeff King
2009-08-13  5:02                       ` Joel Mahoney
2009-08-13  5:10                         ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090813023137.GA17358@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=joelmahoney@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).