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

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

Creates an archive of files from a named tree. Supports tar, tar.gz,
and zip formats.

**Limitation:** The `output` option is currently required. When git archive
runs without `--output`, it writes binary data to stdout which cannot be
reliably captured as a string by `System.cmd/3`. When `output` is specified,
git writes directly to the file and stdout is empty.

# `t`

```elixir
@type t() :: %Git.Commands.Archive{
  format: String.t() | nil,
  output: String.t() | nil,
  paths: [String.t()],
  prefix: String.t() | nil,
  ref: String.t(),
  remote: String.t() | nil,
  verbose: boolean(),
  worktree_attributes: boolean()
}
```

# `args`

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

Returns the argument list for `git archive`.

The tree-ish ref is placed after all flags. Paths are appended after `--`.

## Examples

    iex> Git.Commands.Archive.args(%Git.Commands.Archive{})
    ["archive", "HEAD"]

    iex> Git.Commands.Archive.args(%Git.Commands.Archive{format: "zip", output: "out.zip"})
    ["archive", "--format=zip", "--output=out.zip", "HEAD"]

    iex> Git.Commands.Archive.args(%Git.Commands.Archive{prefix: "project/", paths: ["lib/"]})
    ["archive", "--prefix=project/", "HEAD", "--", "lib/"]

    iex> Git.Commands.Archive.args(%Git.Commands.Archive{verbose: true, worktree_attributes: true})
    ["archive", "-v", "--worktree-attributes", "HEAD"]

# `parse_output`

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

Parses the output of `git archive`.

On success (exit code 0), returns `{:ok, :done}` since the archive
content is written to the output file.
On failure, returns `{:error, {stdout, exit_code}}`.

---

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