Module: R10K::Git

Extended by:
Logging, Settings::Mixin::ClassMethods
Defined in:
lib/r10k/git.rb,
lib/r10k/git/errors.rb,
lib/r10k/git/rugged.rb,
lib/r10k/git/shellgit.rb

Defined Under Namespace

Modules: Rugged, ShellGit Classes: Alternates, Cache, GitError, StatefulRepository, UnresolvableRefError

Constant Summary collapse

NULL_PROVIDER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

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.

Object.new
UNSET_PROVIDER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

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.

Object.new

Constants included from Logging

Logging::LOG_LEVELS

Class Method Summary collapse

Methods included from Logging

debug_formatter, default_formatter, default_outputter, logger, logger_name, parse_level

Methods included from Settings::Mixin::ClassMethods

def_setting_attr, defaults, inherited, settings

Class Method Details

.bare_repositoryObject



117
118
119
# File 'lib/r10k/git.rb', line 117

def self.bare_repository
  provider::BareRepository
end

.cacheObject



113
114
115
# File 'lib/r10k/git.rb', line 113

def self.cache
  provider::Cache
end

.default_nameString

Return the first available Git provider.

Returns:

  • (String)

    The name of the first available Git implementation.

Raises:

  • (R10K::Error)

    if no Git providers are functional.



65
66
67
68
69
70
71
# 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

.get_proxy_for_remote(remote) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/r10k/git.rb', line 149

def self.get_proxy_for_remote(remote)
  # We only support proxy for HTTP(S) transport
  return nil unless remote =~ /^http(s)?/i

  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

.get_repo_settings(remote) ⇒ Object



145
146
147
# File 'lib/r10k/git.rb', line 145

def self.get_repo_settings(remote)
  self.settings[:repositories].find {|r| r[:remote] == remote }
end

.log_proxy_for_remote(proxy, remote) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
# File 'lib/r10k/git.rb', line 166

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

.providerModule

Returns The namespace of the first available Git implementation. Implementation classes should be looked up against this returned Module.

Returns:

  • (Module)

    The namespace of the first available Git implementation. Implementation classes should be looked up against this returned Module.



101
102
103
104
105
106
107
108
109
110
111
# 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

.provider=(name) ⇒ void

This method returns an undefined value.

Manually set the Git provider by name.

Parameters:

  • name (Symbol)

    The name of the Git provider to use.

Raises:

  • (R10K::Error)

    if the requested Git provider doesn’t exist.

  • (R10K::Error)

    if the requested Git provider isn’t functional.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# 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

.reset!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Clear the currently set provider.



128
129
130
# File 'lib/r10k/git.rb', line 128

def self.reset!
  @provider = UNSET_PROVIDER
end

.thin_repositoryObject



121
122
123
# File 'lib/r10k/git.rb', line 121

def self.thin_repository
  provider::ThinRepository
end

.with_proxy(new_proxy) ⇒ Object

Execute block with given proxy configured in ENV



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/r10k/git.rb', line 179

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