Skip to main content

Git bisection with Bayesian statistics

Project description

git bayesect

Bayesian git bisection!

Use this to detect changes in likelihoods of events, for instance, to isolate a commit where a slightly flaky test became very flaky.

You don't need to know the likelihoods (although you can provide priors), just that something has changed at some point in some direction

Installation

pip install git_bayesect

Or:

uv tool install git_bayesect

How it works

git_bayesect uses Bayesian inference to identify the commit introducing a change, with commit selection performed via greedy minimisation of expected entropy, and using a Beta-Bernoulli conjugacy trick while calculating posterior probabilities to make handling unknown failure rates tractable.

See https://hauntsaninja.github.io/git_bayesect.html for a write up.

Usage

Start a Bayesian bisection:

git bayesect start --old $COMMIT

Record an observation on the current commit:

git bayesect fail

Or on a specific commit:

git bayesect pass --commit $COMMIT

Check the overall status of the bisection:

git bayesect status

Reset:

git bayesect reset

More usage

Set the prior for a given commit:

git bayesect prior --commit $COMMIT --weight 10

Set prior for all commits based on filenames:

git bayesect priors_from_filenames --filenames-callback "return 10 if any('suspicious' in f for f in filenames) else 1"

Set prior for all commits based on the text in the commit message + diff:

git bayesect priors_from_text --text-callback "return 10 if 'timeout' in text.lower() else 1"

Get a log of commands to let you reconstruct the state:

git bayesect log

Undo the last observation:

git bayesect undo

Run the bisection automatically using a command to make observations:

git bayesect run $CMD

Checkout the best commmit to test:

git bayesect checkout

Demo

This repository contains a little demo, in case you'd like to play around:

# Create a fake repository with a history to bayesect over
python scripts/generate_fake_repo.py
cd fake_repo

# The fake repo contains a script called flaky.py
# This is a simple script that fails some fraction of the time
# At some point in the history of the repo, that fraction was changed
python flaky.py
git log --oneline

# Start the bayesection
OLD_COMMIT=$(git rev-list HEAD --reverse | head -n 2 | tail -n 1)
git bayesect start --new main --old $OLD_COMMIT

# Run a bayesection to find the commit that introduced the change
git bayesect run python flaky.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git_bayesect-1.2.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_bayesect-1.2-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file git_bayesect-1.2.tar.gz.

File metadata

  • Download URL: git_bayesect-1.2.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for git_bayesect-1.2.tar.gz
Algorithm Hash digest
SHA256 f4de8951f322c9986ebf6a5ae83b8edd252a7d33dbe0307d0b86321de5d37ebb
MD5 e9e4c66a0fd435404478ba4a6ffb000e
BLAKE2b-256 e88b09152d08d47d27c0cb52073471b9cd47eb0f4e4c34dd1dde69955843bf64

See more details on using hashes here.

File details

Details for the file git_bayesect-1.2-py3-none-any.whl.

File metadata

  • Download URL: git_bayesect-1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for git_bayesect-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fbd105e6205787c8a9e7232ea2e949516dd309471d424591d872bc181c5d89d4
MD5 0d39f638576fb76e10cdf9fd4d5ce78f
BLAKE2b-256 6c23f50266cb896b1d1c50c79a0201936179b0243fbebfd30b7ded609f8d7827

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page