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

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

Supports fetching from a remote with options for pruning, tags, depth,
submodules, and more.

# `t`

```elixir
@type t() :: %Git.Commands.Fetch{
  all: boolean(),
  branch: String.t() | nil,
  depth: pos_integer() | nil,
  dry_run: boolean(),
  force: boolean(),
  jobs: pos_integer() | nil,
  no_tags: boolean(),
  prune: boolean(),
  prune_tags: boolean(),
  quiet: boolean(),
  recurse_submodules: boolean() | String.t(),
  remote: String.t() | nil,
  set_upstream: boolean(),
  tags: boolean(),
  unshallow: boolean(),
  verbose: boolean()
}
```

# `args`

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

Returns the argument list for `git fetch`.

Builds the argument list from the struct fields. Boolean flags are appended
when set to `true`. The `recurse_submodules` field may be `true` (for
`--recurse-submodules`) or a string such as `"yes"`, `"no"`, or `"on-demand"`
(for `--recurse-submodules=<value>`). The `remote` and `branch` positional
arguments are appended at the end when present.

## Examples

    iex> Git.Commands.Fetch.args(%Git.Commands.Fetch{})
    ["fetch"]

    iex> Git.Commands.Fetch.args(%Git.Commands.Fetch{remote: "origin"})
    ["fetch", "origin"]

    iex> Git.Commands.Fetch.args(%Git.Commands.Fetch{all: true, prune: true})
    ["fetch", "--all", "--prune"]

    iex> Git.Commands.Fetch.args(%Git.Commands.Fetch{remote: "origin", depth: 1})
    ["fetch", "--depth=1", "origin"]

    iex> Git.Commands.Fetch.args(%Git.Commands.Fetch{recurse_submodules: "on-demand"})
    ["fetch", "--recurse-submodules=on-demand"]

# `parse_output`

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

Parses the output of `git fetch`.

On success (exit code 0), returns `{:ok, :done}`. On failure, returns
`{:error, {stdout, exit_code}}`.

---

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