Class: R10K::Module::Git
- Includes:
- Util::Setopts
- Defined in:
- lib/r10k/module/git.rb
Constant Summary
Constants included from Logging
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.
- #version ⇒ Object
Methods included from Logging
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.
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 84 85 86 |
# File 'lib/r10k/module/git.rb', line 53 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_ref, :default_branch_override => :default_override_ref, }, :raise_on_unhandled => false) force = @overrides.dig(:modules, :force) @force = force == false ? false : true @desired_ref ||= 'master' 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.
49 50 51 |
# File 'lib/r10k/module/git.rb', line 49 def default_override_ref @default_override_ref end |
#default_ref ⇒ Object (readonly)
Returns the value of attribute default_ref.
44 45 46 |
# File 'lib/r10k/module/git.rb', line 44 def default_ref @default_ref end |
#desired_ref ⇒ Object (readonly)
Returns the value of attribute desired_ref.
39 40 41 |
# File 'lib/r10k/module/git.rb', line 39 def desired_ref @desired_ref end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
34 35 36 |
# File 'lib/r10k/module/git.rb', line 34 def repo @repo end |
Class Method Details
.implement?(name, args) ⇒ Boolean
10 11 12 13 14 |
# File 'lib/r10k/module/git.rb', line 10 def self.implement?(name, args) args.has_key?(:git) || args[:type].to_s == 'git' rescue false 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.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/r10k/module/git.rb', line 19 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
117 118 119 |
# File 'lib/r10k/module/git.rb', line 117 def cachedir @repo.cache.sanitized_dirname end |
#properties ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/r10k/module/git.rb', line 92 def properties { :expected => version, :actual => (@repo.head || "(unresolvable)"), :type => :git, } end |
#status ⇒ Object
113 114 115 |
# File 'lib/r10k/module/git.rb', line 113 def status @repo.status(version) end |
#sync(opts = {}) ⇒ Boolean
Returns true if the module was updated, false otherwise.
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/r10k/module/git.rb', line 102 def sync(opts={}) force = opts[:force] || @force if should_sync? updated = @repo.sync(version, force) else updated = false end maybe_delete_spec_dir updated end |
#version ⇒ Object
88 89 90 |
# File 'lib/r10k/module/git.rb', line 88 def version validate_ref(@desired_ref, @default_ref, @default_override_ref) end |