@@ -279,53 +279,68 @@ $ git bisect start HEAD origin -- # HEAD is bad, origin is good
279279$ git bisect run make test # "make test" builds and tests
280280------------
281281
282- * Automatically bisect a broken test suite :
282+ * Automatically bisect a broken test case :
283283+
284284------------
285285$ cat ~/test.sh
286286#!/bin/sh
287- make || exit 125 # this skips broken builds
288- make test # "make test" runs the test suite
289- $ git bisect start v1.3 v1.1 -- # v1.3 is bad, v1.1 is good
287+ make || exit 125 # this skips broken builds
288+ ~/check_test_case.sh # does the test case pass?
289+ $ git bisect start HEAD HEAD~10 -- # culprit is among the last 10
290290$ git bisect run ~/test.sh
291291------------
292292+
293293Here we use a "test.sh" custom script. In this script, if "make"
294294fails, we skip the current commit.
295+ "check_test_case.sh" should "exit 0" if the test case passes,
296+ and "exit 1" otherwise.
295297+
296- It is safer to use a custom script outside the repository to prevent
297- interactions between the bisect, make and test processes and the
298- script.
299- +
300- "make test" should "exit 0", if the test suite passes, and
301- "exit 1" otherwise.
298+ It is safer if both "test.sh" and "check_test_case.sh" are
299+ outside the repository to prevent interactions between the bisect,
300+ make and test processes and the scripts.
302301
303- * Automatically bisect a broken test case :
302+ * Automatically bisect with temporary modifications (hot-fix) :
304303+
305304------------
306305$ cat ~/test.sh
307306#!/bin/sh
308- make || exit 125 # this skips broken builds
309- ~/check_test_case.sh # does the test case passes ?
310- $ git bisect start HEAD HEAD~10 -- # culprit is among the last 10
311- $ git bisect run ~/test.sh
307+
308+ # tweak the working tree by merging the hot-fix branch
309+ # and then attempt a build
310+ if git merge --no-commit hot-fix &&
311+ make
312+ then
313+ # run project specific test and report its status
314+ ~/check_test_case.sh
315+ status=$?
316+ else
317+ # tell the caller this is untestable
318+ status=125
319+ fi
320+
321+ # undo the tweak to allow clean flipping to the next commit
322+ git reset --hard
323+
324+ # return control
325+ exit $status
312326------------
313327+
314- Here "check_test_case.sh" should "exit 0" if the test case passes ,
315- and "exit 1" otherwise.
316- +
317- It is safer if both "test.sh" and "check_test_case.sh" scripts are
318- outside the repository to prevent interactions between the bisect,
319- make and test processes and the scripts.
328+ This applies modifications from a hot-fix branch before each test run ,
329+ e.g. in case your build or test environment changed so that older
330+ revisions may need a fix which newer ones have already. (Make sure the
331+ hot-fix branch is based off a commit which is contained in all revisions
332+ which you are bisecting, so that the merge does not pull in too much, or
333+ use `git cherry-pick` instead of `git merge`.)
320334
321- * Automatically bisect a broken test suite :
335+ * Automatically bisect a broken test case :
322336+
323337------------
324338$ git bisect start HEAD HEAD~10 -- # culprit is among the last 10
325339$ git bisect run sh -c "make || exit 125; ~/check_test_case.sh"
326340------------
327341+
328- Does the same as the previous example, but on a single line.
342+ This shows that you can do without a run script if you write the test
343+ on a single line.
329344
330345SEE ALSO
331346--------
0 commit comments