Add support for master svn repositories
[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   optional_commands :svn      => 'svn',
7                     :svnadmin => 'svnadmin',
8                     :svnlook  => 'svnlook'
9
10   has_features :filesystem_types, :reference_tracking, :basic_auth, :configuration
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     update_owner
21   end
22
23   def working_copy_exists?
24     if File.directory?(@resource.value(:path))
25       if File.directory?(File.join(@resource.value(:path), '.svn'))
26         return true
27       end
28       if svnlook('uuid',@resource.value(:path))
29         return true
30       end
31     end
32     return false
33   end
34
35   def exists?
36     working_copy_exists?
37   end
38
39   def destroy
40     FileUtils.rm_rf(@resource.value(:path))
41   end
42
43   def latest?
44     at_path do
45       if self.revision < self.latest then
46         return false
47       else
48         return true
49       end
50     end
51   end
52
53   def buildargs
54     args = ['--non-interactive']
55     if @resource.value(:basic_auth_username) && @resource.value(:basic_auth_password)
56       args.push('--username', @resource.value(:basic_auth_username))
57       args.push('--password', @resource.value(:basic_auth_password))
58       args.push('--no-auth-cache')
59     end
60
61     if @resource.value(:force)
62       args.push('--force')
63     end
64
65     if @resource.value(:configuration)
66       args.push('--config-dir', @resource.value(:configuration))
67     end
68
69     return args
70   end
71
72   def latest
73     args = buildargs.push('info', '-r', 'HEAD')
74     at_path do
75       svn(*args)[/^Last Changed Rev:\s+(\d+)/m, 1]
76     end
77   end
78
79   def revision
80     args = buildargs.push('info')
81     at_path do
82       svn(*args)[/^Last Changed Rev:\s+(\d+)/m, 1]
83     end
84   end
85
86   def revision=(desired)
87     args = buildargs.push('update', '-r', desired)
88     at_path do
89       svn(*args)
90     end
91     update_owner
92   end
93
94   private
95
96   def checkout_repository(source, path, revision)
97     args = buildargs.push('checkout')
98     if revision
99       args.push('-r', revision)
100     end
101     args.push(source, path)
102     svn(*args)
103   end
104
105   def create_repository(path)
106     args = ['create']
107     if @resource.value(:fstype)
108       args.push('--fs-type', @resource.value(:fstype))
109     end
110     args << path
111     svnadmin(*args)
112   end
113
114   def update_owner
115     if @resource.value(:owner) or @resource.value(:group)
116       set_ownership
117     end
118   end
119 end