threads / discuss / 58507

Scriptable mode for git bisect

Subject: Scriptable mode for git bisect

## tl;dr

8 messages between Sep 23, 2022 and Sep 26, 2022.

replies: 7people: 3as markdown or json

Claus Fischer· Sep 23, 2022, 20:54 UTC · lore
Dear Git maintainers,

I have looked at the manpage of git bisect but have not found what I need: I would like git bisect not just to report the 'bad' revision within a bunch of text but instead either stop at the first bad revision (the last good will then be HEAD~1) or report it in a scriptable way, i.e.

  BADHEAD=$(git bisect run --shut-up-and-report-the-bad)
Have I overlooked anything?
***

The pourpose is to keep the source trees of two different projects that share a few files synchronous. My good/bad-script is a script that checks whether these files are similar. I want git to stop at the first change in source tree A so that I can update source tree B with the same commit message, then proceed to the next change in A that changes one of those files.

Regards,
Cluas
Đoàn Trần Công Danh· Sep 24, 2022, 01:44 UTC · re: Claus Fischer · lore

Re: Scriptable mode for git bisect

On 2022-09-23 22:54:03+0200, Claus Fischer <claus.fischer@clausfischer.com> wrote:
Show 13 quoted lines
> 
> Dear Git maintainers,
> 
> I have looked at the manpage of git bisect but have not found
> what I need:
> I would like git bisect not just to report the 'bad' revision
> within a bunch of text but instead either stop at the first
> bad revision (the last good will then be HEAD~1) or report
> it in a scriptable way, i.e.
> 
>   BADHEAD=$(git bisect run --shut-up-and-report-the-bad)
> 
> Have I overlooked anything?

After running "git bisect run" You can take its revisions with:

	BADHEAD=$(git rev-parse --verify refs/bisect/bad)
Show 15 quoted lines
> 
> ***
> 
> The pourpose is to keep the source trees of two different
> projects that share a few files synchronous.
> My good/bad-script is a script that checks whether these
> files are similar.
> I want git to stop at the first change in source tree A
> so that I can update source tree B with the same commit
> message, then proceed to the next change in A that
> changes one of those files.
> 
> Regards,
> 
> Cluas
-- 
Danh
Claus Fischer· Sep 24, 2022, 09:32 UTC · re: Đoàn Trần Công Danh · lore

Re: Scriptable mode for git bisect

I tried that but it turns out it does not always stop at the bad revision.
Claus
Show 40 quoted lines
> On 24.09.2022, at 03:44, Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote:
> 
> On 2022-09-23 22:54:03+0200, Claus Fischer <claus.fischer@clausfischer.com> wrote:
>> 
>> Dear Git maintainers,
>> 
>> I have looked at the manpage of git bisect but have not found
>> what I need:
>> I would like git bisect not just to report the 'bad' revision
>> within a bunch of text but instead either stop at the first
>> bad revision (the last good will then be HEAD~1) or report
>> it in a scriptable way, i.e.
>> 
>>  BADHEAD=$(git bisect run --shut-up-and-report-the-bad)
>> 
>> Have I overlooked anything?
> 
> After running "git bisect run"
> You can take its revisions with:
> 
> 	BADHEAD=$(git rev-parse --verify refs/bisect/bad)
> 
>> 
>> ***
>> 
>> The pourpose is to keep the source trees of two different
>> projects that share a few files synchronous.
>> My good/bad-script is a script that checks whether these
>> files are similar.
>> I want git to stop at the first change in source tree A
>> so that I can update source tree B with the same commit
>> message, then proceed to the next change in A that
>> changes one of those files.
>> 
>> Regards,
>> 
>> Cluas
> 
> -- 
> Danh
Đoàn Trần Công Danh· Sep 24, 2022, 09:46 UTC · re: Claus Fischer · lore

Re: Scriptable mode for git bisect

On 2022-09-24 11:32:52+0200, Claus Fischer <claus.fischer@clausfischer.com> wrote:
> I tried that but it turns out it does not always stop at the bad revision.

"git bisect" won't stop at the bad revision, it only left "refs/bisect/bad" point to the first bad revision, assuming non-alternative terms were used.

If refs/bisect/bad doesn't point to the first bad revision, your installation is borked. Please file a bug report.

Show 44 quoted lines
> 
> Claus
> 
> > On 24.09.2022, at 03:44, Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote:
> > 
> > On 2022-09-23 22:54:03+0200, Claus Fischer <claus.fischer@clausfischer.com> wrote:
> >> 
> >> Dear Git maintainers,
> >> 
> >> I have looked at the manpage of git bisect but have not found
> >> what I need:
> >> I would like git bisect not just to report the 'bad' revision
> >> within a bunch of text but instead either stop at the first
> >> bad revision (the last good will then be HEAD~1) or report
> >> it in a scriptable way, i.e.
> >> 
> >>  BADHEAD=$(git bisect run --shut-up-and-report-the-bad)
> >> 
> >> Have I overlooked anything?
> > 
> > After running "git bisect run"
> > You can take its revisions with:
> > 
> > 	BADHEAD=$(git rev-parse --verify refs/bisect/bad)
> > 
> >> 
> >> ***
> >> 
> >> The pourpose is to keep the source trees of two different
> >> projects that share a few files synchronous.
> >> My good/bad-script is a script that checks whether these
> >> files are similar.
> >> I want git to stop at the first change in source tree A
> >> so that I can update source tree B with the same commit
> >> message, then proceed to the next change in A that
> >> changes one of those files.
> >> 
> >> Regards,
> >> 
> >> Cluas
> > 
> > -- 
> > Danh
> 
-- 
Danh
Junio C Hamano· Sep 24, 2022, 16:24 UTC · re: Đoàn Trần Công Danh · lore

Re: Scriptable mode for git bisect

Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:
Show 19 quoted lines
> On 2022-09-23 22:54:03+0200, Claus Fischer <claus.fischer@clausfischer.com> wrote:
>> 
>> Dear Git maintainers,
>> 
>> I have looked at the manpage of git bisect but have not found
>> what I need:
>> I would like git bisect not just to report the 'bad' revision
>> within a bunch of text but instead either stop at the first
>> bad revision (the last good will then be HEAD~1) or report
>> it in a scriptable way, i.e.
>> 
>>   BADHEAD=$(git bisect run --shut-up-and-report-the-bad)
>> 
>> Have I overlooked anything?
>
> After running "git bisect run"
> You can take its revisions with:
>
> 	BADHEAD=$(git rev-parse --verify refs/bisect/bad)

Christian, who invested quite a lot of work in the command (cc'ed), may have more tricks up his sleeve.

You can also check .git/BISECT_LOG; the value of refs/bisect/bad is the source of truth, as the final verdict message given by the command (cf. builtin/bisect--helper.c::bisect_successful() that reads from "refs/bisect/$bad" which is called when "the first bad commit" is found by bisect.c::bisect_next_all()).

One thing that may confuse a new user is that the commit HEAD, when "git bisect" finds the first bad commit, may not be a bad one. You start from a longer streatch of history (time flows from left to right, B and G are known bad and good ones, ? are not known)

               ?---?---?
              /         \
    -----G---?---?---?---?---?---B

and then go narrowing down by answering "is this one good?" questions. Answering "Good" paints all its unknown ancestors as "Good". The final step may look like this, where the sole '?' is the commit that is checked out to be tested:

               G---G---G
              /         \
    -----G---G---G---?---B---B---B

And the answer to the final step may be "good" or "bad". If it is "good", then the first bad commit would be its child commit, which is a merge commit that introduced the badness into the history.

But still, the first bad commit is found at refs/bisect/bad
Đoàn Trần Công Danh· Sep 25, 2022, 00:59 UTC · lore

Re: Scriptable mode for git bisect

On 2022-09-25 01:46:13+0200, Claus Fischer <claus.fischer@clausfischer.com> wrote:
Show 13 quoted lines
> Well since I usually don’t have many revisions backwards, typically
> no more than 50, I can just traverse the tree backwards from main.
> I remember the last ‘bad’ revision before the good one.
> So there’s a solution for me.
> 
> Yes the bisect command puts the correct ‘first bad’ revision in its
> output but it’s surrounded by a large amount of useless text. It
> would be nice to have a ‘quiet’ flag that lets it output just the
> bad revision. Alternatively, that it ends by checking out just that
> bad revision before revert.
> 
> My problem is solved by stepping backwards to HEAD~1 each time, but
> you might consider making bisect more scriptable.

No, you don't need to parse "git bisect" output to get the "first bad" revision. The "first bad" revision is stored in refs/bisect/bad.

And you can take the "first bad" revision in a scriptable way with:
	FIRST_BAD=$(git rev-parse --verify refs/bisect/bad)
Of course, after finishing bisecting.
-- 
Danh
Claus Fischer· Sep 25, 2022, 12:42 UTC · re: Đoàn Trần Công Danh · lore

Re: Scriptable mode for git bisect

Oh thank you, I didn’t know that / didn’t grasp that while reading (apparently too fast) your previous mails.
That is way nicer.
Thank you.
Claus
Show 28 quoted lines
> On 25.09.2022, at 02:59, Đoàn Trần Công Danh <congdanhqx@gmail.com> wrote:
> 
> On 2022-09-25 01:46:13+0200, Claus Fischer <claus.fischer@clausfischer.com> wrote:
>> Well since I usually don’t have many revisions backwards, typically
>> no more than 50, I can just traverse the tree backwards from main.
>> I remember the last ‘bad’ revision before the good one.
>> So there’s a solution for me.
>> 
>> Yes the bisect command puts the correct ‘first bad’ revision in its
>> output but it’s surrounded by a large amount of useless text. It
>> would be nice to have a ‘quiet’ flag that lets it output just the
>> bad revision. Alternatively, that it ends by checking out just that
>> bad revision before revert.
>> 
>> My problem is solved by stepping backwards to HEAD~1 each time, but
>> you might consider making bisect more scriptable.
> 
> No, you don't need to parse "git bisect" output to get the "first bad"
> revision. The "first bad" revision is stored in refs/bisect/bad.
> 
> And you can take the "first bad" revision in a scriptable way with:
> 
> 	FIRST_BAD=$(git rev-parse --verify refs/bisect/bad)
> 
> Of course, after finishing bisecting.
> 
> -- 
> Danh
Junio C Hamano· Sep 26, 2022, 17:00 UTC · re: Claus Fischer · lore

Re: Scriptable mode for git bisect

Claus Fischer <claus.fischer@clausfischer.com> writes:
Show 7 quoted lines
> Oh thank you, I didn’t know that / didn’t grasp that while reading (apparently too fast) your previous mails.
>
> That is way nicer.
>
> Thank you.
>
> Claus
Now I am puzzled by your earlier response in the thread, e.g.
  https://lore.kernel.org/git/E10623C2-FF73-4E5B-AD28-C255B02F3B0F@clausfischer.com/
In any case, it is good to see that your issue has been solved.

← back to recent threads