Git.Status (git v0.4.0)

Copy Markdown View Source

Parsed representation of git status --porcelain=v1 -b output.

Contains branch tracking information and a list of file entries with their index and working tree status codes.

Summary

Functions

Parses porcelain v1 output (with -b flag) into a Git.Status struct.

Types

file_entry()

@type file_entry() :: %{index: String.t(), working_tree: String.t(), path: String.t()}

t()

@type t() :: %Git.Status{
  ahead: non_neg_integer(),
  behind: non_neg_integer(),
  branch: String.t() | nil,
  entries: [file_entry()],
  tracking: String.t() | nil
}

Functions

parse(output)

@spec parse(String.t()) :: t()

Parses porcelain v1 output (with -b flag) into a Git.Status struct.

The first line is the branch header: ## branch...tracking [ahead N, behind N]. Subsequent lines are file entries in XY path format, where X is the index status and Y is the working tree status.

Examples

iex> Git.Status.parse("## main\n?? foo.txt\n")
%Git.Status{
  branch: "main",
  tracking: nil,
  ahead: 0,
  behind: 0,
  entries: [%{index: "?", working_tree: "?", path: "foo.txt"}]
}