Minga.Git (minga_sdk v0.1.2)

Copy Markdown View Source

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.

Summary

Types

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

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

A structured log entry.

A structured stash entry.

A structured status entry for one file.

Accepted status/2 options.

How much untracked-file detail git status should enumerate.

Functions

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

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.

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

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

Requests a status refresh if Minga already tracks this repository.

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

Stages only the selected change without modifying the worktree.

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

Types

change()

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

diff_opt()

@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()

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

log_entry()

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

A structured log entry.

stash_entry()

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

A structured stash entry.

status_entry()

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

A structured status entry for one file.

status_opt()

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

Accepted status/2 options.

status_opts()

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

untracked_mode()

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

How much untracked-file detail git status should enumerate.

Functions

ahead_behind(git_root)

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

blame_line(git_root, relative_path, line_number)

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

branch_create(git_root, name)

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

branch_delete(git_root, name, force \\ false)

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

branch_list(git_root)

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

branch_switch(git_root, name)

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

change_at(hunks, line)

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

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

commit(git_root, message, opts \\ [])

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

current_branch(git_root)

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

diff(git_root, opts \\ [])

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

discard(git_root, path)

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

fetch_remotes(git_root, opts \\ [])

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

index_blob(git_root, relative_path)

@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(git_root)

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

log(git_root, opts \\ [])

@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(hunks, line, direction)

@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(git_root, opts \\ [])

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

push(git_root, opts \\ [])

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

refresh_status(git_root)

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

Requests a status refresh if Minga already tracks this repository.

relative_path(git_root, file_path)

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

revert_change(content, change)

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

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

root_for(path)

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

show_head(git_root, relative_path)

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

show_staged(git_root, relative_path)

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

stage(git_root, paths)

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

stage_change(git_root, relative_path, base, revised, change)

@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(git_root, patch)

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

stash(git_root, opts \\ [])

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

stash_drop(git_root, index)

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

stash_list(git_root)

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

stash_pop(git_root)

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

status(git_root, opts \\ [])

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

tracked_file(buffer_pid)

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

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

unstage(git_root, paths)

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

unstage_all(git_root)

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