summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/provider/vcsrepo/bzr.rb1
-rw-r--r--lib/puppet/provider/vcsrepo/cvs.rb2
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb18
-rw-r--r--lib/puppet/provider/vcsrepo/hg.rb1
-rw-r--r--lib/puppet/provider/vcsrepo/svn.rb2
-rw-r--r--lib/puppet/type/vcsrepo.rb17
-rw-r--r--spec/unit/puppet/provider/vcsrepo/git_spec.rb11
7 files changed, 45 insertions, 7 deletions
diff --git a/lib/puppet/provider/vcsrepo/bzr.rb b/lib/puppet/provider/vcsrepo/bzr.rb
index a6e12cd..a060562 100644
--- a/lib/puppet/provider/vcsrepo/bzr.rb
+++ b/lib/puppet/provider/vcsrepo/bzr.rb
@@ -5,6 +5,7 @@ Puppet::Type.type(:vcsrepo).provide(:bzr, :parent => Puppet::Provider::Vcsrepo)
commands :bzr => 'bzr'
defaultfor :bzr => :exists
+ has_features :reference_tracking
def create
if !@resource.value(:source)
diff --git a/lib/puppet/provider/vcsrepo/cvs.rb b/lib/puppet/provider/vcsrepo/cvs.rb
index 1cedc8b..e82c23a 100644
--- a/lib/puppet/provider/vcsrepo/cvs.rb
+++ b/lib/puppet/provider/vcsrepo/cvs.rb
@@ -5,7 +5,7 @@ Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo)
commands :cvs => 'cvs'
defaultfor :cvs => :exists
- has_features :gzip_compression
+ has_features :gzip_compression, :reference_tracking
def create
if !@resource.value(:source)
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb
index 274f25b..ba5065e 100644
--- a/lib/puppet/provider/vcsrepo/git.rb
+++ b/lib/puppet/provider/vcsrepo/git.rb
@@ -5,7 +5,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
commands :git => 'git'
defaultfor :git => :exists
- has_features :bare_repositories
+ has_features :bare_repositories, :reference_tracking
def create
if !@resource.value(:source)
@@ -37,7 +37,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
end
def revision=(desired)
- fetch
+ pull
reset(desired)
end
@@ -48,6 +48,16 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
def working_copy_exists?
File.directory?(File.join(@resource.value(:path), '.git'))
end
+
+ def exists?
+ working_copy_exists? || bare_exists?
+ end
+
+ def update_references
+ at_path do
+ git('fetch', '--tags', 'origin')
+ end
+ end
private
@@ -68,9 +78,9 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
git(*args)
end
- def fetch
+ def pull
at_path do
- git('fetch', 'origin')
+ git('pull', 'origin')
end
end
diff --git a/lib/puppet/provider/vcsrepo/hg.rb b/lib/puppet/provider/vcsrepo/hg.rb
index 928049f..df8b4f0 100644
--- a/lib/puppet/provider/vcsrepo/hg.rb
+++ b/lib/puppet/provider/vcsrepo/hg.rb
@@ -5,6 +5,7 @@ Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) d
commands :hg => 'hg'
defaultfor :hg => :exists
+ has_features :reference_tracking
def create
if !@resource.value(:source)
diff --git a/lib/puppet/provider/vcsrepo/svn.rb b/lib/puppet/provider/vcsrepo/svn.rb
index 7cdd157..5fa586d 100644
--- a/lib/puppet/provider/vcsrepo/svn.rb
+++ b/lib/puppet/provider/vcsrepo/svn.rb
@@ -7,7 +7,7 @@ Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo)
:svnadmin => 'svnadmin'
defaultfor :svn => :exists
- has_features :filesystem_types
+ has_features :filesystem_types, :reference_tracking
def create
if !@resource.value(:source)
diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb
index 69c7f74..137f8cd 100644
--- a/lib/puppet/type/vcsrepo.rb
+++ b/lib/puppet/type/vcsrepo.rb
@@ -14,6 +14,10 @@ Puppet::Type.newtype(:vcsrepo) do
feature :filesystem_types,
"The provider supports different filesystem types"
+ feature :reference_tracking,
+ "The provider supports tracking revision references that can change
+ over time (eg, some VCS tags and branch names)"
+
ensurable do
newvalue :present do
@@ -28,6 +32,19 @@ Puppet::Type.newtype(:vcsrepo) do
provider.destroy
end
+ newvalue :latest, :required_features => [:reference_tracking] do
+ if provider.exists?
+ if provider.respond_to?(:update_references)
+ provider.update_references
+ end
+ reference = resource.value(:revision) || provider.revision
+ notice "Updating to latest '#{reference}' revision"
+ provider.revision = reference
+ else
+ provider.create
+ end
+ end
+
def retrieve
prov = @resource.provider
if prov
diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
index 5cf6c86..0e16e60 100644
--- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
@@ -185,11 +185,20 @@ describe provider_class do
describe "when setting the revision property" do
it "should use 'git fetch' and 'git reset'" do
@resource.expects(:value).with(:path).returns(@path).at_least_once
- @provider.expects('git').with('fetch', 'origin')
+ @provider.expects('git').with('pull', 'origin')
Dir.expects(:chdir).with(@path).at_least_once.yields
@provider.expects('git').with('reset', '--hard', 'carcar')
@provider.revision = 'carcar'
end
end
+ describe "when updating references" do
+ it "should use 'git fetch --tags'" do
+ @resource.expects(:value).with(:path).returns(@path).at_least_once
+ @provider.expects('git').with('fetch', '--tags', 'origin')
+ Dir.expects(:chdir).with(@path).at_least_once.yields
+ @provider.update_references
+ end
+ end
+
end