Ancora.Git (ancora v1.0.0)

Copy Markdown View Source

The only git subprocess spawner in ancora.

Every git invocation in the library goes through this module. Ancora.Git.BatchPort is the long-lived cat-file --batch reader; read_blob/2 is the single function head for base-side blob reads, with per-file git show as the escape hatch when the run has no batch port.

Summary

Functions

Lists a tree recursively through one ls-tree -r -z subprocess.

Reads one base-side blob.

Runs a git plumbing command against root.

Types

git_error()

@type git_error() :: {:error, {:git, [String.t()], String.t(), non_neg_integer()}}

Functions

ls_tree_entries(root, treeish, pathspecs \\ [])

@spec ls_tree_entries(Path.t(), String.t(), [String.t()]) ::
  {:ok,
   [%{mode: String.t(), type: String.t(), oid: String.t(), path: String.t()}]}
  | git_error()
  | {:error, term()}

Lists a tree recursively through one ls-tree -r -z subprocess.

Each entry is %{mode:, type:, oid:, path:}. Optional pathspecs narrow the listing. -z keeps paths unquoted so names round-trip byte-identical.

read_blob(run_context, path)

@spec read_blob(Ancora.Derive.RunContext.t(), String.t()) ::
  {:ok, binary()} | {:error, term()}

Reads one base-side blob.

When the run context owns a BatchPort, the read goes through that port. When it does not, the same function head falls back to git show <base>:<path>.

run(root, args, opts \\ [])

@spec run(Path.t(), [String.t()], keyword()) :: {:ok, String.t()} | git_error()

Runs a git plumbing command against root.

Returns {:ok, output} or {:error, {:git, args, output, status}}.