lib/berkshelf/locations/git_location.rb in berkshelf-3.0.0.beta3 vs lib/berkshelf/locations/git_location.rb in berkshelf-3.0.0.beta4
- old
+ new
@@ -26,17 +26,27 @@
# @option options [String] :rel
# the path within the repository to find the cookbook
def initialize(dependency, options = {})
super
@uri = options[:git]
- @branch = options[:branch] || options[:tag] || 'master'
@ref = options[:ref]
+ @branch = options[:branch] || options[:tag] || "master" unless ref
+ @sha = ref
@rel = options[:rel]
Git.validate_uri!(@uri)
end
+ def checkout_info
+ if @sha
+ kind, rev = "ref", @sha
+ else
+ kind, rev = "branch", branch
+ end
+ { :kind => kind, :rev => rev }
+ end
+
# @param [#to_s] destination
#
# @return [Berkshelf::CachedCookbook]
def do_download
destination = Berkshelf::CookbookStore.instance.storage_path
@@ -44,18 +54,16 @@
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
+ Berkshelf::Git.checkout(clone, ref || checkout_info[:rev])
@ref = Berkshelf::Git.rev_parse(clone)
tmp_path = rel ? File.join(clone, rel) : clone
unless File.chef_cookbook?(tmp_path)
- msg = "Cookbook '#{dependency.name}' not found at git: #{uri}"
- msg << " with branch '#{branch}'" if branch
- msg << " with ref '#{ref}'" if ref
+ msg = "Cookbook '#{dependency.name}' not found at git: #{to_display}"
msg << " at path '#{rel}'" if rel
raise CookbookNotFound, msg
end
cb_path = revision_path(destination)
@@ -74,24 +82,28 @@
h[:branch] = self.branch if branch
end
end
def to_s
- s = "#{self.class.location_key}: '#{uri}'"
- s << " with branch: '#{branch}'" if branch
- s << " at ref: '#{ref}'" if ref
- s
+ "#{self.class.location_key}: #{to_display}"
end
private
+ def to_display
+ info = checkout_info
+ s = "'#{uri}' with #{info[:kind]}: '#{info[:rev]}'"
+ s << " at ref: '#{ref}'" if ref && (info[:kind] != "ref" || ref != info[:rev])
+ s
+ end
+
def git
@git ||= Berkshelf::Git.new(uri)
end
def clone
tmp_clone = File.join(self.class.tmpdir, uri.gsub(/[\/:]/,'-'))
-
+ FileUtils.mkdir_p(File.join(File.split(tmp_clone).shift))
unless File.exists?(tmp_clone)
Berkshelf::Git.clone(uri, tmp_clone)
end
tmp_clone