Method: Git::Lib#clone

Defined in:
lib/git/lib.rb

#clone(repository_url, directory, opts = {}) ⇒ Hash

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.

TODO:

make this work with SSH password or auth_key

Clones a repository into a newly created directory

Parameters:

  • repository_url (String)

    the URL of the repository to clone

  • directory (String, nil)

    the directory to clone into

    If nil, the repository is cloned into a directory with the same name as the repository.

  • opts (Hash) (defaults to: {})

    the options for this command

Options Hash (opts):

  • :bare (Boolean) — default: false

    if true, clone as a bare repository

  • :branch (String)

    the branch to checkout

  • :config (String, Array)

    one or more configuration options to set

  • :depth (Integer)

    the number of commits back to pull

  • :filter (String)

    specify partial clone

  • :mirror (String)

    set up a mirror of the source repository

  • :origin (String)

    the name of the remote

  • :path (String)

    an optional prefix for the directory parameter

  • :remote (String)

    the name of the remote

  • :recursive (Boolean)

    after the clone is created, initialize all within, using their default settings

  • :timeout (Numeric, nil)

    the number of seconds to wait for the command to complete

    See #command for more information about :timeout

Returns:

  • (Hash)

    the options to pass to Base.new



166
167
168
169
170
171
172
173
174
175
176
# File 'lib/git/lib.rb', line 166

def clone(repository_url, directory, opts = {})
  @path = opts[:path] || '.'
  clone_dir = opts[:path] ? File.join(@path, directory) : directory

  args = build_args(opts, CLONE_OPTION_MAP)
  args.push('--', repository_url, clone_dir)

  command('clone', *args, timeout: opts[:timeout])

  return_base_opts_from_clone(clone_dir, opts)
end