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
Types
@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
Returns the argument list for git submodule.
- If
:add_urlis set, buildsgit submodule add [options] <url> [<path>]. - If
:deinitis set, buildsgit submodule deinit [--force] [--all] <path>. - If
:initis true, buildsgit submodule init [<path>]. - If
:updateis true, buildsgit submodule update [options] [<path>]. - If
:syncis true, buildsgit submodule sync [--recursive] [<path>]. - If
:summaryis true, buildsgit submodule summary [<path>]. - If
:set_branchis set, buildsgit submodule set-branch -b <branch> <path>. - If
:set_urlis set, buildsgit 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"]
@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}}.