GitHoox.Git (GitHoox v0.1.0)

Copy Markdown View Source

Shell out to git for file-state queries.

All functions assume the current working directory is inside a git worktree. Errors from the underlying git invocation surface as {:error, {exit_code, stderr}}.

Summary

Types

git --diff-filter status letters (e.g. "ACMR").

Functions

All tracked files via git ls-files.

Files modified in worktree since index, scoped to candidates. Used to detect what a hook mutated.

Files changed between two refs (used for post-checkout).

Files touched by the HEAD commit (used for post-commit).

Return absolute path of .git/hooks/ honoring core.hooksPath + worktrees.

Files changed by the last merge (used for post-merge).

Parse pre-push stdin and return files changed across all pushed refs.

Re-stage files via git add.

List files staged for commit.

Return repo root via git rev-parse --show-toplevel.

Types

diff_filter()

@type diff_filter() :: String.t()

git --diff-filter status letters (e.g. "ACMR").

git_error()

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

Functions

all_files()

@spec all_files() :: {:ok, [GitHoox.path()]} | git_error()

All tracked files via git ls-files.

changed_in_worktree(candidates)

@spec changed_in_worktree([GitHoox.path()]) :: [GitHoox.path()]

Files modified in worktree since index, scoped to candidates. Used to detect what a hook mutated.

diff_files(from, to)

@spec diff_files(String.t(), String.t()) :: {:ok, [GitHoox.path()]} | git_error()

Files changed between two refs (used for post-checkout).

files_in_head()

@spec files_in_head() :: {:ok, [GitHoox.path()]} | git_error()

Files touched by the HEAD commit (used for post-commit).

hooks_dir()

@spec hooks_dir() :: {:ok, Path.t()} | git_error()

Return absolute path of .git/hooks/ honoring core.hooksPath + worktrees.

merge_files()

@spec merge_files() :: {:ok, [GitHoox.path()]} | git_error()

Files changed by the last merge (used for post-merge).

push_files(stdin)

@spec push_files(String.t() | nil) :: {:ok, [GitHoox.path()]}

Parse pre-push stdin and return files changed across all pushed refs.

Stdin format per githooks(5): <local_ref> <local_sha> <remote_ref> <remote_sha> per line.

restage(files)

@spec restage([GitHoox.path()]) :: :ok | git_error()

Re-stage files via git add.

staged_files(opts \\ [])

@spec staged_files(keyword()) :: {:ok, [GitHoox.path()]} | git_error()

List files staged for commit.

Options

  • :filter--diff-filter letters. Default "ACMR" (skip deletes).

toplevel()

@spec toplevel() :: {:ok, Path.t()} | git_error()

Return repo root via git rev-parse --show-toplevel.