Git.Commands.Init (git v0.7.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git init.

Supports initializing a new repository at an optional path, with optional --bare and --initial-branch options.

Summary

Functions

Returns the argument list for git init.

Parses the output of git init.

Types

t()

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

Functions

args(command)

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

Returns the argument list for git init.

When :bare is true, passes --bare. When :initial_branch is set, passes --initial-branch=<name> (useful because CI runners often have no init.defaultBranch configured). 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{initial_branch: "main"})
["init", "--initial-branch=main"]

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

iex> Git.Commands.Init.args(%Git.Commands.Init{bare: true, initial_branch: "main", path: "/tmp/repo.git"})
["init", "--bare", "--initial-branch=main", "/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}}.