patchcov
Patch coverage for git diffs. patchcov attributes a per-line coverage report to a
git diff and tells you what share of the lines a change added are covered, which
new lines are not, and whether anything moved on code the change did not touch.
- Reads lcov, llvm-cov JSON, Cobertura, JaCoCo XML and Go coverprofiles, detected from the content.
- Reports patch coverage, the uncovered new lines, per-file project deltas and indirect changes, as a markdown PR comment, YAML or JSON.
- Gates a branch with
--fail-under-patchand--fail-under-lines. - Merges the reports of a sharded CI run into one file, or takes them directly.
- Silences known-flaky regions with source markers, and files with a repo-level ignore list, without hiding real coverage.
Install
Prebuilt binaries for Linux (glibc 2.35 or newer) and macOS are attached to each GitHub release.
Use
# Produce a per-line report (any tool that writes one of the supported formats).
# Patch coverage against the merge base with origin/main.
# Fail the job if patch coverage is under 80% or overall coverage under 70%.
# Merge the shards of a sharded run, then gate as usual.
# Check source markers without a coverage report.
The full guide is in docs/usage.md: input formats and path mapping for non-Rust languages, gating semantics, sharded runs, the ignore list, source markers and the flag reference.
Configuration
Settings that belong to a repository live in .patchcov/config.yaml, found by
walking up from the repository root. --config-dir and the PATCHCOV_CONFIG_DIR
environment variable override the location. There are no user-level or
machine-level settings, so what a gate reports is visible in version control.
Library
The analysis is a library as well as a command: patchcov::parse reads a report,
patchcov::DiffModel builds the added-line sets from git2, patchcov::analyze
attributes coverage to the diff and patchcov::render formats the result.
Releasing
See docs/RELEASE.md.
License
BSD-3-Clause. See LICENSE.