Class: Git::Commands::Archive Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/archive.rb,
lib/git/commands/archive/list_formats.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Note:

arguments block audited against https://git-scm.com/docs/git-archive/2.53.0

Archive creator for files from a named tree via git archive

Produces an archive of the specified format containing the tree structure for the named tree, and writes it to stdout (or to a file when out: or output: is given). If prefix: is specified it is prepended to the filenames in the archive.

Examples:

Archive HEAD as a tar stream to a file

cmd = Git::Commands::Archive.new(execution_context)
File.open('release.tar', 'wb') do |f|
  cmd.call('HEAD', format: 'tar', out: f)
end

Archive a tag with a prefix

cmd = Git::Commands::Archive.new(execution_context)
cmd.call('v1.0', format: 'zip', prefix: 'myproject-1.0/', output: 'release.zip')

Archive a subdirectory only

cmd = Git::Commands::Archive.new(execution_context)
cmd.call('HEAD', 'src/', format: 'tar', out: io)

See Also:

Defined Under Namespace

Classes: ListFormats

Instance Method Summary collapse

Methods inherited from Base

allow_exit_status, arguments, #initialize, requires_git_version, skip_version_validation

Constructor Details

This class inherits a constructor from Git::Commands::Base

Instance Method Details

#call(tree_ish = nil, *path, **options) ⇒ Git::CommandLineResult

Execute the git archive command.

Archive output is binary. On the capturing path (no out: option), normalize and chomp are disabled so stdout bytes are returned unchanged. When out: is given, the streaming path is used.

Parameters:

  • tree_ish (String, nil) (defaults to: nil)

    (nil) the tree or commit to produce an archive for; omit when using the :list option to enumerate available formats

  • path (Array<String>)

    paths within the tree to include in the archive

  • options (Hash)

    command options

Options Hash (**options):

  • :format (String) — default: nil

    archive format — tar, zip, tar.gz, tgz, or any format defined via tar.<format>.command

  • :list (Boolean, nil) — default: nil

    show all available archive formats

    Alias: :l

  • :verbose (Boolean, nil) — default: nil

    report progress to stderr

    Alias: :v

  • :prefix (String) — default: nil

    prepend <prefix>/ to each filename in the archive

  • :output (String) — default: nil

    write the archive to this file instead of stdout

    Alias: :o

  • :add_file (String, Array<String>) — default: nil

    add one or more non-tracked files to the archive; may be passed multiple times

  • :add_virtual_file (String, Array<String>) — default: nil

    add one or more virtual files by <path>:<content>; may be passed multiple times

  • :worktree_attributes (Boolean, nil) — default: nil

    look for attributes in .gitattributes files in the working tree as well

  • :mtime (String) — default: nil

    set modification time of archive entries

  • :remote (String) — default: nil

    retrieve a tar archive from a remote repository instead of the local one

  • :exec (String) — default: nil

    path to git-upload-archive on the remote side; used with :remote

  • :out (IO, #write) — default: nil

    stream archive output to this IO object instead of capturing it; the result's .stdout will be ''

Returns:

Raises:

  • (ArgumentError)

    if unsupported options are provided

  • (Git::FailedError)

    if git exits with a non-zero exit status



# File 'lib/git/commands/archive.rb', line 58

#chomp_captured_stdout?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Archive output is binary, so preserve captured stdout byte-for-byte even when it ends with a newline.

Returns:

  • (Boolean)

    false



137
# File 'lib/git/commands/archive.rb', line 137

def chomp_captured_stdout? = false

#normalize_captured_stdout?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Archive output is intrinsically binary (tar, zip, etc.) — opt out of Ruby string normalization and trailing-newline chomping so that result.stdout bytes are returned unchanged. Only affects the capturing path; streaming via out: is never normalized or chomped regardless of these settings.

Returns:

  • (Boolean)

    false



130
# File 'lib/git/commands/archive.rb', line 130

def normalize_captured_stdout? = false