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