Git.Commands.Submodule (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git submodule.

Supports status (default), init, update, add, deinit, sync, summary, set-branch, and set-url subcommands.

The foreach subcommand is intentionally not supported because it requires an arbitrary shell command string, which does not fit the structured command model and would introduce shell injection concerns.

Summary

Functions

Returns the argument list for git submodule.

Parses the output of git submodule.

Types

t()

@type t() :: %Git.Commands.Submodule{
  add_path: String.t() | nil,
  add_url: String.t() | nil,
  all: boolean(),
  branch: String.t() | nil,
  deinit: String.t() | nil,
  depth: non_neg_integer() | nil,
  force: boolean(),
  init: boolean(),
  merge: boolean(),
  name: String.t() | nil,
  path: String.t() | nil,
  quiet: boolean(),
  rebase: boolean(),
  recursive: boolean(),
  reference: String.t() | nil,
  remote: boolean(),
  set_branch: String.t() | nil,
  set_url: String.t() | nil,
  status: boolean(),
  summary: boolean(),
  sync: boolean(),
  update: boolean()
}

Functions

args(command)

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

Returns the argument list for git submodule.

  • If :add_url is set, builds git submodule add [options] <url> [<path>].
  • If :deinit is set, builds git submodule deinit [--force] [--all] <path>.
  • If :init is true, builds git submodule init [<path>].
  • If :update is true, builds git submodule update [options] [<path>].
  • If :sync is true, builds git submodule sync [--recursive] [<path>].
  • If :summary is true, builds git submodule summary [<path>].
  • If :set_branch is set, builds git submodule set-branch -b <branch> <path>.
  • If :set_url is set, builds git submodule set-url <path> <url>.
  • Otherwise, shows status with git submodule status [--recursive] [<path>].

Examples

iex> Git.Commands.Submodule.args(%Git.Commands.Submodule{})
["submodule", "status"]

iex> Git.Commands.Submodule.args(%Git.Commands.Submodule{init: true})
["submodule", "init"]

iex> Git.Commands.Submodule.args(%Git.Commands.Submodule{update: true, recursive: true})
["submodule", "update", "--recursive"]

iex> Git.Commands.Submodule.args(%Git.Commands.Submodule{add_url: "https://example.com/lib.git", add_path: "vendor/lib"})
["submodule", "add", "https://example.com/lib.git", "vendor/lib"]

iex> Git.Commands.Submodule.args(%Git.Commands.Submodule{deinit: "vendor/lib", force: true})
["submodule", "deinit", "--force", "vendor/lib"]

iex> Git.Commands.Submodule.args(%Git.Commands.Submodule{sync: true, recursive: true})
["submodule", "sync", "--recursive"]

parse_output(stdout, exit_code)

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

Parses the output of git submodule.

For status operations (exit 0), parses each line into a Git.SubmoduleEntry struct. For mutation operations (exit 0), returns {:ok, :done}. For summary operations (exit 0), returns {:ok, stdout} with the raw summary text. On failure, returns {:error, {stdout, exit_code}}.