Git.Commands.Pull (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git pull.

Supports pulling from a remote with options for rebase, fast-forward, autostash, squash, depth, and more.

Summary

Functions

Returns the argument list for git pull.

Parses the output of git pull.

Types

t()

@type t() :: %Git.Commands.Pull{
  autostash: boolean(),
  branch: String.t() | nil,
  depth: pos_integer() | nil,
  dry_run: boolean(),
  ff_only: boolean(),
  no_autostash: boolean(),
  no_commit: boolean(),
  no_ff: boolean(),
  no_tags: boolean(),
  prune: boolean(),
  quiet: boolean(),
  rebase: boolean() | String.t(),
  remote: String.t() | nil,
  squash: boolean(),
  tags: boolean(),
  verbose: boolean()
}

Functions

args(command)

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

Returns the argument list for git pull.

Builds the argument list from the struct fields. Boolean flags are appended when set to true. The rebase field may be true (for --rebase) or a string such as "interactive" or "merges" (for --rebase=<value>). The remote and branch positional arguments are appended at the end when present.

Examples

iex> Git.Commands.Pull.args(%Git.Commands.Pull{})
["pull"]

iex> Git.Commands.Pull.args(%Git.Commands.Pull{remote: "origin", branch: "main"})
["pull", "origin", "main"]

iex> Git.Commands.Pull.args(%Git.Commands.Pull{rebase: true})
["pull", "--rebase"]

iex> Git.Commands.Pull.args(%Git.Commands.Pull{rebase: "merges"})
["pull", "--rebase=merges"]

iex> Git.Commands.Pull.args(%Git.Commands.Pull{ff_only: true, prune: true})
["pull", "--ff-only", "--prune"]

parse_output(stdout, exit_code)

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

Parses the output of git pull.

On success (exit code 0), parses the output into a Git.PullResult struct. On failure, returns {:error, {stdout, exit_code}}.