Skip to content

Skip diff coverage in a build outside a git work tree - #37

Open
vlsi wants to merge 2 commits into
cribro-dev:mainfrom
vlsi:claude/fix-issue-36-5d0313
Open

vlsi wants to merge 2 commits into
cribro-dev:mainfrom
vlsi:claude/fix-issue-36-5d0313

Conversation

@vlsi

@vlsi vlsi commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

A build of a source release, such as a git archive export, has no changed lines to measure. Cribro used to attach JaCoCo anyway and report that it could not resolve a base. If Git was unavailable, Gradle failed with cannot run git in <dir> after the tests passed.

Cribro checks for a usable Git work tree before configuring automatic diff coverage. It probes Git only when repository hints exist. Gradle tracks the selection as a configuration-cache input so that a change in repository layout can change test instrumentation before Gradle computes the task graph.

User-visible changes

  • Outside a Git work tree, Cribro skips diff coverage and leaves the project's JaCoCo configuration in place.
  • With automatic diff coverage enabled, Cribro prints Diff coverage: skipped, since <dir> is not in a git work tree. once per build. Gradle prints it at QUIET level. Maven prints it after a recorded Surefire execution and before the build summary.
  • Outside a Git work tree, changedLines writes only the header not in a git work tree. pitestDiff skips without resolving PIT dependencies, including under the configuration cache.
  • A source archive without repository metadata builds without Git installed. If Git cannot start and plausible repository metadata remains, Cribro retains the Git launch error.

Verification

  • ./gradlew --quiet build dist -PtestJavaVersion=21 completed with 889 tests passed and two Windows-only tests skipped. The Gradle 8.14.3 sample also passed on JDK 11.
  • A fresh Gradle JVM with an empty native PATH ran the archive's tests, printed one notice, and removed a stale report. Archive pitestDiff also passed with the configuration cache and an empty PIT dependency cache.
  • Gradle's project-owned JaCoCo fixture wrote measured XML and enforced its configured coverage threshold. The Gradle and Maven fixtures verified changed lines with linked or separate Git metadata.

Open review findings

  • A nested build can drop changed lines when separate Git metadata uses core.worktree to select the enclosing checkout. Git returns checkout-relative paths, while Cribro filters against the nested command directory.
  • An empty nested .git directory can hide a Git error for the enclosing checkout when Git cannot complete discovery.
  • The command directory for relative GIT_WORK_TREE overrides in nested builds remains under review.

Fixes #36

vlsi and others added 2 commits December 1, 2026 19:45
A build of a source release, such as a git archive export, has no
.git, so no line can count as changed. cribro still ran test under the
JaCoCo agent, which costs about 20% of its wall time, and then printed

    Diff coverage: no base ref resolved, so no line counts as changed. Pass -Pcribro.diffBase=<ref>, or set an upstream branch, or fetch origin/HEAD, origin/main, or origin/master.

once per module, advising a fetch into a repository that does not
exist. Where git is not installed, diffCoverage failed the build after
the tests passed, with "cannot run git in <dir>".

Whether the build lies in a work tree is now decided at configuration
time from the file system and the environment, with no git process:
a .git directory or file at or above the root directory, as in a clone,
a linked worktree, or a submodule, or GIT_DIR in the environment.
Outside a work tree the Gradle plugin turns the agent off on test and
disables jacocoTestReport, as -Pcribro.diffCoverageEnabled=false does,
and finalizes test with diffCoverage alone; the Maven extension attaches
no agent. Deciding at execution time was rejected: whether the agent is
enabled is an input of test, so turning it off in doFirst would cache an
uninstrumented result under the key of an instrumented run.

With GIT_DIR and no .git, git keeps running in the build's root
directory, so a relative GIT_DIR or GIT_WORK_TREE resolves as before.

User-visible:
Outside a git work tree, test runs without the JaCoCo agent, and the build prints one line, "Diff coverage: skipped, since <dir> is not in a git work tree.", at the QUIET level in Gradle and at the end of the session in Maven; no git command runs.
Outside a git work tree, changedLines writes a file with the header "not in a git work tree" and no line, so pitestDiff is skipped.
In Maven, GIT_DIR in the environment with no .git now counts as a work tree, where cribro used to report that the build was not in one.

Fixes cribro-dev#36

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Skipping Cribro instrumentation also disabled a Gradle project's own
JaCoCo setup. A direct pitestDiff invocation could still resolve PIT
dependencies while Gradle saved the configuration cache.

Leave project-owned coverage in place and keep PIT inputs out of the
archive task graph. Share configuration-time Git discovery between
Gradle and Maven, and cover the skip notice and stale-report cleanup
with a fresh Gradle process that cannot launch Git.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A build outside a git repository runs test with the JaCoCo agent, and fails where git is not installed

1 participant