Git.Commands.HashObject (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git hash-object.

Computes the object ID for a file and optionally writes it into the object database. Only file-based hashing is supported (no stdin).

Summary

Functions

Returns the argument list for git hash-object.

Parses the output of git hash-object.

Types

t()

@type t() :: %Git.Commands.HashObject{
  file: String.t() | nil,
  literally: boolean(),
  type: String.t() | nil,
  write: boolean()
}

Functions

args(command)

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

Returns the argument list for git hash-object.

Examples

iex> Git.Commands.HashObject.args(%Git.Commands.HashObject{file: "README.md"})
["hash-object", "README.md"]

iex> Git.Commands.HashObject.args(%Git.Commands.HashObject{file: "README.md", write: true})
["hash-object", "-w", "README.md"]

iex> Git.Commands.HashObject.args(%Git.Commands.HashObject{file: "README.md", type: "commit"})
["hash-object", "-t", "commit", "README.md"]

iex> Git.Commands.HashObject.args(%Git.Commands.HashObject{file: "README.md", literally: true})
["hash-object", "--literally", "README.md"]

parse_output(stdout, exit_code)

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

Parses the output of git hash-object.

On success (exit code 0), returns {:ok, hash} where hash is the trimmed SHA string. On failure, returns {:error, {stdout, exit_code}}.