Reliable 'git bisect run' recipes in a few lines of Python.
Repo martinus/git_bisectlib, read from GitHub 3 h ago. martinus has not joined Take My Repo.
martinus/git_bisectlib is a public repo on GitHub by martinus. Reliable 'git bisect run' recipes in a few lines of Python. It declares the MIT license on GitHub. It is written mainly in Python, has 4 stars and last changed on 2026-07-08. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-24.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
Reliable git bisect run recipes in a few lines of Python.
git bisect finds the commit that introduced a bug by binary-searching your history, and
git bisect run automates it — if your test script is perfect. But the script is exactly
where bisects quietly go wrong:
bisectlib is the recipe you meant to write. It knows the difference between "this commit is bad" and "I couldn't test this commit," retries flaky tests until the verdict is real, judges benchmarks, patches un-buildable commits on the fly — and streams a live report you can watch.
# recipe.py
from bisectlib import run, test
run("cmake -B build") # broken build? ABORT — don't guess
run("cmake --build build -j")
test("ctest -R foo", attempts=5, min_passes=2) # flaky? 2 of up to 5 passes = good
# fell off the end → GOOD
git bisect start <BAD> <GOOD>
git bisect run python recipe.py
git bisect reset # done — return to your branch
That's the whole thing — three git commands you already half-know, plus a recipe.
Pure standard library, no dependencies — just git on your PATH.
Tip: a recipe is a plain script, so run
python recipe.pyon your current checkout before starting — exit0means "good", non-zero tells you it works — a five-second smoke test that catches a broken recipe before git spends an hour on it.
git bisect run shell script?Because the naive script silently gives wrong answers, and the careful one is a pile of plumbing you rewrite on every hard bisect. bisectlib is that plumbing, done once and done right:
A hand-rolled git bisect run script |
bisectlib |
|---|---|
| A broken build exits non-zero → git reads it as bad → silent mis-bisect | run() aborts on build failure — bisect state is kept, you fix the recipe and resume |
| One flaky failure blames the wrong commit | test(attempts=5, min_passes=2) — a quorum that stops the moment the verdict is decided |
| Benchmarks need custom timing + threshold code | passed=lambda r: r.seconds < 6.7 — any aggregate (min/median/all) via the quorum |
| Un-buildable ranges need manual patching each run | fixup(patch=…) / replace(...) apply a fix, then auto-revert to keep the tree clean |
| Progress is a wall of scrolling output | a live .bisect/status.md — watch the range funnel down to the culprit |
The headline is the first row: a broken build is not a bad commit. Treating the two the
same is the classic way a git bisect run script lands on the wrong answer without a single
error message. bisectlib makes that distinction the default.
1. Infrastructure vs. verdict. run() is for configure/build/setup — if it fails, your
harness is probably broken, so it aborts the whole bisect (git keeps its state) rather
than mis-marking the commit. test() is the actual verdict: pass → good, fail → bad. For a
genuinely un-buildable stretch, opt into skipping with run(..., skip_on_error=True).
2. Flaky tests, both directions. To tolerate a flake, run a quorum — attempts is the
max tries, min_passes how many must pass; it stops as soon as the outcome is locked in.
To hunt a rare flake, do the opposite: hammer the test and fail on the first bad run.
for_seconds gives a wall-clock budget instead of a fixed count, and parallel runs several
copies at once for throughput:
test("./integration", attempts=5, min_passes=2) # tolerate: 2 of up to 5 passes = good
hammer("./flaky") # hunt: all cores for a minute, any fail = bad
3. Benchmarks are just a time-aware predicate. passed receives the Result (which
carries .seconds), and the quorum count expresses any aggregate:
test("./bench", attempts=5, min_passes=1, passed=lambda r: r.seconds < 6.7) # min of 5 < 6.7s
test("./bench", attempts=5, passed=lambda r: r.seconds < 6.7) # all 5 < 6.7s
test("./bench", attempts=5, min_passes=3, passed=lambda r: r.seconds < 6.7) # median < 6.7s
4. Per-range build fixes that clean up after themselves. Old commits often need a small
patch to compile with today's toolchain. Apply one for the commits that need it — it reverts
automatically so git bisect can move to the next commit:
with fixup("fixes/missing-header.patch", when=in_range("abc123..def456")):
run("cmake -B build")
run("cmake --build build -j")
test("ctest -R foo")
replace("CMakeLists.txt", "c++14", "c++17") # sed-like edit, also auto-reverted
You can also decide straight from Python after measuring something — no need to shell back out just to compare a value:
from bisectlib import check, bad
size = int(check("stat -c%s build/app").out)
if size > 5 * 1024 * 1024:
bad("binary too big") # exit 1; reaching the end instead is good
.bisect/status.mdAs the recipe runs, bisectlib writes a live Markdown report to .bisect/status.md at
the root of the repo you're bisecting. Open it in your editor and leave it open — it's a
fixed path that updates in place, so you watch the range narrow and see what's building
right now without babysitting a terminal.
# Bisect report
**original range:** good `2801e9572` · bad `79cb050c2`
## 🎯 First bad commit: `5c9dcafb3` — commit 8: change subsystem 8
```
commit 5c9dcafb3a1e2f00d4c8b9a7e6f5d4c3b2a10987
Author: Eve <eve@example.com>
Date: 2026-06-15 11:40:00 +0200
commit 8: change subsystem 8
src/subsystem8.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
```
| good | bad | probe | range | status |
|------|-----|----------|-------|--------|
| `2801e9572` …, Bob | `79cb050c2` …, Alice | `cb5394973` …, Carol | 27d 15h · 11 commits | 🟢 good |
| `cb5394973` …, Carol | `79cb050c2` …, Alice | `95345541b` …, Dan | 12d 7h · 6 commits | 🔴 bad · 81.2s |
| `cb5394973` …, Carol | `95345541b` …, Dan | `5c9dcafb3` …, Eve | 6d 3h · 3 commits | 🔴 bad |
| `cb5394973` …, Carol | `5c9dcafb3` …, Eve | `19d89b121` …, Fay | 3d 5h · 2 commits | 🟢 good |
Each row reads in causal order — the input range (good/bad) → the probe git
chose → the result — so you see the range funnel down as you scan. The report is
re-rendered the moment each command starts, links every step to its live-streamed log
under .bisect/<sha>/, and — when the search resolves — shows the culprit the way
git bisect does, with the full commit and diffstat. When it's done, you have the answer
without another git show — then git bisect reset puts you back on the branch you
started from.
.bisect/carries its own.gitignoreof*, so it ignores itself entirely — it stays out ofgit status, is never committed, and survives the checkouts git does between commits, without touching your project's tracked.gitignoreor.git/. Point it elsewhere withconfigure(logs="…", status_md="…")— a relocated dir gets the same.gitignore.
pip install git_bisectlib
That gives you import bisectlib for recipes anywhere (the distribution is
git_bisectlib, the import is bisectlib — like pyyaml/yaml). It ships a py.typed
marker, so editors and type-checkers resolve run, test, … with no warnings.
Prefer the bleeding edge? Install straight from main:
pip install --force-reinstall git+https://github.com/martinus/git_bisectlib
Zero-install alternative: running python recipe.py puts the recipe's own directory on
sys.path, so just dropping the bisectlib/ package folder next to recipe.py is enough —
no install, no PYTHONPATH. Keep that copy untracked in the repo you're bisecting so it
survives every checkout (commit it and it would vanish on older commits and break the
import mid-bisect).
Requires Python 3.10+. No third-party dependencies — and that's a guarantee, not
a coincidence. bisectlib imports only the Python standard library, so installing it
never pulls a transitive dependency tree onto the machine you're bisecting on. That keeps
the supply-chain surface as small as it can be — nothing to audit, nothing that can be
compromised upstream. A test (tests/test_no_dependencies.py) enforces it, so a stray
import requests can never sneak in unnoticed.
from bisectlib import (run, test, hammer, check, once,
good, bad, skip, abort, replace, fixup, in_range, touches)
| Verb | Meaning | On failure |
|---|---|---|
run(cmd, skip_on_error=False) |
infrastructure (configure/build/setup) | abort (or skip) |
test(cmd, attempts=1, min_passes=None, passed=None, warmup=0, bad_when="fail") |
the verdict | bad |
hammer(cmd, for_seconds=60, parallel=<all cores>, passed=None, bad_when="fail") |
hunt a rare flake: run till one fails | bad |
check(cmd) -> Result |
run once, never exits — introspect .ok, .out, .seconds |
— |
good() / bad() / skip() / abort() |
decide the commit directly from Python | — |
Every verb takes cwd= (relative paths resolve against the repo root; configure(cwd=…)
sets a default) and timeout= seconds. When a step exceeds timeout, on_timeout decides
the outcome — run defaults to abort, test to skip.
Hunting a hang? If the regression is that a command stops terminating, set
test("./app", timeout=30, on_timeout="bad")— a commit that runs forever is the bug, so time-out means bad. (The defaulton_timeout="skip"would route around every bad commit and stall the bisect.)
hammer(cmd, for_seconds=…, parallel=…) — hunt a rare flake: run the command up to
parallel at a time (default: all cores) for a wall-clock budget (default: 60s),
bad on the first failing run, good if the budget elapses clean. passed=/bad_when=
still define what a failing run is. The report shows total runs, threads used, and runtime.once(key="setup") — run one-time, commit-independent setup (fetch a dependency,
create a symlink) exactly once across the whole bisect instead of on every commit.replace(path, old, new) — sed-like edit, auto-reverted. old is a literal str or a
compiled re.Pattern (the type decides — no regex= flag).fixup(patch=… | cherry_pick=…, when=…) — apply a patch/cherry-pick for a block, then
revert.in_range("v1.0..v2.0"), touches("src/x.c") — predicates for when=, also usable in
a plain if.sha(), subject(), is_clean() — read HEAD's full sha, its commit subject, and
whether the tree is clean; handy inside a when= predicate or before a custom
good()/bad() decision.configure(clean="reset"|"clean", color=…, cwd=…, logs=…, status_md=…) — tune tree
cleanup ("clean" adds git clean -fdx, keeping .bisect/), force color on/off, or
relocate the report and logs.Mistyped a string option (bad_when="Pass", on_timeout="abrot") or an impossible
min_passes? The verb raises immediately — which aborts the bisect with a clear
message rather than silently defaulting and quietly bisecting in the wrong direction. The
fixed-choice options (bad_when, on_timeout, if_missing, clean) are typed with
Literal, so your editor autocompletes the valid values and a type-checker flags a typo
before you even run — no enum import, you still just write on_timeout="bad".
bisectlib maps outcomes to the exit codes git bisect run understands:
| Outcome | Exit | Meaning |
|---|---|---|
| good | 0 |
bug absent |
| bad | 1 |
bug present |
| skip | 125 |
commit untestable — route around it |
| abort | 128 |
harness broken — bisect state preserved, fix the recipe and re-run |
An uncaught exception in a recipe aborts (128) — it is never misread as "bad."
Abort is the "my harness is wrong" signal, and it's built to recover from. git keeps the
whole bisect state with the failing commit checked out, so you fix the recipe and re-run
the same command — do not git bisect start again (that resets):
git bisect run python recipe.py # aborts on a broken recipe → state kept
# … edit recipe.py: add a fixup, set skip_on_error=True, fix a typo …
git bisect run python recipe.py # SAME command → re-tests the current commit and continues
martinus/git_bisectlib is a public repo on GitHub by martinus. Reliable 'git bisect run' recipes in a few lines of Python.
It declares the MIT license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-07-08. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Take My Repo cannot say: it does not audit code and has not run git_bisectlib. What is known comes from GitHub. It declares the MIT license on GitHub. Its last change was on 2026-07-08. It has 4 stars, which measure popularity, not safety. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read the source before you run it. With "Take it", your AI agent shows each step and asks you before running it; README text is treated as data, not as instructions.