Module: Git::Helpers::Utils
- Defined in:
- lib/git/helpers/utils.rb
Overview
Provides utility methods for other Git-Helper modules
Class Method Summary collapse
-
.remote?(repo, remote) ⇒ Boolean
Checks if the given remote exists on the given repo.
-
.remotes_hash(repo) ⇒ Hash{String => Git::Remote}
Get a hash of remotes keyed to their name.
-
.split_remote_string(str) ⇒ Array<String>
Splits a remote/branch string into its component parts.
-
.transform_url(url, scheme = 'https') ⇒ String
Takes a url from a git remote and transforms it into an normal url with the desired scheme.
-
.true_name(remote) ⇒ String
Gets the true name for a remote.
Class Method Details
.remote?(repo, remote) ⇒ Boolean
Checks if the given remote exists on the given repo
10 11 12 |
# File 'lib/git/helpers/utils.rb', line 10 def self.remote?(repo, remote) repo.remotes.map(&:name).include?(remote) end |
.remotes_hash(repo) ⇒ Hash{String => Git::Remote}
Get a hash of remotes keyed to their name
17 18 19 |
# File 'lib/git/helpers/utils.rb', line 17 def self.remotes_hash(repo) Hash[repo.remotes.map { |r| [r.name, r] }] end |
.split_remote_string(str) ⇒ Array<String>
Splits a remote/branch string into its component parts
40 41 42 43 44 45 46 47 |
# File 'lib/git/helpers/utils.rb', line 40 def self.split_remote_string(str) first_slash = str.index('/') if first_slash.nil? return str, nil else return str[0..first_slash-1], str[first_slash+1..-1] end end |
.transform_url(url, scheme = 'https') ⇒ String
Takes a url from a git remote and transforms it into an normal url with
the desired scheme
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/git/helpers/utils.rb', line 26 def self.transform_url(url, scheme = 'https') # if git ssh url if /^git@/ === url url.gsub(/^git@(.*):/, scheme + '://\1/') elsif %r{^git://} === url url.gsub(/^git/, scheme) else url end end |
.true_name(remote) ⇒ String
Gets the true name for a remote
52 53 54 55 |
# File 'lib/git/helpers/utils.rb', line 52 def self.true_name(remote) transform_url(remote.url) =~ %r{^https://.*?/(.*?)/.*$} Regexp.last_match 1 end |