class R10K::Source::Git
This class implements a source for Git environments.
A Git source generates environments by locally caching the given Git repository and enumerating the branches for the Git repository. Branches are mapped to environments without modification.
@since 1.3.0
Attributes
@!attribute [r] cache
@api private @return [R10K::Git::Cache] The git cache associated with this source
@!attribute [r] #invalid_branches
@return [String] How Git branch names that cannot be cleanly mapped to Puppet environments will be handled.
@!attribute [r] remote
@return [String] The URL to the remote git repository
@!attribute [r] settings
@return [Hash<Symbol, Object>] Additional settings that configure how the source should behave.
Public Class Methods
Initialize the given source.
@param name [String] The identifier for this source. @param basedir [String] The base directory where the generated environments will be created. @param options [Hash] An additional set of options for this source.
@option options [Boolean, String] :prefix If a String this becomes the prefix.
If true, will use the source name as the prefix. Defaults to false for no environment prefix.
@option options [String] :remote The URL to the base directory of the SVN repository @option options [Hash] :remote Additional settings that configure how the
source should behave.
# File lib/r10k/source/git.rb, line 51 def initialize(name, basedir, options = {}) super @environments = [] @remote = options[:remote] @invalid_branches = (options[:invalid_branches] || 'correct_and_warn') @cache = R10K::Git.cache.generate(@remote) end
Public Instance Methods
List all environments that should exist in the basedir for this source @note This is required by {R10K::Util::Basedir} @return [Array<String>]
# File lib/r10k/source/git.rb, line 108 def desired_contents environments.map {|env| env.dirname } end
Load the git remote and create environments for each branch. If the cache has not been fetched, this will return an empty list.
@return [Array<R10K::Environment::Git>]
# File lib/r10k/source/git.rb, line 77 def environments if not @cache.cached? [] elsif @environments.empty? @environments = generate_environments() else @environments end end
# File lib/r10k/source/git.rb, line 87 def generate_environments envs = [] branch_names.each do |bn| if bn.valid? envs << R10K::Environment::Git.new(bn.name, @basedir, bn.dirname, {:remote => remote, :ref => bn.name}) elsif bn.correct? logger.warn "Environment #{bn.name.inspect} contained non-word characters, correcting name to #{bn.dirname}" envs << R10K::Environment::Git.new(bn.name, @basedir, bn.dirname, {:remote => remote, :ref => bn.name}) elsif bn.validate? logger.error "Environment #{bn.name.inspect} contained non-word characters, ignoring it." end end envs end
Update the git cache for this git source to get the latest list of environments.
@return [void]
# File lib/r10k/source/git.rb, line 65 def preload! logger.debug "Fetching '#{@remote}' to determine current branches." @cache.sync rescue => e raise R10K::Error.wrap(e, "Unable to determine current branches for Git source '#{@name}' (#{@basedir})") end
Private Instance Methods
# File lib/r10k/source/git.rb, line 114 def branch_names opts = {:prefix => @prefix, :invalid => @invalid_branches, :source => @name} @cache.branches.map do |branch| R10K::Environment::Name.new(branch, opts) end end