Git.Commands.SparseCheckout (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git sparse-checkout.

Supports initializing, setting, adding, listing, disabling, reapplying, and checking rules for sparse-checkout.

Summary

Functions

Returns the argument list for git sparse-checkout.

Parses the output of git sparse-checkout.

Types

t()

@type t() :: %Git.Commands.SparseCheckout{
  add: [String.t()],
  check_rules: boolean(),
  cone: boolean(),
  disable: boolean(),
  init: boolean(),
  list: boolean(),
  no_cone: boolean(),
  no_sparse_index: boolean(),
  reapply: boolean(),
  set: [String.t()],
  sparse_index: boolean()
}

Functions

args(command)

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

Returns the argument list for git sparse-checkout.

  • If :init is true, builds git sparse-checkout init [--cone] [--sparse-index].
  • If :set is non-empty, builds git sparse-checkout set [--cone] [--no-cone] <patterns...>.
  • If :add is non-empty, builds git sparse-checkout add [--cone] [--no-cone] <patterns...>.
  • If :disable is true, builds git sparse-checkout disable.
  • If :reapply is true, builds git sparse-checkout reapply.
  • If :check_rules is true, builds git sparse-checkout check-rules.
  • Otherwise, lists current patterns with git sparse-checkout list.

Examples

iex> Git.Commands.SparseCheckout.args(%Git.Commands.SparseCheckout{})
["sparse-checkout", "list"]

iex> Git.Commands.SparseCheckout.args(%Git.Commands.SparseCheckout{init: true, cone: true})
["sparse-checkout", "init", "--cone"]

iex> Git.Commands.SparseCheckout.args(%Git.Commands.SparseCheckout{set: ["src/", "docs/"], cone: true})
["sparse-checkout", "set", "--cone", "src/", "docs/"]

iex> Git.Commands.SparseCheckout.args(%Git.Commands.SparseCheckout{add: ["tests/"]})
["sparse-checkout", "add", "tests/"]

iex> Git.Commands.SparseCheckout.args(%Git.Commands.SparseCheckout{disable: true})
["sparse-checkout", "disable"]

iex> Git.Commands.SparseCheckout.args(%Git.Commands.SparseCheckout{reapply: true})
["sparse-checkout", "reapply"]

parse_output(stdout, exit_code)

@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, [String.t()]} | {:ok, :done} | {:error, {String.t(), non_neg_integer()}}

Parses the output of git sparse-checkout.

For list operations (exit 0), returns {:ok, [pattern]} with one pattern per line. For all mutation operations (exit 0), returns {:ok, :done}. On failure, returns {:error, {stdout, exit_code}}.