‹ All Git Interview Questions questions

Git Interview Question 9: Bisect Run Exit Codes

Git Interview Questions · Test 1 · question 9 of 10

Debugging with Githard

A regression appeared somewhere in the last 400 commits. You automate the search with git bisect run ./check.sh. The script builds the project and runs a test. For each commit it must report one of three results: the test passes, the test fails, or the build itself is broken. Some commits in the range don't compile at all because of an unrelated problem. For those commits, the test result tells you nothing either way.

Which exit code should check.sh return when the build fails, so that bisect does not blame or clear the wrong commit?

Select one answer
Show answer and explanation

Answer:

  • B. 125, so that the commit is skipped as untestable

git bisect run reads the script's exit code. 0 means the commit is good. Any code from 1 to 127 except 125 means it is bad. The code 125 is reserved to mean "this commit cannot be tested," and bisect then skips that commit just as git bisect skip would. A commit that doesn't compile gives no information about the regression, so skipping it is correct. Git chose 125 because 126 and 127 are used by POSIX shells for specific errors.

Option A marks every commit that doesn't compile as bad. If that build failure is older than the regression, bisect ends up blaming an unrelated commit.

Option C doesn't skip the commit. Any exit code outside the defined values makes bisect abort the whole run. The docs note that exit(-1) shows up as 255.

Option D marks broken commits as good, which can push the search past the real culprit and name the wrong commit.

Reference: git-bisect

Practice Test 1 ›

Study guides for Git Interview Questions