Minga.Extension.Git (Minga v0.1.0)

Copy Markdown View Source

Resolves git-sourced extensions by cloning and updating repos.

Extensions declared with git: are cloned to a local cache directory (~/.local/share/minga/extensions/{name}/). On first load, the repo is cloned. On subsequent boots, the cached checkout is used as-is. Explicit updates via SPC h e u fetch and fast-forward.

Summary

Types

Summary of available updates for a git extension.

Functions

Applies a previously fetched update by fast-forwarding the local checkout.

Returns the current HEAD ref (short hash) for a cloned extension.

Ensures the git repo is cloned locally. Returns the local path.

Returns the local cache path for a named extension.

Fetches remote changes and returns update info without applying them.

Rolls back to a specific ref after a failed update or compile.

Types

update_info()

@type update_info() :: %{
  name: atom(),
  old_ref: String.t(),
  new_ref: String.t(),
  commit_count: non_neg_integer(),
  branch: String.t() | nil
}

Summary of available updates for a git extension.

Functions

apply_update(name)

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

Applies a previously fetched update by fast-forwarding the local checkout.

current_ref(name)

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

Returns the current HEAD ref (short hash) for a cloned extension.

ensure_cloned(name, git_opts)

@spec ensure_cloned(atom(), %{
  url: String.t(),
  branch: String.t() | nil,
  ref: String.t() | nil
}) ::
  {:ok, String.t()} | {:error, String.t()}

Ensures the git repo is cloned locally. Returns the local path.

If the cache directory already exists, returns it immediately (no network access). If missing, clones the repo. Respects branch: and ref: options from the git config.

extension_path(name)

@spec extension_path(atom()) :: String.t()

Returns the local cache path for a named extension.

fetch_updates(name, git_opts)

@spec fetch_updates(atom(), %{
  url: String.t(),
  branch: String.t() | nil,
  ref: String.t() | nil
}) ::
  {:ok, update_info()} | :up_to_date | {:error, String.t()}

Fetches remote changes and returns update info without applying them.

Returns {:ok, update_info} if there are new commits available, :up_to_date if already current, or {:error, reason} on failure.

rollback(name, ref)

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

Rolls back to a specific ref after a failed update or compile.