#!/usr/bin/env bash# Avoid exiting early; we want to control exit codes explicitly.set+e
# Optional: clean/build if your project needs it# build_cmd here is an example; replace with your actual build steps.if!./build.sh>/dev/null2>&1;thenecho"[skip] build failed; not judging this commit"exit125fi# Run your test command; examples:# pytest -q# mvn -q -DskipTests=false test# npm test --silent# go test ./..../run-unit-tests.sh
test_status=$?# If your test runner already returns non-zero on failures, you can use it directly.if[$test_status-eq0];thenecho"[good] tests passed"exit0elseecho"[bad] tests failed (exit $test_status)"# Map any non-zero to 1 so Git treats it as "bad"exit1fi
gitbisectstart
gitbisectbad# current commit failsgitbisectgoodv1.4.2# or some SHA/tag you know was passinggitbisectrun./bisect-test.sh# will auto-checkout and test several commits# When it finishes, Git prints the first bad commit.gitbisectreset# return to your original branch