Git.Commands.Add (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git add.

Supports adding specific files or all changes with --all.

Summary

Functions

Returns the argument list for git add.

Parses the output of git add.

Types

t()

@type t() :: %Git.Commands.Add{all: boolean(), files: [String.t()]}

Functions

args(add)

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

Returns the argument list for git add.

When :all is true, passes --all. Otherwise, appends the list of file paths to the argument list.

Examples

iex> Git.Commands.Add.args(%Git.Commands.Add{all: true})
["add", "--all"]

iex> Git.Commands.Add.args(%Git.Commands.Add{files: ["foo.txt", "bar.txt"]})
["add", "foo.txt", "bar.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 add.

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