Ragex.Git.Diff (Ragex v0.17.1)

View Source

Resolves the set of files changed between two git refs.

Used by mix ragex.analyze --diff and mix ragex.ci to scope analysis to only modified code (pull request / incremental CI workflows).

Tries the active git backend (egit NIF when available) first, then falls back to shelling out to git.

Summary

Functions

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

Convenience: resolves the repo root, then returns changed files.

Types

diff_opts()

@type diff_opts() :: [
  base: String.t(),
  head: String.t(),
  filter: String.t(),
  extensions: [String.t()]
]

Functions

changed_files(repo_root, opts \\ [])

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

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

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

Options

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

Examples

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

changed_files!(repo_root, opts \\ [])

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

Like changed_files/2 but raises on error.

changed_files_for_path(path, opts \\ [])

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

Convenience: resolves the repo root, then returns changed files.

Accepts any path inside a repository.