Git.Commands.Fsck (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git fsck.

Verifies the connectivity and validity of objects in the database. Parses fsck output into a list of issue maps describing dangling, missing, or broken objects.

Summary

Functions

Returns the argument list for git fsck.

Parses the output of git fsck.

Types

t()

@type t() :: %Git.Commands.Fsck{
  connectivity_only: boolean(),
  dangling: boolean(),
  full: boolean(),
  lost_found: boolean(),
  name_objects: boolean(),
  no_dangling: boolean(),
  no_progress: boolean(),
  no_reflogs: boolean(),
  progress: boolean(),
  root: boolean(),
  strict: boolean(),
  unreachable: boolean(),
  verbose: boolean()
}

Functions

args(command)

@spec args(t()) :: [String.t()]

Returns the argument list for git fsck.

Examples

iex> Git.Commands.Fsck.args(%Git.Commands.Fsck{})
["fsck"]

iex> Git.Commands.Fsck.args(%Git.Commands.Fsck{full: true, strict: true})
["fsck", "--full", "--strict"]

iex> Git.Commands.Fsck.args(%Git.Commands.Fsck{unreachable: true, no_reflogs: true})
["fsck", "--unreachable", "--no-reflogs"]

iex> Git.Commands.Fsck.args(%Git.Commands.Fsck{connectivity_only: true})
["fsck", "--connectivity-only"]

iex> Git.Commands.Fsck.args(%Git.Commands.Fsck{lost_found: true, name_objects: true})
["fsck", "--lost-found", "--name-objects"]

parse_output(stdout, exit_code)

@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, [map()]} | {:error, {String.t(), non_neg_integer()}}

Parses the output of git fsck.

On success (exit code 0), parses each line into an issue map with :type, :object_type, and :sha keys. Lines that do not match the expected format (e.g. informational messages) are silently ignored.

Returns {:ok, [map()]} on success or {:error, {stdout, exit_code}} on failure.