lib/berkshelf/locations/git_location.rb in berkshelf-1.4.6 vs lib/berkshelf/locations/git_location.rb in berkshelf-2.0.0.beta

- old
+ new

@@ -18,14 +18,13 @@ set_valid_options :ref, :branch, :tag, :rel attr_accessor :uri attr_accessor :branch attr_accessor :rel - attr_accessor :branch_name + attr_accessor :ref attr_reader :options - alias_method :ref, :branch alias_method :tag, :branch # @param [#to_s] name # @param [Solve::Constraint] version_constraint # @param [Hash] options @@ -42,37 +41,39 @@ # the path within the repository to find the cookbook def initialize(name, version_constraint, options = {}) @name = name @version_constraint = version_constraint @uri = options[:git] - @branch = options[:branch] || options[:ref] || options[:tag] || "master" + @branch = options[:branch] || options[:tag] || 'master' + @ref = options[:ref] @rel = options[:rel] - @branch_name = @branch.gsub("-", "_").gsub("/", "__") # In case the remote is specified Git.validate_uri!(@uri) end # @param [#to_s] destination # # @return [Berkshelf::CachedCookbook] def download(destination) - return local_revision(destination) if cached?(destination) - - ::Berkshelf::Git.checkout(clone, branch) if branch - unless branch - self.branch = ::Berkshelf::Git.rev_parse(clone) + if cached?(destination) + @ref = Berkshelf::Git.rev_parse(revision_path(destination)) + return local_revision(destination) end + Berkshelf::Git.checkout(clone, ref || branch) if ref || branch + @ref = Berkshelf::Git.rev_parse(clone) + tmp_path = rel ? File.join(clone, rel) : clone unless File.chef_cookbook?(tmp_path) msg = "Cookbook '#{name}' not found at git: #{uri}" msg << " with branch '#{branch}'" if branch + msg << " with ref '#{ref}'" if ref msg << " at path '#{rel}'" if rel raise CookbookNotFound, msg end - cb_path = File.join(destination, "#{name}-#{branch_name}") + cb_path = File.join(destination, "#{name}-#{ref}") FileUtils.rm_rf(cb_path) FileUtils.mv(tmp_path, cb_path) cached = CachedCookbook.from_store_path(cb_path) validate_cached(cached) @@ -89,10 +90,11 @@ end def to_s s = "#{self.class.location_key}: '#{uri}'" s << " with branch: '#{branch}'" if branch + s << " at ref: '#{ref}'" if ref s end private @@ -120,10 +122,10 @@ validate_cached(cached) return cached end def revision_path(destination) - return unless branch - File.join(destination, "#{name}-#{branch_name}") + return unless ref + File.join(destination, "#{name}-#{ref}") end end end