Method: Git::URL.parse

Defined in:
lib/git/url.rb

.parse(url) ⇒ Addressable::URI

Parse a Git URL and return an Addressable::URI object

The URI returned can be converted back to a string with 'to_s'. This is guaranteed to return the same URL string that was parsed.

Examples:

uri = Git::URL.parse('https://github.com/ruby-git/ruby-git.git')
  #=> #<Addressable::URI:0x44c URI:https://github.com/ruby-git/ruby-git.git>
uri.scheme #=> "https"
uri.host #=> "github.com"
uri.path #=> "/ruby-git/ruby-git.git"

Git::URL.parse('/Users/James/projects/ruby-git')
  #=> #<Addressable::URI:0x438 URI:/Users/James/projects/ruby-git>

Parameters:

  • url (String)

    the Git URL to parse

Returns:

  • (Addressable::URI)

    the parsed URI



47
48
49
50
51
52
53
# File 'lib/git/url.rb', line 47

def self.parse(url)
  if !url.start_with?('file:') && (m = GIT_ALTERNATIVE_SSH_SYNTAX.match(url))
    GitAltURI.new(user: m[:user], host: m[:host], path: m[:path])
  else
    Addressable::URI.parse(url)
  end
end