Git.Commands.Mv (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git mv.

Supports moving or renaming a tracked file, with options for force, dry-run, verbose output, and skipping errors.

Summary

Functions

Returns the argument list for git mv.

Parses the output of git mv.

Types

t()

@type t() :: %Git.Commands.Mv{
  destination: String.t(),
  dry_run: boolean(),
  force: boolean(),
  skip_errors: boolean(),
  source: String.t(),
  verbose: boolean()
}

Functions

args(command)

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

Returns the argument list for git mv.

Builds git mv [options] <source> <destination> from the struct fields.

Examples

iex> Git.Commands.Mv.args(%Git.Commands.Mv{source: "a.txt", destination: "b.txt"})
["mv", "a.txt", "b.txt"]

iex> Git.Commands.Mv.args(%Git.Commands.Mv{source: "a.txt", destination: "b.txt", force: true})
["mv", "-f", "a.txt", "b.txt"]

iex> Git.Commands.Mv.args(%Git.Commands.Mv{source: "a.txt", destination: "b.txt", dry_run: true, verbose: true})
["mv", "-n", "-v", "a.txt", "b.txt"]

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

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