Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit c34ece6

Browse files
committed
Fix ensure_remote logic
1 parent 7eb3a67 commit c34ece6

File tree

1 file changed

+28
-11
lines changed
  • lib/puppet/provider/repository

1 file changed

+28
-11
lines changed

lib/puppet/provider/repository/git.rb

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@ def query
2424
h = { :name => @resource[:name], :provider => :git }
2525

2626
if cloned?
27-
if [:present, :absent].member? @resource[:ensure]
28-
h.merge(:ensure => :present)
27+
if @resource[:ensure] == :absent
28+
h.merge(:ensure => :present)
29+
elsif @resource[:ensure] == :present
30+
if correct_remote?
31+
h.merge(:ensure => :present)
32+
else
33+
# we need to ensure the correct remote, cheat #exists?
34+
h.merge(:ensure => :update)
35+
end
2936
else
30-
if correct_revision?
37+
if correct_remote? && correct_revision?
3138
h.merge(:ensure => @resource[:ensure])
3239
else
33-
# we need to ensure the correct revision, cheat #exists?
34-
h.merge(:ensure => current_revision)
40+
# we need to ensure the correct revision and remote, cheat #exists?
41+
h.merge(:ensure => :update)
3542
end
3643
end
3744
else
@@ -55,13 +62,11 @@ def create
5562
def ensure_remote
5663
create unless cloned?
5764

58-
Dir.chdir @resource[:path] do
59-
source = execute [command(:git), "config", "--get", "remote.origin.url"], command_opts
60-
61-
if source != friendly_source
62-
execute [command(:git), "config", "--set", "remote.origin.url", friendly_source], command_opts
65+
unless correct_remote?
66+
Dir.chdir @resource[:path] do
67+
execute [command(:git), "config", "remote.origin.url", friendly_source], command_opts
6368

64-
Puppet.info("Repository[#{@resource[:name]}] changing source from #{source} to #{friendly_source}")
69+
Puppet.notice("Repository[#{@resource[:name]}] changing source from #{current_remote} to #{friendly_source}")
6570
end
6671
end
6772
end
@@ -162,6 +167,14 @@ def target_revision
162167
end
163168
end
164169

170+
def current_remote
171+
@current_remote ||= Dir.chdir @resource[:path] do
172+
execute([
173+
command(:git), "config", "--get", "remote.origin.url"
174+
], command_opts).chomp
175+
end
176+
end
177+
165178
def cloned?
166179
File.directory?(@resource[:path]) &&
167180
File.directory?("#{@resource[:path]}/.git")
@@ -176,4 +189,8 @@ def correct_revision?
176189
current_revision == target_revision
177190
end
178191
end
192+
193+
def correct_remote?
194+
current_remote == friendly_source
195+
end
179196
end

0 commit comments

Comments
 (0)