diff options
-rw-r--r-- | lib/puppet/provider/vcsrepo/git.rb | 34 | ||||
-rw-r--r-- | lib/puppet/type/vcsrepo.rb | 20 |
2 files changed, 32 insertions, 22 deletions
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index a17990e..7ae9182 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -30,18 +30,19 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) FileUtils.rm_rf(@resource.value(:path)) end - def revision - if !working_copy_exists? - create + def latest? + at_path do + return self.revision == self.latest end + end - current = at_path { git('rev-parse', 'HEAD') } - canonical = at_path { git('rev-parse', @resource.value(:revision)) } - if current == canonical - @resource.value(:revision) - else - current - end + def latest + fetch + return get_revision('origin/HEAD') + end + + def revision + return get_revision('HEAD') end def revision=(desired) @@ -219,4 +220,17 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) at_path { git('branch', '-a') }.gsub('*', ' ').split(/\n/).map { |line| line.strip } end + def get_revision(rev) + if !working_copy_exists? + create + end + + current = at_path { git('rev-parse', rev).strip } + if @resource.value(:revision) + canonical = at_path { git('rev-parse', @resource.value(:revision)).strip } + current = @resource.value(:revision) if current == canonical + end + + return current + end end diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb index ff3624b..8b2d93e 100644 --- a/lib/puppet/type/vcsrepo.rb +++ b/lib/puppet/type/vcsrepo.rb @@ -28,13 +28,13 @@ Puppet::Type.newtype(:vcsrepo) do when :present return true unless [:absent, :purged, :held].include?(is) when :latest - if provider.latest? + if is == :latest return true else self.debug "%s repo revision is %s, latest is %s" % [@resource.name, provider.revision, provider.latest] return false - end + end end end @@ -70,16 +70,12 @@ Puppet::Type.newtype(:vcsrepo) do def retrieve prov = @resource.provider if prov - if prov.class.feature?(:bare_repositories) - if prov.working_copy_exists? - :present - elsif prov.bare_exists? - :bare - else - :absent - end + if prov.working_copy_exists? + prov.latest? ? :latest : :present + elsif prov.class.feature?(:bare_repositories) and prov.bare_exists? + :bare else - prov.exists? ? :present : :absent + :absent end else raise Puppet::Error, "Could not find provider" @@ -121,4 +117,4 @@ Puppet::Type.newtype(:vcsrepo) do end end -end
\ No newline at end of file +end |