Git.Commands.Fetch (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git fetch.

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

Summary

Functions

Returns the argument list for git fetch.

Parses the output of git fetch.

Types

t()

@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()
}

Functions

args(command)

@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(stdout, exit_code)

@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}}.