ensure = latest to support reference tracking.\n\nWorking with tags, more work needed...
[puppet_vcsrepo.git] / lib / puppet / provider / vcsrepo / svn.rb
1 require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
2
3 Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo) do
4   desc "Supports Subversion repositories"
5
6   commands :svn      => 'svn',
7            :svnadmin => 'svnadmin'
8
9   defaultfor :svn => :exists
10   has_features :filesystem_types, :reference_tracking
11
12   def create
13     if !@resource.value(:source)
14       create_repository(@resource.value(:path))
15     else
16       checkout_repository(@resource.value(:source),
17                           @resource.value(:path),
18                           @resource.value(:revision))
19     end
20   end
21
22   def exists?
23     File.directory?(@resource.value(:path))
24   end
25
26   def destroy
27     FileUtils.rm_rf(@resource.value(:path))
28   end
29   
30   def revision
31     at_path do
32       svn('info')[/^Revision:\s+(\d+)/m, 1]
33     end
34   end
35
36   def revision=(desired)
37     at_path do
38       svn('update', '-r', desired)
39     end
40   end
41
42   private
43
44   def checkout_repository(source, path, revision = nil)
45     args = ['checkout']
46     if revision
47       args.push('-r', revision)
48     end
49     args.push(source, path)
50     svn(*args)
51   end
52
53   def create_repository(path)
54     args = ['create']
55     if @resource.value(:fstype)
56       args.push('--fs-type', @resource.value(:fstype))
57     end
58     args << path
59     svnadmin(*args)
60   end
61
62 end