Muex.GitDiff (Muex v0.8.1)

View Source

Maps a git diff to the set of source lines a change touched, so mutation testing can be scoped to exactly what a branch/PR modified.

changed_lines/1 is a pure parser over git diff --unified=0 output; changed_since/2 shells out to git and feeds it that parser.

Summary

Functions

Parses git diff --unified=0 output into %{path => MapSet of line numbers}.

Returns the lines changed on the current branch relative to ref.

Keeps only the mutations whose location falls on a changed line.

Functions

changed_lines(diff)

@spec changed_lines(String.t()) :: %{required(String.t()) => MapSet.t(pos_integer())}

Parses git diff --unified=0 output into %{path => MapSet of line numbers}.

Only added/modified lines on the new-file side are recorded. Deleted files and pure-deletion hunks contribute nothing.

changed_since(ref, opts \\ [])

@spec changed_since(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, String.t()}

Returns the lines changed on the current branch relative to ref.

Uses git diff --unified=0 <ref>...HEAD, i.e. changes since the branch diverged from ref (PR semantics). Returns {:ok, map} or {:error, reason}.

filter_mutations(mutations, changed)

@spec filter_mutations([map()], map() | nil) :: [map()]

Keeps only the mutations whose location falls on a changed line.

changed is a map as returned by changed_lines/1/changed_since/2, or nil to disable filtering (returns every mutation unchanged).