Git.Commands.Archive (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git archive.

Creates an archive of files from a named tree. Supports tar, tar.gz, and zip formats.

Limitation: The output option is currently required. When git archive runs without --output, it writes binary data to stdout which cannot be reliably captured as a string by System.cmd/3. When output is specified, git writes directly to the file and stdout is empty.

Summary

Functions

Returns the argument list for git archive.

Parses the output of git archive.

Types

t()

@type t() :: %Git.Commands.Archive{
  format: String.t() | nil,
  output: String.t() | nil,
  paths: [String.t()],
  prefix: String.t() | nil,
  ref: String.t(),
  remote: String.t() | nil,
  verbose: boolean(),
  worktree_attributes: boolean()
}

Functions

args(command)

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

Returns the argument list for git archive.

The tree-ish ref is placed after all flags. Paths are appended after --.

Examples

iex> Git.Commands.Archive.args(%Git.Commands.Archive{})
["archive", "HEAD"]

iex> Git.Commands.Archive.args(%Git.Commands.Archive{format: "zip", output: "out.zip"})
["archive", "--format=zip", "--output=out.zip", "HEAD"]

iex> Git.Commands.Archive.args(%Git.Commands.Archive{prefix: "project/", paths: ["lib/"]})
["archive", "--prefix=project/", "HEAD", "--", "lib/"]

iex> Git.Commands.Archive.args(%Git.Commands.Archive{verbose: true, worktree_attributes: true})
["archive", "-v", "--worktree-attributes", "HEAD"]

parse_output(stdout, exit_code)

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

Parses the output of git archive.

On success (exit code 0), returns {:ok, :done} since the archive content is written to the output file. On failure, returns {:error, {stdout, exit_code}}.