Git.Commands.Rm (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git rm.

Supports removing tracked files from the index and optionally from the working tree, with options for cached-only removal, force, recursive, dry-run, quiet output, and pathspec-from-file.

Summary

Functions

Returns the argument list for git rm.

Parses the output of git rm.

Types

t()

@type t() :: %Git.Commands.Rm{
  cached: boolean(),
  dry_run: boolean(),
  files: [String.t()],
  force: boolean(),
  pathspec_from_file: String.t() | nil,
  quiet: boolean(),
  recursive: boolean()
}

Functions

args(command)

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

Returns the argument list for git rm.

Builds git rm [options] [--] <files> from the struct fields.

Examples

iex> Git.Commands.Rm.args(%Git.Commands.Rm{files: ["a.txt"]})
["rm", "a.txt"]

iex> Git.Commands.Rm.args(%Git.Commands.Rm{files: ["a.txt"], cached: true})
["rm", "--cached", "a.txt"]

iex> Git.Commands.Rm.args(%Git.Commands.Rm{files: ["dir/"], recursive: true, force: true})
["rm", "-f", "-r", "dir/"]

iex> Git.Commands.Rm.args(%Git.Commands.Rm{files: [], pathspec_from_file: "paths.txt"})
["rm", "--pathspec-from-file", "paths.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 rm.

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