Amandasaurus
Amandasaurus

Reputation: 60689

Check if `git bisect` is active in a script, in a robust stable way?

If I start doing a git bisect, then the output of git status will show me that I am currently bisecting. I would like to perform this “are you bisecting?” test in a script, I could look at the output of git status, but I suspect there is a better way. git status --porcelain doesn't include this bisecting status.

How can I robustly check in a script that a git bisect is currently active?

git version 2.25

Upvotes: 5

Views: 119

Answers (1)

torek
torek

Reputation: 487983

  1. Run git bisect log. This will produce output and/or errors, so redirect that away.
  2. Test the status of the command when it finishes. If you are in the middle of a bisect, the status will be zero, otherwise it will be nonzero.

Hence:

if git bisect log >/dev/null 2>&1; then
    echo bisection is in progress
else
    echo no bisection is in progress
fi

or:

if ! git bisect log >/dev/null 2>&1; then echo no bisection in progress; fi

(this is not documented but appears to be pretty reliable).

Upvotes: 2

Related Questions