Git.Patch (git v0.4.0)

Copy Markdown View Source

Higher-level patch workflow operations that compose Git.format_patch/1, Git.apply_patch/1, and Git.am/1.

All functions accept an optional keyword list. Use :config to specify the repository via a Git.Config struct; when omitted a default config is built from the environment.

Summary

Functions

Applies a patch file to the working tree.

Applies mailbox-formatted patches (git am).

Checks whether a patch applies cleanly without actually applying it.

Creates patch files from commits starting at a ref.

Functions

apply(patch_file, opts \\ [])

@spec apply(
  String.t(),
  keyword()
) :: {:ok, :done} | {:ok, String.t()} | {:error, term()}

Applies a patch file to the working tree.

Delegates to Git.apply_patch/1.

Options

Examples

{:ok, :done} = Git.Patch.apply("0001-fix.patch")

apply_mailbox(patches, opts \\ [])

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

Applies mailbox-formatted patches (git am).

Delegates to Git.am/1.

Options

Examples

{:ok, :done} = Git.Patch.apply_mailbox(["0001-fix.patch"])

check(patch_file, opts \\ [])

@spec check(
  String.t(),
  keyword()
) :: {:ok, String.t()} | {:error, term()}

Checks whether a patch applies cleanly without actually applying it.

Uses Git.apply_patch/1 with the :check option.

Options

Examples

{:ok, _output} = Git.Patch.check("0001-fix.patch")

create(ref, opts \\ [])

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

Creates patch files from commits starting at a ref.

Delegates to Git.format_patch/1.

Options

  • :config - a Git.Config struct
  • :output_directory - directory to write patch files to

Examples

{:ok, files} = Git.Patch.create("HEAD~3")
{:ok, files} = Git.Patch.create("HEAD~1", output_directory: "/tmp/patches")