Merge pull request #35 from sodabrew/dummy-provider
[puppet_vcsrepo.git] / lib / puppet / provider / vcsrepo / bzr.rb
1 require File.join(File.dirname(__FILE__), '..', 'vcsrepo')
2
3 Puppet::Type.type(:vcsrepo).provide(:bzr, :parent => Puppet::Provider::Vcsrepo) do
4   desc "Supports Bazaar repositories"
5
6   optional_commands   :bzr => 'bzr'
7   has_features :reference_tracking
8
9   def create
10     if !@resource.value(:source)
11       create_repository(@resource.value(:path))
12     else
13       clone_repository(@resource.value(:revision))
14     end
15   end
16
17   def working_copy_exists?
18     File.directory?(File.join(@resource.value(:path), '.bzr'))
19   end
20
21   def exists?
22     working_copy_exists?
23   end
24
25   def destroy
26     FileUtils.rm_rf(@resource.value(:path))
27   end
28
29   def revision
30     at_path do
31       current_revid = bzr('version-info')[/^revision-id:\s+(\S+)/, 1]
32       desired = @resource.value(:revision)
33       begin
34         desired_revid = bzr('revision-info', desired).strip.split(/\s+/).last
35       rescue Puppet::ExecutionFailure
36         # Possible revid available during update (but definitely not current)
37         desired_revid = nil
38       end
39       if current_revid == desired_revid
40         desired
41       else
42         current_revid
43       end
44     end
45   end
46
47   def revision=(desired)
48     bzr('update', '-r', desired, @resource.value(:path))
49   end
50
51   private
52
53   def create_repository(path)
54     bzr('init', path)
55   end
56
57   def clone_repository(revision)
58     args = ['branch']
59     if revision
60       args.push('-r', revision)
61     end
62     args.push(@resource.value(:source),
63               @resource.value(:path))
64     bzr(*args)
65   end
66
67 end