Fix git vcsrepo support.

ensure => latest should work and trigger when the remote has new
revs, and not at other times. It will handle tags and branches apparently
and will also handle not specifying a branch in the revision.
This commit is contained in:
Monty Taylor 2012-08-12 00:46:58 -04:00
parent 224e2ce3d5
commit 44eb9ad8f7
2 changed files with 37 additions and 44 deletions

View File

@ -33,49 +33,49 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
end end
def latest? def latest?
at_path do #notice "in latest?"
return self.revision == self.latest update_references
end return self.head_revision == self.latest
#notice "end of latest?"
end end
def latest def latest
branch = on_branch? #notice "In Latest"
if branch == 'master' if @resource.value(:revision)
return get_revision("#{@resource.value(:remote)}/HEAD") #notice "We've requested an explicit revision"
elsif branch == '(no branch)' if tag_revision?(@resource.value(:revision))
return get_revision('HEAD') #notice "tag #{@resource.value(:revision)}"
return get_revision(@resource.value(:revision))
elsif remote_branch_revision?(@resource.value(:revision))
#notice "branch #{@resource.value(:revision)}"
return get_revision("remotes/#{@resource.value(:remote)}/#{@resource.value(:revision)}")
end
else else
return get_revision("#{@resource.value(:remote)}/%s" % branch) #notice "we just want the latest thing"
return get_revision('FETCH_HEAD')
end end
end end
def head_revision
#notice "in head_revision"
return get_revision('HEAD')
end
def revision def revision
update_references #notice "in revision"
current = at_path { git_with_identity('rev-parse', 'HEAD').chomp } return @resource.value(:revision) || self.head_revision
return current unless @resource.value(:revision)
if tag_revision?(@resource.value(:revision))
canonical = at_path { git_with_identity('show', @resource.value(:revision)).scan(/commit (.*)/).to_s }
else
canonical = at_path { git_with_identity('rev-parse', @resource.value(:revision)).chomp }
end
if current == canonical
@resource.value(:revision)
else
current
end
end end
def revision=(desired) def revision=(desired)
checkout(desired) checkout(desired)
if local_branch_revision?(desired) if local_branch_revision?(desired)
#notice "revision=local_branch_revision? #{desired}"
# reset instead of pull to avoid merge conflicts. assuming remote is # reset instead of pull to avoid merge conflicts. assuming remote is
# authoritative. # authoritative.
# might be worthwhile to have an allow_local_changes param to decide # might be worthwhile to have an allow_local_changes param to decide
# whether to reset or pull when we're ensuring latest. # whether to reset or pull when we're ensuring latest.
at_path { git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}") } at_path { git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}") }
elsif tag_revision?(desired) else
at_path { git_with_identity('reset', '--hard', "#{desired}") } at_path { git_with_identity('reset', '--hard', "#{desired}") }
end end
if @resource.value(:ensure) != :bare if @resource.value(:ensure) != :bare
@ -98,6 +98,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
def update_references def update_references
at_path do at_path do
git_with_identity('fetch', '--tags', @resource.value(:remote))
git_with_identity('fetch', @resource.value(:remote)) git_with_identity('fetch', @resource.value(:remote))
update_owner_and_excludes update_owner_and_excludes
end end
@ -256,24 +257,11 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
end end
def get_revision(rev) def get_revision(rev)
#notice "in get_revision #{rev}"
if !working_copy_exists? if !working_copy_exists?
create create
end end
at_path do return at_path { git_with_identity('rev-parse', rev).strip }
git_with_identity('fetch', @resource.value(:remote))
git_with_identity('fetch', '--tags', @resource.value(:remote))
end
current = at_path { git_with_identity('rev-parse', rev).strip }
if @resource.value(:revision)
if local_branch_revision? or tag_revision?
canonical = at_path { git_with_identity('rev-parse', @resource.value(:revision)).strip }
elsif remote_branch_revision?
canonical = at_path { git_with_identity('rev-parse', "#{@resource.value(:remote)}/" + @resource.value(:revision)).strip }
end
current = @resource.value(:revision) if current == canonical
end
update_owner_and_excludes
return current
end end
def update_owner_and_excludes def update_owner_and_excludes
@ -305,6 +293,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
elsif @resource.value(:user) elsif @resource.value(:user)
su(@resource.value(:user), '-c', "git #{args.join(' ')}" ) su(@resource.value(:user), '-c', "git #{args.join(' ')}" )
else else
#notice "git #{args.join(' ')}"
git(*args) git(*args)
end end
end end

View File

@ -36,7 +36,6 @@ Puppet::Type.newtype(:vcsrepo) do
def insync?(is) def insync?(is)
@should ||= [] @should ||= []
case should case should
when :present when :present
return true unless [:absent, :purged, :held].include?(is) return true unless [:absent, :purged, :held].include?(is)
@ -46,8 +45,8 @@ Puppet::Type.newtype(:vcsrepo) do
else else
return false return false
end end
when :bare when :bare
return is == :bare return is == :bare
end end
end end
@ -72,7 +71,12 @@ Puppet::Type.newtype(:vcsrepo) do
provider.update_references provider.update_references
end end
if provider.respond_to?(:latest?) if provider.respond_to?(:latest?)
reference = provider.latest || provider.revision if resource.value(:revision) and provider.revision == resource.value(:revision)
reference = resource.value(:revision)
else
reference = provider.latest
end
notice reference
else else
reference = resource.value(:revision) || provider.revision reference = resource.value(:revision) || provider.revision
end end