Minga.Git.Backend behaviour (Minga v0.1.0)

Copy Markdown View Source

Behaviour for git operations.

The default implementation (Minga.Git.System) shells out to the git CLI. In tests, Minga.Git.Stub returns inert responses without spawning OS processes.

Configure via:

config :minga, git_module: Minga.Git.System   # default
config :minga, git_module: Minga.Git.Stub      # tests

Summary

Callbacks

ahead_behind(git_root)

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

blame_line(git_root, relative_path, line)

@callback blame_line(
  git_root :: String.t(),
  relative_path :: String.t(),
  line :: non_neg_integer()
) :: {:ok, String.t()} | :error

branch_create(git_root, name)

@callback branch_create(git_root :: String.t(), name :: String.t()) ::
  :ok | {:error, String.t()}

branch_delete(git_root, name, force)

@callback branch_delete(git_root :: String.t(), name :: String.t(), force :: boolean()) ::
  :ok | {:error, String.t()}

branch_list(git_root)

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

branch_switch(git_root, name)

@callback branch_switch(git_root :: String.t(), name :: String.t()) ::
  :ok | {:error, String.t()}

commit(git_root, message, opts)

@callback commit(git_root :: String.t(), message :: String.t(), opts :: keyword()) ::
  {:ok, String.t()} | {:error, String.t()}

current_branch(git_root)

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

diff(git_root, opts)

@callback diff(git_root :: String.t(), opts :: Minga.Git.diff_opts()) ::
  {:ok, String.t()} | {:error, String.t()}

discard(git_root, path)

@callback discard(git_root :: String.t(), path :: String.t()) ::
  :ok | {:error, String.t()}

fetch_remotes(git_root, opts)

@callback fetch_remotes(git_root :: String.t(), opts :: keyword()) ::
  :ok | {:error, String.t()}

last_commit_message(git_root)

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

log(git_root, opts)

@callback log(git_root :: String.t(), opts :: keyword()) ::
  {:ok, [Minga.Git.log_entry()]} | {:error, String.t()}

pull(git_root, opts)

@callback pull(git_root :: String.t(), opts :: keyword()) :: :ok | {:error, String.t()}

push(git_root, opts)

@callback push(git_root :: String.t(), opts :: keyword()) :: :ok | {:error, String.t()}

root_for(path)

@callback root_for(path :: String.t()) :: {:ok, String.t()} | :not_git

show_head(git_root, relative_path)

@callback show_head(git_root :: String.t(), relative_path :: String.t()) ::
  {:ok, String.t()} | :error

show_staged(git_root, relative_path)

@callback show_staged(git_root :: String.t(), relative_path :: String.t()) ::
  {:ok, String.t()} | :error

stage(git_root, paths)

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

stage_patch(git_root, patch)

@callback stage_patch(git_root :: String.t(), patch :: String.t()) ::
  :ok | {:error, String.t()}

stash(git_root, opts)

@callback stash(git_root :: String.t(), opts :: keyword()) :: :ok | {:error, String.t()}

stash_drop(git_root, index)

@callback stash_drop(git_root :: String.t(), index :: non_neg_integer()) ::
  :ok | {:error, String.t()}

stash_list(git_root)

@callback stash_list(git_root :: String.t()) ::
  {:ok, [Minga.Git.stash_entry()]} | {:error, String.t()}

stash_pop(git_root)

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

status(git_root, opts)

@callback status(git_root :: String.t(), opts :: keyword()) ::
  {:ok, [Minga.Git.status_entry()]} | {:error, String.t()}

unstage(git_root, paths)

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

unstage_all(git_root)

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