Mark the current provider as invalid.
If a provider is set to an invalid provider, we need to make sure that the provider doesn't fall back to the default value, thereby ignoring the explicit value and silently continuing. If the current provider is assigned to this value, no provider will be used until the provider is either reset or assigned a valid provider.
@api private
Mark the current provider as unset.
If the provider has never been set we need to indicate that there is no current value but the default value can be used. If the current provider is assigned to this value and the provider is looked up, the default provider will be looked up and used.
@api private
# File lib/r10k/git.rb, line 117 def self.bare_repository provider::BareRepository end
# File lib/r10k/git.rb, line 113 def self.cache provider::Cache end
Return the first available Git provider.
@raise [R10K::Error] if no Git providers are functional. @return [String] The name of the first available Git implementation.
# File lib/r10k/git.rb, line 65 def self.default_name name, _ = @providers.find { |(_, hash)| R10K::Features.available?(hash[:feature]) } if name.nil? raise R10K::Error, _("No Git providers are functional.") end name end
# File lib/r10k/git.rb, line 145 def self.get_proxy_for_remote(remote) # We only support proxy for HTTP(S) transport return nil unless remote =~ /^http(s)?/ repo_settings = self.get_repo_settings(remote) if repo_settings && repo_settings.has_key?(:proxy) proxy = repo_settings[:proxy] unless repo_settings[:proxy].nil? || repo_settings[:proxy].empty? else proxy = self.settings[:proxy] end R10K::Git.log_proxy_for_remote(proxy, remote) if proxy proxy end
# File lib/r10k/git.rb, line 141 def self.get_repo_settings(remote) self.settings[:repositories].find {|r| r[:remote] == remote } end
# File lib/r10k/git.rb, line 162 def self.log_proxy_for_remote(proxy, remote) # Sanitize passwords out of the proxy URI for loggging. proxy_uri = URI.parse(proxy) proxy_str = "#{proxy_uri.scheme}://" proxy_str << "#{proxy_uri.userinfo.gsub(/:(.*)$/, ':<FILTERED>')}@" if proxy_uri.userinfo proxy_str << "#{proxy_uri.host}:#{proxy_uri.port}" logger.debug { "Using HTTP proxy '#{proxy_str}' for '#{remote}'." } nil end
@return [Module] The namespace of the first available Git implementation.
Implementation classes should be looked up against this returned Module.
# File lib/r10k/git.rb, line 101 def self.provider case @provider when NULL_PROVIDER raise R10K::Error, _("No Git provider set.") when UNSET_PROVIDER self.provider = default_name logger.debug1 { _("Setting Git provider to default provider %{name}") % {name: default_name} } end @provider end
Manually set the Git provider by name.
@param name [Symbol] The name of the Git provider to use. @raise [R10K::Error] if the requested Git provider doesn't exist. @raise [R10K::Error] if the requested Git provider isn't functional. @return [void]
# File lib/r10k/git.rb, line 81 def self.provider=(name) _, attrs = @providers.find { |(providername, _)| name == providername } if attrs.nil? @provider = NULL_PROVIDER raise R10K::Error, _("No Git provider named '%{name}'.") % {name: name} end if !R10K::Features.available?(attrs[:feature]) @provider = NULL_PROVIDER raise R10K::Error, _("Git provider '%{name}' is not functional.") % {name: name} end if attrs[:on_set] attrs[:on_set].call end @provider = attrs[:module] logger.debug1 { _("Setting Git provider to %{provider}") % {provider: @provider.name} } end
Clear the currently set provider.
@api private
# File lib/r10k/git.rb, line 128 def self.reset! @provider = UNSET_PROVIDER end
# File lib/r10k/git.rb, line 121 def self.thin_repository provider::ThinRepository end
Execute block with given proxy configured in ENV
# File lib/r10k/git.rb, line 175 def self.with_proxy(new_proxy) unless new_proxy.nil? old_proxy = Hash[ ['HTTPS_PROXY', 'HTTP_PROXY', 'https_proxy', 'http_proxy'].collect do |var| old_value = ENV[var] ENV[var] = new_proxy [var, old_value] end ] end begin yield ensure ENV.update(old_proxy) if old_proxy end nil end