Git.Commands.MergeFile (git v0.7.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git merge-file.

git merge-file runs a scripted three-way file merge. It incorporates the changes that lead from base to other into current, writing the merged result (with conflict markers where the two sides overlap) back into the current file. Nothing in the repository index or history is touched: this operates purely on the three files on disk.

The process exit code carries the number of conflicts as a signal: 0 for a clean merge, or the conflict count (clamped by git to 127). Values of 128 and above indicate a real error (bad option, missing file), not a conflict count. parse_output/2 distinguishes the two.

Summary

Functions

Returns the argument list for git merge-file.

Parses the output of git merge-file.

Types

t()

@type t() :: %Git.Commands.MergeFile{
  base: String.t() | nil,
  current: String.t() | nil,
  diff3: boolean(),
  labels: [String.t()],
  marker_size: pos_integer() | nil,
  other: String.t() | nil,
  ours: boolean(),
  quiet: boolean(),
  theirs: boolean(),
  union: boolean(),
  zdiff3: boolean()
}

Functions

args(cmd)

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

Returns the argument list for git merge-file.

Examples

iex> Git.Commands.MergeFile.args(%Git.Commands.MergeFile{current: "a", base: "o", other: "b"})
["merge-file", "a", "o", "b"]

iex> Git.Commands.MergeFile.args(%Git.Commands.MergeFile{current: "a", base: "o", other: "b", ours: true})
["merge-file", "--ours", "a", "o", "b"]

iex> Git.Commands.MergeFile.args(%Git.Commands.MergeFile{current: "a", base: "o", other: "b", labels: ["mine", "orig", "theirs"]})
["merge-file", "-L", "mine", "-L", "orig", "-L", "theirs", "a", "o", "b"]

parse_output(stdout, exit_code)

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

Parses the output of git merge-file.

The exit code is the number of conflicts. A clean merge returns {:ok, 0}; a merge that left conflict markers in the current file returns {:ok, count} with count > 0. Exit codes of 128 or greater are real errors and return {:error, {stdout, exit_code}}.