diff options
author | root <root@localhost.localdomain> | 2010-02-22 19:40:07 -0600 |
---|---|---|
committer | root <root@localhost.localdomain> | 2010-02-22 19:40:07 -0600 |
commit | cb2efcdfaa1f9b6d8c78208151d4b4ebd4e35885 (patch) | |
tree | 5d1cb21e799f002de8405a2b16d51f5632289cb9 |
Initial commit
-rw-r--r-- | lib/puppet/provider/vcsrepo/git.rb | 73 | ||||
-rw-r--r-- | lib/puppet/type/vcsrepo.rb | 31 |
2 files changed, 104 insertions, 0 deletions
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb new file mode 100644 index 0000000..298d1dc --- /dev/null +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -0,0 +1,73 @@ +Puppet::Type.type(:vcsrepo).provide(:git) do + desc "Supports Git repositories" + + commands :git => 'git' + + def create + if !@resource.value(:source) + init_repository(@resource.value(:path)) + else + clone_repository(@resource.value(:source), @resource.value(:path)) + reset(@resource.value(:revision)) if @resource.value(:revision) + end + end + + def exists? + File.directory?(@resource.value(:path)) + end + + def destroy + FileUtils.rm_rf(@resource.value(:path)) + end + + def revision + current = Dir.chdir(@resource.value(:path)) do + git('rev-parse', 'HEAD') + end + canonical = Dir.chdir(@resource.value(:path)) do + git('rev-parse', @resource.value(:revision)) + end + if current == canonical + @resource.value(:revision) + else + current + end + end + + def revision=(desired) + fetch + reset(desired) + end + + private + + def clone_repository(source, path) + parent = File.dirname(path) + FileUtils.mkdir_p(parent) + git('clone', source, path) + end + + def fetch + at_path do + git('fetch', 'origin') + end + end + + def init_repository(path) + FileUtils.mkdir_p(path) + at_path do + git('init') + end + end + + def reset(desired) + at_path do + git('reset', '--hard', desired) + end + end + + def at_path(&block) + Dir.chdir(@resource.value(:path), &block) + end + +end diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb new file mode 100644 index 0000000..7db571e --- /dev/null +++ b/lib/puppet/type/vcsrepo.rb @@ -0,0 +1,31 @@ +require 'pathname' + +Puppet::Type.newtype(:vcsrepo) do + desc "A local version control repository" + + ensurable + + newparam(:path) do + desc "Absolute path to repository" + isnamevar + validate do |value| + path = Pathname.new(value) + unless path.absolute? + raise ArgumentError, "Path must be absolute: #{path}" + end + end + end + + newparam(:source) do + desc "The source URL for the repository" + validate do |value| + URI.parse(value) + end + end + + newproperty(:revision) do + desc "The revision of the repository" + newvalue(/^\S+$/) + end + +end |