Method: Git::URL.clone_to

Defined in:
lib/git/url.rb

.clone_to(url, bare: false, mirror: false) ⇒ String

The directory git clone would use for the repository directory for the given URL

Examples:

Git::URL.clone_to('https://github.com/ruby-git/ruby-git.git') #=> 'ruby-git'

Parameters:

  • url (String)

    the Git URL containing the repository directory

Returns:

  • (String)

    the name of the repository directory



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/git/url.rb', line 64

def self.clone_to(url, bare: false, mirror: false)
  uri = parse(url)
  path_parts = uri.path.split('/')
  path_parts.pop if path_parts.last == '.git'
  directory = path_parts.last
  if bare || mirror
    directory += '.git' unless directory.end_with?('.git')
  elsif directory.end_with?('.git')
    directory = directory[0..-5]
  end
  directory
end