0.04
No release in over 3 years
Low commit activity in last 3 years
This supports https protocol, git protocol and ssh protocol.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

GitCloneUrl

Gem version CI Status yard docs

Easy to parse git repository-ish url.

  • Parse by URI.parse
    • git://github.com/schacon/ticgit.git
    • https://github.com/schacon/ticgit.git
  • Parse by URI::SshGit
    • git@github.com:schacon/ticgit.git
require 'git_clone_url'

git_url = 'git://github.com/schacon/ticgit.git'
ssh_url = 'git@github.com:schacon/ticgit.git'
https_url = 'https://github.com/schacon/ticgit.git'
https_url_with_userinfo = 'https://user:pass@github.com/schacon/ticgit.git'

GitCloneUrl.parse(git_url)
#=> #<URI::Generic git://github.com/schacon/ticgit.git>
#=> {scheme: 'git', host: 'github.com', path: '/schacon/ticgit.git' }
GitCloneUrl.parse(ssh_url)
#=> #<URI::SshGit::Generic git@github.com:schacon/ticgit.git>
#=> {scheme: nil, user: 'git', userinfo: 'git', host: 'github.com', path: 'schacon/ticgit.git' }
GitCloneUrl.parse(https_url)
#=> #<URI::HTTPS https://github.com/schacon/ticgit.git>
#=> {scheme: 'https', host: 'github.com', path: '/schacon/ticgit.git'}
GitCloneUrl.parse(https_url_with_userinfo)
#=> #<URI::HTTPS https://user:pass@github.com/schacon/ticgit.git>
#=> {scheme: 'https', userinfo: 'user:pass', user: 'user', password: 'pass',
# host: 'github.com', path: '/schacon/ticgit.git'}

Motivation

URI.parse and Addressable::URI.parse can parse https protocol, git protocol and ssh protocol(ssh://git@github.com...), but they can not parse git@github.com:foo/bar.git pattern of ssh protocol.

# URI
url = URI.parse('git@github.com:schacon/ticgit.git')
URI::InvalidURIError: bad URI(is not URI?): git@github.com:schacon/ticgit.git

# Addressable
url = Addressable::URI.parse('git@github.com:schacon/ticgit.git')
#=> #<Addressable::URI:0x3fedf48fb430 URI:git@github.com:schacon/ticgit.git>
url.path #=> "schacon/ticgit.git"
url.scheme #=> "git@github.com"

url.host #=> nil
url.userinfo #=> nil
url.user #=> nil
url.port #=> nil

API

GitCloneUrl.parse(git_url) -> URI::*

Return URI namespaced object. E.g. URI::Generic, URI::HTTPS and URI::SshGit::Generic. See: class URI::Generic, class URI::HTTPS and URI::SshGit.

git_url

Required Type: string

Git repository-ish url.

details.

Installation

Add this line to your application's Gemfile:

gem 'git_clone_url'

And then execute:

$ bundle

Or install it yourself as:

$ gem install git_clone_url

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release to create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

  1. Fork it ( https://github.com/packsaddle/ruby-git_clone_url/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request