Git.Info (git v0.4.0)

Copy Markdown View Source

One-call repository introspection helpers that compose lower-level Git functions.

Provides convenient summaries of repository state, HEAD information, and remote details without requiring multiple manual calls.

All functions accept an optional keyword list. Use :config to specify the repository via a Git.Config struct; when omitted a default config is built from the environment.

Summary

Functions

Returns whether the repository has any uncommitted changes.

Returns current HEAD information.

Returns enriched remote information.

Returns the repository root path.

Returns a comprehensive repository overview.

Functions

dirty?(opts \\ [])

@spec dirty?(keyword()) :: {:ok, boolean()} | {:error, term()}

Returns whether the repository has any uncommitted changes.

Checks for staged, modified, or untracked files.

Options

Examples

{:ok, false} = Git.Info.dirty?()

head(opts \\ [])

@spec head(keyword()) :: {:ok, map()} | {:error, term()}

Returns current HEAD information.

Includes the branch name, full SHA, and whether HEAD is detached.

Options

Examples

{:ok, head} = Git.Info.head()
head.branch   #=> "main"
head.detached #=> false

remotes_detailed(opts \\ [])

@spec remotes_detailed(keyword()) ::
  {:ok, [%{name: String.t(), fetch_url: String.t(), push_url: String.t()}]}
  | {:error, term()}

Returns enriched remote information.

Lists all remotes with their fetch and push URLs via git remote -v.

Options

Examples

{:ok, remotes} = Git.Info.remotes_detailed()
hd(remotes).name       #=> "origin"
hd(remotes).fetch_url  #=> "https://github.com/owner/repo.git"

root(opts \\ [])

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

Returns the repository root path.

Wraps git rev-parse --show-toplevel.

Options

Examples

{:ok, "/home/user/project"} = Git.Info.root()

summary(opts \\ [])

@spec summary(keyword()) :: {:ok, map()} | {:error, term()}

Returns a comprehensive repository overview.

Composes status, rev-parse, remote, and log to produce a single map describing the current state of the repository.

Options

Examples

{:ok, info} = Git.Info.summary()
info.branch    #=> "main"
info.dirty     #=> false
info.ahead     #=> 0