Home Explore Blog CI



git

5th chunk of `Documentation/git-bisect.adoc`
91accee0b6c422322619c84008e67b3952a657cc22b4b2090000000100000b88
 skipped (see `git bisect skip` above). 125 was chosen
as the highest sensible value to use for this purpose, because 126 and 127
are used by POSIX shells to signal specific error status (127 is for
command not found, 126 is for command found but not executable--these
details do not matter, as they are normal errors in the script, as far as
`bisect run` is concerned).

You may often find that during a bisect session you want to have
temporary modifications (e.g. s/#define DEBUG 0/#define DEBUG 1/ in a
header file, or "revision that does not have this commit needs this
patch applied to work around another problem this bisection is not
interested in") applied to the revision being tested.

To cope with such a situation, after the inner 'git bisect' finds the
next revision to test, the script can apply the patch
before compiling, run the real test, and afterwards decide if the
revision (possibly with the needed patch) passed the test and then
rewind the tree to the pristine state.  Finally the script should exit
with the status of the real test to let the `git bisect run` command loop
determine the eventual outcome of the bisect session.

OPTIONS
-------
--no-checkout::
+
Do not checkout the new working tree at each iteration of the bisection
process. Instead just update the reference named `BISECT_HEAD` to make
it point to the commit that should be tested.
+
This option may be useful when the test you would perform in each step
does not require a checked out tree.
+
If the repository is bare, `--no-checkout` is assumed.

--first-parent::
+
Follow only the first parent commit upon seeing a merge commit.
+
In detecting regressions introduced through the merging of a branch, the merge
commit will be identified as introduction of the bug and its ancestors will be
ignored.
+
This option is particularly useful in avoiding false positives when a merged
branch contained broken or non-buildable commits, but the merge itself was OK.

EXAMPLES
--------

* Automatically bisect a broken build between v1.2 and HEAD:
+
------------
$ git bisect start HEAD v1.2 --      # HEAD is bad, v1.2 is good
$ git bisect run make                # "make" builds the app
$ git bisect reset                   # quit the bisect session
------------

* Automatically bisect a test failure between origin and HEAD:
+
------------
$ git bisect start HEAD origin --    # HEAD is bad, origin is good
$ git bisect run make test           # "make test" builds and tests
$ git bisect reset                   # quit the bisect session
------------

* Automatically bisect a broken test case:
+
------------
$ cat ~/test.sh
#!/bin/sh
make || exit 125                     # this skips broken builds
~/check_test_case.sh                 # does the test case pass?
$ git bisect start HEAD HEAD~10 --   # culprit is among the last 10
$ git bisect run ~/test.sh
$ git bisect reset                   # quit the bisect session
------------
+
Here we use a `test.sh`

Title: Using Git Bisect with Scripts and Options
Summary
Git bisect can be used with scripts to automate testing and debugging processes, and various options are available to customize its behavior, such as --no-checkout and --first-parent, to handle different scenarios and improve the efficiency of the bisect process. Examples are provided to demonstrate how to use git bisect to automatically identify broken builds or test failures in a repository.