Git.Commands.Restore (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git restore.

git restore is the modern (Git 2.23+) command for restoring working tree files, replacing the file-restoration role of git checkout. It provides explicit control over restoring from the index (staged) vs a source commit.

Summary

Functions

Returns the argument list for git restore.

Parses the output of git restore.

Types

t()

@type t() :: %Git.Commands.Restore{
  files: [String.t()],
  ours: boolean(),
  patch: boolean(),
  source: String.t() | nil,
  staged: boolean(),
  theirs: boolean(),
  worktree: boolean()
}

Functions

args(cmd)

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

Returns the argument list for git restore.

Examples

iex> Git.Commands.Restore.args(%Git.Commands.Restore{files: ["README.md"]})
["restore", "README.md"]

iex> Git.Commands.Restore.args(%Git.Commands.Restore{files: ["lib/foo.ex"], staged: true})
["restore", "--staged", "lib/foo.ex"]

iex> Git.Commands.Restore.args(%Git.Commands.Restore{files: ["lib/foo.ex"], source: "HEAD~1"})
["restore", "--source", "HEAD~1", "lib/foo.ex"]

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

git restore produces no stdout on success (exit 0), so we return {:ok, :done}.