Juggernaut.Plan.Git (Juggernaut v0.4.0)

Copy Markdown View Source

The git queries the planner needs, run in the project root through a runner function (run/2 by default; tests pass their own). Paths are relative to the project root (--relative), so a project in a subdirectory of its repository works.

Every failure is a usage error (exit 2): git missing, not a repository, or a ref that does not resolve. Nothing falls back silently to another scope.

Summary

Functions

Files changed since base (committed or not), relative to root.

The -U0 diff of the working tree against base for paths.

The merge base of ref and HEAD.

Runs git with args in root. Success returns stdout alone: git writes warnings (such as core.autocrlf's "LF will be replaced by CRLF") to stderr, and merged into stdout they would corrupt the -z path listings, so they pass through to the terminal instead. On failure git runs again with stderr captured, for its message.

Untracked, not ignored files, relative to root.

Types

runner()

@type runner() :: ([String.t()], Path.t() -> {:ok, String.t()} | {:error, String.t()})

Functions

changed_files(runner, root, base)

@spec changed_files(runner(), Path.t(), String.t()) ::
  {:ok, [String.t()]} | {:error, Juggernaut.Error.t()}

Files changed since base (committed or not), relative to root.

diff(runner, root, base, paths)

@spec diff(runner(), Path.t(), String.t(), [String.t()]) ::
  {:ok, String.t()} | {:error, Juggernaut.Error.t()}

The -U0 diff of the working tree against base for paths.

merge_base(runner, root, ref)

@spec merge_base(runner(), Path.t(), String.t()) ::
  {:ok, String.t()} | {:error, Juggernaut.Error.t()}

The merge base of ref and HEAD.

run(args, root)

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

Runs git with args in root. Success returns stdout alone: git writes warnings (such as core.autocrlf's "LF will be replaced by CRLF") to stderr, and merged into stdout they would corrupt the -z path listings, so they pass through to the terminal instead. On failure git runs again with stderr captured, for its message.

untracked(runner, root)

@spec untracked(runner(), Path.t()) ::
  {:ok, [String.t()]} | {:error, Juggernaut.Error.t()}

Untracked, not ignored files, relative to root.