lib/berkshelf/locations/mercurial_location.rb in berkshelf-3.0.0.beta4 vs lib/berkshelf/locations/mercurial_location.rb in berkshelf-3.0.0.beta5
- old
+ new
@@ -1,8 +1,7 @@
module Berkshelf
class MercurialLocation < Location::ScmLocation
-
set_location_key :hg
set_valid_options :rev, :branch, :tag, :rel
attr_accessor :uri
attr_accessor :rel
@@ -41,14 +40,16 @@
if cached?(destination)
@rev ||= Berkshelf::Mercurial.rev_parse(revision_path(destination))
return local_revision(destination)
end
- Berkshelf::Mercurial.checkout(clone, rev || branch || tag) if rev || branch || tag
- @rev = Berkshelf::Mercurial.rev_parse(clone)
+ repo_path = Berkshelf::Mercurial.clone(uri)
- tmp_path = rel ? File.join(clone, rel) : clone
+ Berkshelf::Mercurial.checkout(repo_path, rev || branch || tag) if rev || branch || tag
+ @rev = Berkshelf::Mercurial.rev_parse(repo_path)
+
+ tmp_path = rel ? File.join(repo_path, rel) : repo_path
unless File.chef_cookbook?(tmp_path)
msg = "Cookbook '#{dependency.name}' not found at hg: #{uri}"
msg << " with rev '#{rev}'" if rev
msg << " at path '#{rel}'" if rel
raise CookbookNotFound, msg
@@ -76,23 +77,9 @@
s << " at rev: '#{rev}'" if rev
s
end
private
-
- def hg
- @hg ||= Berkshelf::Mercurial.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::Mercurial.clone(uri, tmp_clone)
- end
-
- tmp_clone
- end
def cached?(destination)
revision_path(destination) && File.exists?(revision_path(destination))
end