GitCli (fnord v0.9.29)

View Source

Wrapper for direct git CLI calls.

Covers repo classification (is_git_repo?/0, worktree_root/0), branch reporting (current_branch/0, default_branch/1), tree enumeration for indexing (ls_tree/2, show_blob/3), gitignore resolution (ignored_files/1), and formatted user-facing messages (git_info/0).

Note: default_branch/1 resolves the project's indexing branch with a strict fallback chain (origin/HEAD → main → master → nil). For the looser worktree-root resolution that falls back to the current branch, see GitCli.Worktree.default_base_branch/1.

Summary

Functions

Returns the repository's default branch for indexing purposes

Returns an empty map if root is nil, otherwise behaves as before.

Lists every blob in branch's tree as {blob_sha, rel_path} pairs. The blob sha is git's content-addressed hash and is stable across clones and checkouts, so it's usable as a freshness key for the indexer.

Returns the content of rel_path as it exists on branch, or an error tuple if git rejects the request (missing file, invalid branch, etc.). Content is returned as a binary; binaries that aren't valid UTF-8 are still returned — callers decide how to handle them.

Functions

current_branch()

@spec current_branch() :: String.t() | nil

default_branch(root)

@spec default_branch(String.t() | nil) :: String.t() | nil

Returns the repository's default branch for indexing purposes:

  1. origin/HEAD - the remote's declared default (usually main).
  2. Local main or master, in that order.
  3. nil - do not silently fall back to the current branch, since that would make fnord index on a feature branch index the feature branch rather than the project's canonical source.

Callers fall back to filesystem-mode indexing when this returns nil, so the user still gets their working tree indexed; they just won't get default-branch semantics.

git_info()

@spec git_info() :: String.t()

ignored_files(root)

@spec ignored_files(String.t() | nil) :: map()

Returns an empty map if root is nil, otherwise behaves as before.

is_git_repo?()

@spec is_git_repo?() :: boolean()

is_git_repo_at?(path)

@spec is_git_repo_at?(String.t() | nil) :: boolean()

is_worktree?()

ls_tree(root, branch)

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

Lists every blob in branch's tree as {blob_sha, rel_path} pairs. The blob sha is git's content-addressed hash and is stable across clones and checkouts, so it's usable as a freshness key for the indexer.

repo_root()

show_blob(root, branch, rel_path)

@spec show_blob(String.t(), String.t(), String.t()) ::
  {:ok, binary()} | {:error, term()}

Returns the content of rel_path as it exists on branch, or an error tuple if git rejects the request (missing file, invalid branch, etc.). Content is returned as a binary; binaries that aren't valid UTF-8 are still returned — callers decide how to handle them.

worktree_root()