Git.Commands.FormatPatch (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git format-patch.

Generates patch files from commits. Supports output to files or stdout, cover letters, numbering, and various patch formatting options.

Summary

Functions

Returns the argument list for git format-patch.

Parses the output of git format-patch.

Types

t()

@type t() :: %Git.Commands.FormatPatch{
  base: String.t() | nil,
  cover_letter: boolean(),
  from: String.t() | nil,
  no_signature: boolean(),
  no_stat: boolean(),
  numbered: boolean(),
  output_directory: String.t() | nil,
  quiet: boolean(),
  ref: String.t(),
  signature: String.t() | nil,
  start_number: non_neg_integer() | nil,
  stdout: boolean(),
  subject_prefix: String.t() | nil,
  zero_commit: boolean()
}

Functions

args(command)

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

Returns the argument list for git format-patch.

Examples

iex> Git.Commands.FormatPatch.args(%Git.Commands.FormatPatch{ref: "HEAD~3"})
["format-patch", "HEAD~3"]

iex> Git.Commands.FormatPatch.args(%Git.Commands.FormatPatch{ref: "HEAD~1", stdout: true})
["format-patch", "--stdout", "HEAD~1"]

iex> Git.Commands.FormatPatch.args(%Git.Commands.FormatPatch{ref: "v1.0..v2.0", output_directory: "/tmp/patches", numbered: true})
["format-patch", "-n", "-o", "/tmp/patches", "v1.0..v2.0"]

parse_output(stdout, exit_code)

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

Parses the output of git format-patch.

When stdout mode is active, returns {:ok, patch_content}. Otherwise, returns {:ok, [file_path]} with the list of generated patch file paths.

On failure, returns {:error, {stdout, exit_code}}.