From: Jeff King Date: Thu, 13 Aug 2009 02:31:37 GMT Subject: Re: fatal: bad revision 'HEAD' 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: > 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 > Signed-off-by: Junio C Hamano 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