diff --git a/lib/henson/cli.rb b/lib/henson/cli.rb index e9f1f65..e8fc4e5 100644 --- a/lib/henson/cli.rb +++ b/lib/henson/cli.rb @@ -31,6 +31,8 @@ def initialize(*) "Only output warnings and errors." method_option "debug", :type => :boolean, :banner => "Turn on verbose output." + method_option "no-symlink", :type => :boolean, :banner => + "Copy shared modules instead of symlink" method_option "local", :type => :boolean, :banner => "Only check local cache source for modules." method_option "no-cache", :type => :boolean, :banner => @@ -45,6 +47,7 @@ def install Installer.clean! if options[:clean] Henson.settings[:path] = options[:path] if options[:path] + Henson.settings[:symlink] = false if options[:"no-symlink"] Installer.install! end diff --git a/lib/henson/installer.rb b/lib/henson/installer.rb index f62df61..101ae04 100644 --- a/lib/henson/installer.rb +++ b/lib/henson/installer.rb @@ -44,9 +44,10 @@ def self.evaluate_puppetfile! file # mod - The PuppetModule to fetch. def self.fetch_module! mod if mod.needs_fetching? + Henson.ui.info "#{mod.name} is being updated" mod.fetch! else - Henson.ui.debug "#{mod} does not need fetching" + Henson.ui.debug "#{mod} #{mod.name} does not need fetching" end end @@ -55,6 +56,7 @@ def self.fetch_module! mod # mod - The PuppetModule to install. def self.install_module! mod if mod.needs_installing? + Henson.ui.info "#{mod.name} is being installed" mod.install! else install_path = "#{Henson.settings[:path]}/#{mod.name}" diff --git a/lib/henson/settings.rb b/lib/henson/settings.rb index bfa74cb..53ede1a 100644 --- a/lib/henson/settings.rb +++ b/lib/henson/settings.rb @@ -4,6 +4,7 @@ def initialize options = {} self.merge!( :quiet => false, :verbose => false, + :symlink => true, :puppetfile => "#{Dir.pwd}/Puppetfile", :path => "#{Dir.pwd}/shared", :cache_path => "#{Dir.pwd}/.henson/cache", diff --git a/lib/henson/source/git.rb b/lib/henson/source/git.rb index ee7c653..c8c4b27 100644 --- a/lib/henson/source/git.rb +++ b/lib/henson/source/git.rb @@ -18,7 +18,7 @@ def == other end end - attr_reader :name, :repo, :options + attr_reader :name, :repo, :options, :target_revision_without_origin def initialize name, repo, opts = {} @name = name @@ -50,16 +50,19 @@ def initialize name, repo, opts = {} @target_revision = "origin/master" @ref_type = :branch end + @target_revision_without_origin = @target_revision.to_s.gsub(/origin\//,'') end def fetched? - File.directory? fetch_path + return false unless File.directory? fetch_path + return false unless resolved_target_revision_fetched? + commit_id_fetched? remote_commit_id end def fetch! if File.directory? fetch_path in_repo do - git "fetch", "--force", "--quiet", "--tags", "origin", "'refs/heads/*:refs/heads/*'" + git "fetch", "--force", "--quiet", "--tags", "origin", "'refs/heads/*:refs/remotes/origin/*'" end else Henson.ui.debug "Fetching #{name} from #{repo}" @@ -80,7 +83,20 @@ def install! end def installed? - current_revision == resolved_target_revision + return false unless current_revision == resolved_target_revision + remote_commit_id == local_commit_id + end + + def remote_commit_id + @remote_commit_id ||= in_repo do + Revision.new(git(%W(ls-remote --exit-code origin #{target_revision_without_origin})).split(/\s+/)[0]) + end + end + + def local_commit_id + in_repo do + Revision.new(git(%W(ls-remote --exit-code . #{target_revision_without_origin})).split(/\s+/)[0]) + end end def versions @@ -117,7 +133,7 @@ def satisfiable_versions_for_requirement requirement fetch! unless fetched? if @ref_type == :tag || @ref_type == :branch - versions.select { |v| v =~ Regexp.new(target_revision.gsub(/^origin\//, "")) } + versions.select { |v| v =~ Regexp.new(target_revision_without_origin) } else versions.map { |v| v.gsub(/^origin\//, "") } end @@ -125,7 +141,7 @@ def satisfiable_versions_for_requirement requirement def satisfies? requirement if @ref_type == :tag || @ref_type == :branch - versions.member? target_revision.gsub(/^origin\//, "").to_s + versions.member? target_revision_without_origin.to_s else versions.member? resolved_target_revision.to_s end @@ -133,6 +149,7 @@ def satisfies? requirement private def git *args + Henson.ui.debug "#{name}: git #{args.join(' ')}\n" `git #{args.join(" ")}` rescue Errno::ENOENT raise GitNotInstalled if exit_status.nil? @@ -170,6 +187,20 @@ def target_revision @target_revision end + def commit_id_fetched? commit_id + in_repo do + git("rev-parse", '--verify', '-q', "#{commit_id}") + $?.success? + end + end + + def resolved_target_revision_fetched? + in_repo do + git("rev-parse", '--verify', '-q', "#{target_revision}^{commit}") + $?.success? + end + end + def resolved_target_revision in_repo do Revision.new(git("rev-parse", "#{target_revision}^{commit}").strip) diff --git a/lib/henson/source/path.rb b/lib/henson/source/path.rb index 9b7eb49..3078516 100644 --- a/lib/henson/source/path.rb +++ b/lib/henson/source/path.rb @@ -21,8 +21,14 @@ def fetch! end def install! - Henson.ui.debug "Symlinking #{path} to #{install_path}" - FileUtils.ln_sf path, install_path.to_path + if Henson.settings[:symlink] + Henson.ui.debug "Symlinking #{path} to #{install_path}" + FileUtils.ln_sf path, install_path.to_path + else + Henson.ui.debug "Installing #{name} from #{path} into #{Henson.settings[:path]}..." + Henson.ui.info "Installing #{name} from #{path}..." + FileUtils.cp_r path, Henson.settings[:path] + end end def versions