Class: R10K::Module::Git
- Includes:
- Util::Setopts
- Defined in:
- lib/r10k/module/git.rb
Constant Summary
Constants included from Logging
Logging::LOG_LEVELS, Logging::SYSLOG_LEVELS_MAP
Instance Attribute Summary collapse
-
#default_override_ref ⇒ Object
readonly
Returns the value of attribute default_override_ref.
-
#default_ref ⇒ Object
readonly
Returns the value of attribute default_ref.
-
#desired_ref ⇒ Object
readonly
Returns the value of attribute desired_ref.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Attributes inherited from Base
#dirname, #environment, #name, #origin, #owner, #path, #spec_deletable, #title
Class Method Summary collapse
- .implement?(name, args) ⇒ Boolean
-
.statically_defined_version(name, args) ⇒ Object
Will be called if self.implement? above returns true.
Instance Method Summary collapse
- #cachedir ⇒ Object
-
#initialize(title, dirname, opts, environment = nil) ⇒ Git
constructor
A new instance of Git.
- #properties ⇒ Object
- #status ⇒ Object
-
#sync(opts = {}) ⇒ Boolean
True if the module was updated, false otherwise.
- #validate_ref_defined ⇒ Object
- #version ⇒ Object
Methods included from Logging
add_outputters, debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level
Methods inherited from Base
#accept, #delete_spec_dir, #full_path, #maybe_delete_spec_dir, #should_sync?
Constructor Details
#initialize(title, dirname, opts, environment = nil) ⇒ Git
Returns a new instance of Git.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/r10k/module/git.rb', line 51 def initialize(title, dirname, opts, environment=nil) super setopts(opts, { # Standard option interface :version => :desired_ref, :source => :remote, :type => ::R10K::Util::Setopts::Ignore, # Type-specific options :branch => :desired_ref, :tag => :desired_ref, :commit => :desired_ref, :ref => :desired_ref, :git => :remote, :default_branch => :default_branch, :default_branch_override => :default_override_ref, }, :raise_on_unhandled => false) @default_ref = @default_branch.nil? ? @overrides.dig(:modules, :default_ref) : @default_branch force = @overrides[:force] @force = force == false ? false : true if @desired_ref == :control_branch if @environment && @environment.respond_to?(:ref) @desired_ref = @environment.ref else logger.warn _("Cannot track control repo branch for content '%{name}' when not part of a git-backed environment, will use default if available." % {name: name}) end end @repo = R10K::Git::StatefulRepository.new(@remote, @dirname, @name) end |
Instance Attribute Details
#default_override_ref ⇒ Object (readonly)
Returns the value of attribute default_override_ref.
47 48 49 |
# File 'lib/r10k/module/git.rb', line 47 def default_override_ref @default_override_ref end |
#default_ref ⇒ Object (readonly)
Returns the value of attribute default_ref.
42 43 44 |
# File 'lib/r10k/module/git.rb', line 42 def default_ref @default_ref end |
#desired_ref ⇒ Object (readonly)
Returns the value of attribute desired_ref.
37 38 39 |
# File 'lib/r10k/module/git.rb', line 37 def desired_ref @desired_ref end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
32 33 34 |
# File 'lib/r10k/module/git.rb', line 32 def repo @repo end |
Class Method Details
.implement?(name, args) ⇒ Boolean
10 11 12 |
# File 'lib/r10k/module/git.rb', line 10 def self.implement?(name, args) args.has_key?(:git) || args[:type].to_s == 'git' end |
.statically_defined_version(name, args) ⇒ Object
Will be called if self.implement? above returns true. Will return the version info, if version is statically defined in the modules declaration.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/r10k/module/git.rb', line 17 def self.statically_defined_version(name, args) if !args[:type] && (args[:ref] || args[:tag] || args[:commit]) if args[:ref] && args[:ref].to_s.match(/[0-9a-f]{40}/) args[:ref] else args[:tag] || args[:commit] end elsif args[:type].to_s == 'git' && args[:version] && args[:version].to_s.match(/[0-9a-f]{40}/) args[:version] end end |
Instance Method Details
#cachedir ⇒ Object
114 115 116 |
# File 'lib/r10k/module/git.rb', line 114 def cachedir @repo.cache.sanitized_dirname end |
#properties ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/r10k/module/git.rb', line 89 def properties { :expected => version, :actual => (@repo.head || "(unresolvable)"), :type => :git, } end |
#status ⇒ Object
110 111 112 |
# File 'lib/r10k/module/git.rb', line 110 def status @repo.status(version) end |
#sync(opts = {}) ⇒ Boolean
Returns true if the module was updated, false otherwise.
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/r10k/module/git.rb', line 99 def sync(opts={}) force = opts[:force] || @force if should_sync? updated = @repo.sync(version, force, @exclude_spec) else updated = false end maybe_delete_spec_dir updated end |
#validate_ref_defined ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/r10k/module/git.rb', line 118 def validate_ref_defined if @desired_ref.nil? && @default_ref.nil? && @default_override_ref.nil? msg = "No ref defined for module #{@name}. Add a ref to the module definition " msg << "or set git:default_ref in the r10k.yaml config to configure a global default ref." raise ArgumentError, msg end end |
#version ⇒ Object
85 86 87 |
# File 'lib/r10k/module/git.rb', line 85 def version validate_ref(@desired_ref, @default_ref, @default_override_ref) end |