Check.Git (AlCheck v0.1.23)

View Source

Helpers for resolving git diff ranges relative to the base branch.

Summary

Functions

Git revision range (as diff args) for committed changes relative to base_branch.

Name of the currently checked-out branch, or nil if it cannot be resolved.

True when HEAD has a parent commit (i.e. it is not the root commit).

Functions

committed_diff_range(base_branch)

@spec committed_diff_range(String.t()) :: [String.t()]

Git revision range (as diff args) for committed changes relative to base_branch.

Three-dot base...HEAD collapses to nothing when the current branch is the base branch, so running on main would never report any changes. On the base branch we instead compare against the latest commit.

  • feature branch: base...HEAD (commits made since the base branch)
  • base branch: HEAD~1...HEAD (the latest commit), or the empty tree on a root commit

Working-tree/uncommitted changes are never included.

Examples

iex> Check.Git.committed_diff_range("main")
["main...HEAD"]

current_branch()

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

Name of the currently checked-out branch, or nil if it cannot be resolved.

parent_commit?()

@spec parent_commit?() :: boolean()

True when HEAD has a parent commit (i.e. it is not the root commit).