summaryrefslogtreecommitdiff
path: root/lib/puppet/provider/vcsrepo
diff options
context:
space:
mode:
authorBruce Williams <bruce@codefluency.com>2010-03-13 15:19:39 -0800
committerBruce Williams <bruce@codefluency.com>2010-03-13 15:19:39 -0800
commit15ddecef0ee3634d730ae2a6342859dbeba6d835 (patch)
tree622cac34ccb4164f8fc96df6d153c0f871f34081 /lib/puppet/provider/vcsrepo
parent9d1e7c7284d03e7524d39ab9e000ec1371c1724d (diff)
Basic Mercurial support
Diffstat (limited to 'lib/puppet/provider/vcsrepo')
-rw-r--r--lib/puppet/provider/vcsrepo/cvs.rb2
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb2
-rw-r--r--lib/puppet/provider/vcsrepo/hg.rb59
-rw-r--r--lib/puppet/provider/vcsrepo/svn.rb2
4 files changed, 62 insertions, 3 deletions
diff --git a/lib/puppet/provider/vcsrepo/cvs.rb b/lib/puppet/provider/vcsrepo/cvs.rb
index 58018d3..99faa54 100644
--- a/lib/puppet/provider/vcsrepo/cvs.rb
+++ b/lib/puppet/provider/vcsrepo/cvs.rb
@@ -1,4 +1,4 @@
-require 'puppet/provider/vcsrepo'
+require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo) do
desc "Supports CVS repositories/workspaces"
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb
index 99477a0..eeecac3 100644
--- a/lib/puppet/provider/vcsrepo/git.rb
+++ b/lib/puppet/provider/vcsrepo/git.rb
@@ -1,4 +1,4 @@
-require 'puppet/provider/vcsrepo'
+require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) do
desc "Supports Git repositories"
diff --git a/lib/puppet/provider/vcsrepo/hg.rb b/lib/puppet/provider/vcsrepo/hg.rb
new file mode 100644
index 0000000..7263b4f
--- /dev/null
+++ b/lib/puppet/provider/vcsrepo/hg.rb
@@ -0,0 +1,59 @@
+require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
+
+Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) do
+ desc "Supports Mercurial repositories"
+
+ commands :hg => 'hg'
+ defaultfor :hg => :exists
+
+ def create
+ if !@resource.value(:source)
+ create_repository(@resource.value(:path))
+ else
+ clone_repository(@resource.value(:revision))
+ end
+ end
+
+ def exists?
+ File.directory?(File.join(@resource.value(:path), '.hg'))
+ end
+
+ def destroy
+ FileUtils.rm_rf(@resource.value(:path))
+ end
+
+ def revision
+ at_path do
+ hg('parents')[/^changeset:\s+(?:-?\d+):(\S+)/m, 1]
+ end
+ end
+
+ def revision=(desired)
+ at_path do
+ hg('pull')
+ begin
+ hg('merge')
+ rescue Puppet::ExecutionFailure
+ # If there's nothing to merge, just skip
+ end
+ hg('update', '--clean', '-r', desired)
+ end
+ end
+
+ private
+
+ def create_repository(path)
+ hg('init', path)
+ end
+
+ def clone_repository(revision)
+ args = ['clone']
+ if revision
+ args.push('-u', revision)
+ end
+ args.push(@resource.value(:source),
+ @resource.value(:path))
+ hg(*args)
+ end
+
+end
diff --git a/lib/puppet/provider/vcsrepo/svn.rb b/lib/puppet/provider/vcsrepo/svn.rb
index 97c7fcb..09fdd0e 100644
--- a/lib/puppet/provider/vcsrepo/svn.rb
+++ b/lib/puppet/provider/vcsrepo/svn.rb
@@ -1,4 +1,4 @@
-require 'puppet/provider/vcsrepo'
+require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo) do
desc "Supports Subversion repositories"