Implements the Git.Command behaviour for git checkout.
Supports switching to an existing branch, creating and switching to a new
branch (-b), and restoring files from the index.
Summary
Types
Functions
Returns the argument list for git checkout.
- If
:filesis non-empty, buildsgit checkout -- <files...>. - If
:branchis set and:createis true, buildsgit checkout -b <branch>. - If
:branchis set, buildsgit checkout <branch>.
Examples
iex> Git.Commands.Checkout.args(%Git.Commands.Checkout{branch: "main"})
["checkout", "main"]
iex> Git.Commands.Checkout.args(%Git.Commands.Checkout{branch: "feat/new", create: true})
["checkout", "-b", "feat/new"]
iex> Git.Commands.Checkout.args(%Git.Commands.Checkout{files: ["README.md", "lib/foo.ex"]})
["checkout", "--", "README.md", "lib/foo.ex"]
@spec parse_output(String.t(), non_neg_integer()) :: {:ok, Git.Checkout.t()} | {:ok, :done} | {:error, {String.t(), non_neg_integer()}}
Parses the output of git checkout.
For file restore operations (exit 0), returns {:ok, :done}.
For branch operations (exit 0), parses into a Git.Checkout struct.
On failure, returns {:error, {stdout, exit_code}}.