# `Git.Commands.Blame`
[🔗](https://github.com/joshrotenberg/git_wrapper_ex/blob/main/lib/git/commands/blame.ex#L1)

Implements the `Git.Command` behaviour for `git blame`.

Always uses `--porcelain` output format internally for reliable,
machine-readable parsing. The output is parsed into a list of
`Git.BlameEntry` structs.

Supports line ranges, specific revisions, email display, date formatting,
reverse blame, first-parent following, encoding, and root commit handling.

# `t`

```elixir
@type t() :: %Git.Commands.Blame{
  date: String.t() | nil,
  encoding: String.t() | nil,
  file: String.t(),
  first_parent: boolean(),
  lines: String.t() | nil,
  rev: String.t() | nil,
  reverse: boolean(),
  root: boolean(),
  show_email: boolean(),
  show_name: boolean()
}
```

# `args`

```elixir
@spec args(t()) :: [String.t()]
```

Returns the argument list for `git blame`.

Always includes `--porcelain` for reliable parsing regardless of the
`:porcelain` struct field. The `:file` field is required and appended
at the end of the argument list.

## Examples

    iex> Git.Commands.Blame.args(%Git.Commands.Blame{file: "lib/app.ex"})
    ["blame", "--porcelain", "lib/app.ex"]

    iex> Git.Commands.Blame.args(%Git.Commands.Blame{file: "lib/app.ex", lines: "1,5"})
    ["blame", "--porcelain", "-L", "1,5", "lib/app.ex"]

    iex> Git.Commands.Blame.args(%Git.Commands.Blame{file: "lib/app.ex", rev: "HEAD~1"})
    ["blame", "--porcelain", "HEAD~1", "--", "lib/app.ex"]

    iex> Git.Commands.Blame.args(%Git.Commands.Blame{file: "lib/app.ex", show_email: true})
    ["blame", "--porcelain", "-e", "lib/app.ex"]

# `parse_output`

```elixir
@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, [Git.BlameEntry.t()]} | {:error, {String.t(), non_neg_integer()}}
```

Parses the output of `git blame --porcelain`.

On success (exit code 0), parses the porcelain output into a list of
`Git.BlameEntry` structs. Each entry contains the commit SHA,
author information, line numbers, and the actual line content.

Returns `{:ok, [BlameEntry.t()]}` on success or
`{:error, {stdout, exit_code}}` on failure.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
