# `Minga.Git`
[🔗](https://github.com/jsmestad/minga/blob/main/sdk/lib/minga/git.ex#L1)

Read and change an explicit Git repository. Operations that invoke Git belong in an extension worker, not an editor callback. Editor buffer tracking and repository processes are private to the host.

# `change`

```elixir
@type change() :: MingaEditor.Extension.GitDiff.Hunk.change()
```

One contiguous change with zero-based coordinates in the base and revised text.

# `diff_opt`

```elixir
@type diff_opt() :: {:path, String.t()} | {:staged, boolean()} | {:commit, String.t()}
```

Accepted diff options. Unknown keys, duplicate keys, and invalid values are rejected. `:commit` may be combined with `:staged`, but only when `:staged` is `false`.

# `diff_opts`

```elixir
@type diff_opts() :: [diff_opt()]
```

# `log_entry`

```elixir
@type log_entry() :: Minga.Git.LogEntry.t()
```

A structured log entry.

# `stash_entry`

```elixir
@type stash_entry() :: Minga.Git.StashEntry.t()
```

A structured stash entry.

# `status_entry`

```elixir
@type status_entry() :: Minga.Git.StatusEntry.t()
```

A structured status entry for one file.

# `status_opt`

```elixir
@type status_opt() ::
  {:untracked_mode, untracked_mode()} | {:timeout_ms, pos_integer()}
```

Accepted `status/2` options.

# `status_opts`

```elixir
@type status_opts() :: [status_opt()]
```

# `untracked_mode`

```elixir
@type untracked_mode() :: :no | :normal | :all
```

How much untracked-file detail `git status` should enumerate.

# `ahead_behind`

```elixir
@spec ahead_behind(String.t()) :: {:ok, non_neg_integer(), non_neg_integer()} | :error
```

# `blame_line`

```elixir
@spec blame_line(String.t(), String.t(), non_neg_integer()) ::
  {:ok, String.t()} | :error
```

# `branch_create`

```elixir
@spec branch_create(String.t(), String.t()) :: :ok | {:error, String.t()}
```

# `branch_delete`

```elixir
@spec branch_delete(String.t(), String.t(), boolean()) :: :ok | {:error, String.t()}
```

# `branch_list`

```elixir
@spec branch_list(String.t()) ::
  {:ok, [Minga.Git.BranchInfo.t()]} | {:error, String.t()}
```

# `branch_switch`

```elixir
@spec branch_switch(String.t(), String.t()) :: :ok | {:error, String.t()}
```

# `change_at`

```elixir
@spec change_at([change()], non_neg_integer()) :: change() | nil
```

Finds the change at a buffer line, including the anchor above a deletion.

# `commit`

```elixir
@spec commit(String.t(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, String.t()}
```

# `current_branch`

```elixir
@spec current_branch(String.t()) :: {:ok, String.t()} | :error
```

# `diff`

```elixir
@spec diff(String.t(), diff_opts()) :: {:ok, String.t()} | {:error, String.t()}
```

# `discard`

```elixir
@spec discard(String.t(), String.t()) :: :ok | {:error, String.t()}
```

# `fetch_remotes`

```elixir
@spec fetch_remotes(String.t(), keyword()) :: :ok | {:error, String.t()}
```

# `index_blob`

```elixir
@spec index_blob(String.t(), String.t()) ::
  {:ok, binary() | nil} | {:error, String.t()}
```

Reads a regular file's stage-zero blob, returning `{:ok, nil}` for an absent
path, `{:ok, ""}` for an empty blob, and `{:error, reason}` for an unmerged
path or a read failure.

# `last_commit_message`

```elixir
@spec last_commit_message(String.t()) :: {:ok, String.t()} | :error
```

# `log`

```elixir
@spec log(String.t(), keyword()) :: {:ok, [log_entry()]} | {:error, String.t()}
```

Reads recent commits with `:count`, `:path`, `:skip`, and a full `:revision` object ID.

# `neighbor_change_line`

```elixir
@spec neighbor_change_line([change()], non_neg_integer(), :next | :previous) ::
  non_neg_integer() | nil
```

Returns the next or previous change's buffer line, or nil if there is none.

# `pull`

```elixir
@spec pull(String.t(), keyword()) :: :ok | {:error, String.t()}
```

# `push`

```elixir
@spec push(String.t(), keyword()) :: :ok | {:error, String.t()}
```

# `refresh_status`

```elixir
@spec refresh_status(String.t()) :: :ok
```

Requests a status refresh if Minga already tracks this repository.

# `relative_path`

```elixir
@spec relative_path(String.t(), String.t()) :: String.t()
```

# `revert_change`

```elixir
@spec revert_change(binary(), change()) :: binary()
```

Reverts just one change in the revised text, without editing or saving a buffer.

# `root_for`

```elixir
@spec root_for(String.t() | nil) :: {:ok, String.t()} | :not_git
```

# `show_head`

```elixir
@spec show_head(String.t(), String.t()) :: {:ok, String.t()} | :error
```

# `show_staged`

```elixir
@spec show_staged(String.t(), String.t()) :: {:ok, String.t()} | :error
```

# `stage`

```elixir
@spec stage(String.t(), String.t() | [String.t()]) :: :ok | {:error, String.t()}
```

# `stage_change`

```elixir
@spec stage_change(String.t(), String.t(), binary() | nil, binary() | nil, change()) ::
  :ok | {:error, String.t()}
```

Stages only the selected change without modifying the worktree.

Use `nil` for an absent file and `""` for a present empty file in either
snapshot. A mismatch in index presence or a conflicting edit at the selected
hunk is rejected. Unrelated staged changes are preserved.

# `stage_patch`

```elixir
@spec stage_patch(String.t(), String.t()) :: :ok | {:error, String.t()}
```

# `stash`

```elixir
@spec stash(String.t(), keyword()) :: :ok | {:error, String.t()}
```

# `stash_drop`

```elixir
@spec stash_drop(String.t(), non_neg_integer()) :: :ok | {:error, String.t()}
```

# `stash_list`

```elixir
@spec stash_list(String.t()) :: {:ok, [stash_entry()]} | {:error, String.t()}
```

# `stash_pop`

```elixir
@spec stash_pop(String.t()) :: :ok | {:error, String.t()}
```

# `status`

```elixir
@spec status(String.t(), status_opts()) ::
  {:ok, [status_entry()]} | {:error, String.t()}
```

# `tracked_file`

```elixir
@spec tracked_file(pid()) :: {:ok, Minga.Git.TrackedFile.t()} | :not_tracked
```

Captures tracked-buffer text, cursor, version, and changes against cached HEAD.

# `unstage`

```elixir
@spec unstage(String.t(), String.t() | [String.t()]) :: :ok | {:error, String.t()}
```

# `unstage_all`

```elixir
@spec unstage_all(String.t()) :: :ok | {:error, String.t()}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
