threads / bug / 28304

[BUG] git bisect start fails when stale bisect data is left behind

Subject: [BUG] git bisect start fails when stale bisect data is left behind

## tl;dr

6 messages between Sep 5, 2011 and Sep 7, 2011.

replies: 5people: 3as markdown or json

Joel Kaasinen· Sep 5, 2011, 11:15 UTC · lore
Hi,

Just bumped into a weird bug: bisect refused to start. It seems some previous bisect had left around state that referred to a now-nonexistent branch.

How to reproduce: $ echo foo > .git/BISECT_START $ git bisect start HEAD HEAD^

Fails with "fatal: invalid reference:" on git 1.7.6.
–J
PS. Please CC me when answering, I'm not subscribed
Christian Couder· Sep 6, 2011, 07:48 UTC · re: Joel Kaasinen · lore

Re: [BUG] git bisect start fails when stale bisect data is left behind

Hi,
On Mon, Sep 5, 2011 at 1:15 PM, Joel Kaasinen <joel@zenrobotics.com> wrote:
Show 11 quoted lines
> Hi,
>
> Just bumped into a weird bug: bisect refused to start. It seems some
> previous bisect had left around state that referred to a
> now-nonexistent branch.
>
> How to reproduce:
> $ echo foo > .git/BISECT_START
> $ git bisect start HEAD HEAD^
>
> Fails with "fatal: invalid reference:" on git 1.7.6.

Yeah, it looks like a very old behavior. I'd suggest a simple improvement in the error message like this:

diff --git a/git-bisect.sh b/git-bisect.sh
index c21e33c..bd7155b 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -67,7 +67,8 @@ bisect_start() {
        then
                # Reset to the rev from where we started.
                start_head=$(cat "$GIT_DIR/BISECT_START")
-               git checkout "$start_head" -- || exit
+               git checkout "$start_head" -- ||
+               die "Could not checkout previous start point
'$start_head'. Try 'git bisect reset <branch>' first."
        else
                # Get rev from where we start.
                case "$head" in

If there is no objection I will provide a proper patch.

Thanks,
Christian.
Junio C Hamano· Sep 6, 2011, 16:38 UTC · re: Christian Couder · lore

Re: [BUG] git bisect start fails when stale bisect data is left behind

Christian Couder <christian.couder@gmail.com> writes:
Show 21 quoted lines
>> How to reproduce:
>> $ echo foo > .git/BISECT_START
>> $ git bisect start HEAD HEAD^
>>
>> Fails with "fatal: invalid reference:" on git 1.7.6.
>
> Yeah, it looks like a very old behavior.
> I'd suggest a simple improvement in the error message like this:
>
> diff --git a/git-bisect.sh b/git-bisect.sh
> index c21e33c..bd7155b 100755
> --- a/git-bisect.sh
> +++ b/git-bisect.sh
> @@ -67,7 +67,8 @@ bisect_start() {
>         then
>                 # Reset to the rev from where we started.
>                 start_head=$(cat "$GIT_DIR/BISECT_START")
> -               git checkout "$start_head" -- || exit
> +               git checkout "$start_head" -- ||
> +               die "Could not checkout previous start point
> '$start_head'. Try 'git bisect reset <branch>' first."

I do not necessarily think this is a bug to begin with --- the user had a bad state, and bisect stopped without doing further damage.

The real question is what the sensible suggestion/advice the new message should give. It would have to involve bisect reset in the end to get rid of the stale bisect state, but wouldn't the user potentially lose some other state if s/he blindly followed the die message's suggestion and ran "bisect reset"?

Christian Couder· Sep 7, 2011, 04:48 UTC · re: Junio C Hamano · lore

Re: [BUG] git bisect start fails when stale bisect data is left behind

On Tuesday 06 September 2011 18:38:55 Junio C Hamano wrote:
Show 28 quoted lines
> Christian Couder <christian.couder@gmail.com> writes:
> >> How to reproduce:
> >> $ echo foo > .git/BISECT_START
> >> $ git bisect start HEAD HEAD^
> >> 
> >> Fails with "fatal: invalid reference:" on git 1.7.6.
> > 
> > Yeah, it looks like a very old behavior.
> > I'd suggest a simple improvement in the error message like this:
> > 
> > diff --git a/git-bisect.sh b/git-bisect.sh
> > index c21e33c..bd7155b 100755
> > --- a/git-bisect.sh
> > +++ b/git-bisect.sh
> > @@ -67,7 +67,8 @@ bisect_start() {
> > 
> >         then
> >         
> >                 # Reset to the rev from where we started.
> >                 start_head=$(cat "$GIT_DIR/BISECT_START")
> > 
> > -               git checkout "$start_head" -- || exit
> > +               git checkout "$start_head" -- ||
> > +               die "Could not checkout previous start point
> > '$start_head'. Try 'git bisect reset <branch>' first."
> 
> I do not necessarily think this is a bug to begin with --- the user had a
> bad state, and bisect stopped without doing further damage.

Yeah, in fact commit f3a186ffade15f793ea17713a10e10ec4f26ff11 (bisect: improve error message when branch checkout fails, Sat Apr 4, 2009) already improved the error message, but probably didn't go far enough.

Show 5 quoted lines
> The real question is what the sensible suggestion/advice the new message
> should give. It would have to involve bisect reset in the end to get rid
> of the stale bisect state, but wouldn't the user potentially lose some
> other state if s/he blindly followed the die message's suggestion and ran
> "bisect reset"?

When using "git bisect start" with an existing $GIT_DIR/BISECT_START file, the next thing we do after checking out the previous head from the BISECT_START file is a call to "bisect_clean_state". So all the previous bisect state is discarded except the previous head that is in $start_head.

If checking out the previous head fails, that probably means that the previous head is bad because it has been deleted.

In this case running "git bisect reset <branch>" and then "git bisect start ..." is ok because there is no valuable state lost compared to the situation where "git bisect start ..." succeeded in the first place.

Of course if checking out the previous head failed because the $GIT_DIR/BISECT_START file has been corrupted, then it might be better to fix the content of this file. But anyway if we are able to fix the content of the file, for example by putting "foobar" in it instead of the truncated "foo" that made the checkout fail, then running "git bisect reset foobar" and then "git bisect start ..." would probably do the trick too.

It wouldn't do the trick if the $GIT_DIR/BISECT_START file also needed a permission change or more free space on the disc or something like that. But in this case we will get an hopefully meaningful error message when running "git bisect reset foobar" or "git bisect start ..." and we would not lose information.

Thanks, Christian.

Joel Kaasinen· Sep 7, 2011, 06:28 UTC · re: Junio C Hamano · lore

Re: [BUG] git bisect start fails when stale bisect data is left behind

On Tue, Sep 6, 2011 at 19:38, Junio C Hamano <gitster@pobox.com> wrote:
> I do not necessarily think this is a bug to begin with --- the user had a
> bad state, and bisect stopped without doing further damage.
Oh, actually my git-bisect man page says:
"""
   Bisect reset
       After a bisect session, to clean up the bisection state and return to
       the original HEAD, issue the following command:
           $ git bisect reset
       By default, this will return your tree to the commit that was checked
       out before git bisect start. (A new git bisect start will also do that,
       as it cleans up the old bisection state.)
"""

The parenthetical sentence seems to imply that a bisect start cleans out the old state. The problem is that the cleaning fails when the state is bad. (Try e.g. "git bisect start; git bisect start a b" where a and b are valid refs.)

It's pretty much the same to me how this gets resolved. I'm fine with a more verbose error message from bisect start.

–J
Junio C Hamano· Sep 7, 2011, 10:51 UTC · re: Joel Kaasinen · lore

Re: [BUG] git bisect start fails when stale bisect data is left behind

Joel Kaasinen <joel@zenrobotics.com> writes:
Show 25 quoted lines
> On Tue, Sep 6, 2011 at 19:38, Junio C Hamano <gitster@pobox.com> wrote:
>> I do not necessarily think this is a bug to begin with --- the user had a
>> bad state, and bisect stopped without doing further damage.
>
> Oh, actually my git-bisect man page says:
>
> """
>    Bisect reset
>        After a bisect session, to clean up the bisection state and return to
>        the original HEAD, issue the following command:
>
>            $ git bisect reset
>
>        By default, this will return your tree to the commit that was checked
>        out before git bisect start. (A new git bisect start will also do that,
>        as it cleans up the old bisection state.)
> """
>
> The parenthetical sentence seems to imply that a bisect start cleans
> out the old state. The problem is that the cleaning fails when the
> state is bad. (Try e.g. "git bisect start; git bisect start a b" where
> a and b are valid refs.)
>
> It's pretty much the same to me how this gets resolved. I'm fine with
> a more verbose error message from bisect start.

I do not think anybody minds "a more verbose" message. I do mind if the suggestion the message makes were "wrong". That is what I was questioning.

← back to recent threads