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

Implements the `Git.Command` behaviour for `git rev-parse`.

Supports resolving refs, querying repository properties such as the
top-level directory, git directory, and various boolean checks like
whether the current directory is inside a work tree.

# `t`

```elixir
@type t() :: %Git.Commands.RevParse{
  abbrev_ref: boolean(),
  absolute_git_dir: boolean(),
  git_common_dir: boolean(),
  git_dir: boolean(),
  is_bare_repository: boolean(),
  is_inside_git_dir: boolean(),
  is_inside_work_tree: boolean(),
  ref: String.t() | nil,
  short: boolean() | non_neg_integer() | nil,
  show_cdup: boolean(),
  show_prefix: boolean(),
  show_toplevel: boolean(),
  symbolic_full_name: boolean(),
  verify: boolean()
}
```

# `args`

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

Returns the argument list for `git rev-parse`.

Builds the argument list from the struct fields, appending flags for
each enabled boolean option and the ref (if provided) at the end.

## Examples

    iex> Git.Commands.RevParse.args(%Git.Commands.RevParse{ref: "HEAD"})
    ["rev-parse", "HEAD"]

    iex> Git.Commands.RevParse.args(%Git.Commands.RevParse{show_toplevel: true})
    ["rev-parse", "--show-toplevel"]

    iex> Git.Commands.RevParse.args(%Git.Commands.RevParse{verify: true, ref: "HEAD"})
    ["rev-parse", "--verify", "HEAD"]

    iex> Git.Commands.RevParse.args(%Git.Commands.RevParse{short: true, ref: "HEAD"})
    ["rev-parse", "--short", "HEAD"]

    iex> Git.Commands.RevParse.args(%Git.Commands.RevParse{short: 8, ref: "HEAD"})
    ["rev-parse", "--short=8", "HEAD"]

    iex> Git.Commands.RevParse.args(%Git.Commands.RevParse{abbrev_ref: true, ref: "HEAD"})
    ["rev-parse", "--abbrev-ref", "HEAD"]

# `parse_output`

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

Parses the output of `git rev-parse`.

On success (exit code 0), returns `{:ok, trimmed_output}` where the output
is the trimmed stdout string. On failure, returns
`{:error, {stdout, exit_code}}`.

---

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