Git.Commands.Add (git v0.6.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git add.

Builds git add [flags] [-- <paths>]. Flags and a pathspec compose, so a path can be staged together with any of --all, --update, --force, --dry-run, --intent-to-add, --renormalize, and --chmod.

Summary

Functions

Returns the argument list for git add.

Parses the output of git add.

Types

t()

@type t() :: %Git.Commands.Add{
  all: boolean(),
  chmod: String.t() | nil,
  dry_run: boolean(),
  files: [String.t()],
  force: boolean(),
  intent_to_add: boolean(),
  renormalize: boolean(),
  update: boolean()
}

Functions

args(command)

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

Returns the argument list for git add.

Emits the enabled flags followed by the pathspec, so flags and files compose (unlike the previous behavior, where :all dropped :files).

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"]

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

iex> Git.Commands.Add.args(%Git.Commands.Add{intent_to_add: true, files: ["new.ex"]})
["add", "--intent-to-add", "new.ex"]

iex> Git.Commands.Add.args(%Git.Commands.Add{chmod: "+x", files: ["run.sh"]})
["add", "--chmod=+x", "run.sh"]

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