Git.Commands.Push (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git push.

Supports pushing to a remote with options for force push, upstream tracking, tags, delete, dry run, and more.

Summary

Functions

Returns the argument list for git push.

Parses the output of git push.

Types

t()

@type t() :: %Git.Commands.Push{
  all: boolean(),
  atomic: boolean(),
  branch: String.t() | nil,
  delete: boolean(),
  dry_run: boolean(),
  force: boolean(),
  force_with_lease: boolean(),
  no_verify: boolean(),
  prune: boolean(),
  remote: String.t() | nil,
  set_upstream: boolean(),
  tags: boolean()
}

Functions

args(command)

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

Returns the argument list for git push.

Builds the argument list from the struct fields. Boolean flags are appended when set to true. The remote and branch positional arguments are appended at the end when present.

Examples

iex> Git.Commands.Push.args(%Git.Commands.Push{})
["push"]

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

iex> Git.Commands.Push.args(%Git.Commands.Push{remote: "origin", set_upstream: true, branch: "feature"})
["push", "-u", "origin", "feature"]

iex> Git.Commands.Push.args(%Git.Commands.Push{force: true, tags: true})
["push", "--force", "--tags"]

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 push.

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