Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/henson/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/henson/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}"
Expand Down
1 change: 1 addition & 0 deletions lib/henson/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 37 additions & 6 deletions lib/henson/source/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand All @@ -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
Expand Down Expand Up @@ -117,22 +133,23 @@ 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
end

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
end

private
def git *args
Henson.ui.debug "#{name}: git #{args.join(' ')}\n"
`git #{args.join(" ")}`
rescue Errno::ENOENT
raise GitNotInstalled if exit_status.nil?
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions lib/henson/source/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down