Some fixes after live testing, add support for bare cloned repos
[puppet_vcsrepo.git] / lib / puppet / provider / vcsrepo / svn.rb
1 Puppet::Type.type(:vcsrepo).provide(:svn) do
2   desc "Supports Subversion repositories"
3
4   commands :svn      => 'svn',
5            :svnadmin => 'svnadmin'
6
7   defaultfor :svn => :exists
8   
9   def create
10     if !@resource.value(:source)
11       create_repository(@resource.value(:path))
12     else
13       checkout_repository(@resource.value(:source),
14                           @resource.value(:path),
15                           @resource.value(:revision))
16     end
17   end
18
19   def exists?
20     File.directory?(@resource.value(:path))
21   end
22
23   def destroy
24     FileUtils.rm_rf(@resource.value(:path))
25   end
26   
27   def revision
28     at_path do
29       svn('info')[/^Revision:\s+(\d+)/m, 1]
30     end
31   end
32
33   def revision=(desired)
34     at_path do
35       svn('update', '-r', desired)
36     end
37   end
38
39   private
40
41   def checkout_repository(source, path, revision = nil)
42     args = ['checkout']
43     if revision
44       args.push('-r', revision)
45     end
46     args.push(source, path)
47     svn(*args)
48   end
49
50   def create_repository(path)
51     args = ['create']
52     if @resource.value(:fstype)
53       args.push('--fs-type', @resource.value(:fstype))
54     end
55     args << path
56     svnadmin(*args)
57   end
58
59   def reset(desired)
60     at_path do
61       git('reset', '--hard', desired)
62     end
63   end
64
65   # Note: We don't rely on Dir.chdir's behavior of automatically returning the
66   # value of the last statement -- for easier stubbing.
67   def at_path(&block) #:nodoc:
68     value = nil
69     Dir.chdir(@resource.value(:path)) do
70       value = yield
71     end
72     value
73   end
74
75 end