MetaCredo.Git (MetaCredo v0.3.0)

View Source

Lightweight git helpers for diff-based analysis.

Resolves the list of changed files between two git refs so that mix metacredo --diff can scope analysis to only modified code.

Summary

Functions

Returns the list of files changed between base and head refs.

Returns the git repository root for the given path, or nil.

Functions

changed_files(repo_root, opts \\ [])

@spec changed_files(
  String.t(),
  keyword()
) :: {:ok, [String.t()]} | {:error, term()}

Returns the list of files changed between base and head refs.

Only files that still exist on disk are returned (added, copied, modified, renamed -- not deleted).

Options

  • :base - Base git ref (default: "origin/main")
  • :head - Head git ref (default: "HEAD")
  • :filter - Git diff filter string (default: "ACMR")
  • :extensions - Optional list of extensions to keep (e.g. [".ex", ".py"])

Examples

iex> MetaCredo.Git.changed_files("/path/to/repo")
{:ok, ["lib/foo.ex", "lib/bar.ex"]}

changed_files!(repo_root, opts \\ [])

@spec changed_files!(
  String.t(),
  keyword()
) :: [String.t()]

Like changed_files/2 but raises on error.

repo_root(path)

@spec repo_root(String.t()) :: String.t() | nil

Returns the git repository root for the given path, or nil.