Git.Commands.Clone (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git clone.

Supports cloning a repository with optional --depth (shallow clone) and --branch flags. An optional target directory name may also be specified.

Summary

Functions

Returns the argument list for git clone.

Parses the output of git clone.

Types

t()

@type t() :: %Git.Commands.Clone{
  branch: String.t() | nil,
  depth: pos_integer() | nil,
  directory: String.t() | nil,
  url: String.t()
}

Functions

args(clone)

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

Returns the argument list for git clone.

Always includes the repository URL. Optional flags are appended in order: --depth=N, --branch=NAME, and a target directory when set.

Examples

iex> Git.Commands.Clone.args(%Git.Commands.Clone{url: "https://example.com/repo.git"})
["clone", "https://example.com/repo.git"]

iex> Git.Commands.Clone.args(%Git.Commands.Clone{url: "https://example.com/repo.git", depth: 1})
["clone", "--depth=1", "https://example.com/repo.git"]

iex> Git.Commands.Clone.args(%Git.Commands.Clone{url: "https://example.com/repo.git", branch: "main", depth: 1})
["clone", "--depth=1", "--branch=main", "https://example.com/repo.git"]

iex> Git.Commands.Clone.args(%Git.Commands.Clone{url: "https://example.com/repo.git", directory: "my-repo"})
["clone", "https://example.com/repo.git", "my-repo"]

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

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