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

Implements the `Git.Command` behaviour for `git hash-object`.

Computes the object ID for a file and optionally writes it into the
object database. Only file-based hashing is supported (no stdin).

# `t`

```elixir
@type t() :: %Git.Commands.HashObject{
  file: String.t() | nil,
  literally: boolean(),
  type: String.t() | nil,
  write: boolean()
}
```

# `args`

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

Returns the argument list for `git hash-object`.

## Examples

    iex> Git.Commands.HashObject.args(%Git.Commands.HashObject{file: "README.md"})
    ["hash-object", "README.md"]

    iex> Git.Commands.HashObject.args(%Git.Commands.HashObject{file: "README.md", write: true})
    ["hash-object", "-w", "README.md"]

    iex> Git.Commands.HashObject.args(%Git.Commands.HashObject{file: "README.md", type: "commit"})
    ["hash-object", "-t", "commit", "README.md"]

    iex> Git.Commands.HashObject.args(%Git.Commands.HashObject{file: "README.md", literally: true})
    ["hash-object", "--literally", "README.md"]

# `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 hash-object`.

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

---

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