Only add ssh options to commands that actually talk to the network.
[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     at_path do
49       begin
50         bzr('update', '-r', desired)
51       rescue Puppet::ExecutionFailure
52         bzr('update', '-r', desired, ':parent')
53       end
54     end
55   end
56
57   def latest
58     at_path do
59       bzr('version-info', ':parent')[/^revision-id:\s+(\S+)/, 1]
60     end
61   end
62
63   def latest?
64     at_path do
65       return self.revision == self.latest
66     end
67   end
68
69   private
70
71   def create_repository(path)
72     bzr('init', path)
73   end
74
75   def clone_repository(revision)
76     args = ['branch']
77     if revision
78       args.push('-r', revision)
79     end
80     args.push(@resource.value(:source),
81               @resource.value(:path))
82     bzr(*args)
83   end
84
85 end