Git.Commands.Init (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git init.

Supports initializing a new repository at an optional path, with an optional --bare flag for creating a bare repository.

Summary

Functions

Returns the argument list for git init.

Parses the output of git init.

Types

t()

@type t() :: %Git.Commands.Init{bare: boolean(), path: String.t() | nil}

Functions

args(init)

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

Returns the argument list for git init.

When :bare is true, passes --bare. When :path is set, appends it as the final argument.

Examples

iex> Git.Commands.Init.args(%Git.Commands.Init{})
["init"]

iex> Git.Commands.Init.args(%Git.Commands.Init{bare: true})
["init", "--bare"]

iex> Git.Commands.Init.args(%Git.Commands.Init{path: "/tmp/repo"})
["init", "/tmp/repo"]

iex> Git.Commands.Init.args(%Git.Commands.Init{bare: true, path: "/tmp/repo.git"})
["init", "--bare", "/tmp/repo.git"]

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

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