Skip to content

Commit b9b954d

Browse files
committed
Merge branch 'chef-639' of git://github.com/fujin/chef into fujin/chef-639
2 parents b3f19a6 + e6259b8 commit b9b954d

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

chef/lib/chef/provider/git.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ def load_current_resource
3636
end
3737

3838
def action_checkout
39-
clone
40-
checkout
41-
enable_submodules
42-
@new_resource.updated = true
39+
if !::File.exist?(@new_resource.destination) || Dir.entries(@new_resource.destination) == ['.','..']
40+
clone
41+
checkout
42+
enable_submodules
43+
@new_resource.updated = true
44+
else
45+
Chef::Log.info "Taking no action, checkout destination " +
46+
"#{@new_resource.destination} already exists or is a non-empty directory"
47+
end
4348
end
4449

4550
def action_export

chef/spec/unit/provider/git_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,28 @@
203203
@provider.should_receive(:run_command).with(:command => expected_cmd, :cwd => "/my/deploy/dir")
204204
@provider.sync
205205
end
206-
206+
207207
it "does a checkout running the clone command then running the after clone command from the destination dir" do
208+
::File.stub!(:exist?).with("/my/deploy/dir").and_return(false)
209+
::Dir.stub!(:entries).with("/my/deploy/dir").and_return(['.','..'])
208210
@provider.should_receive(:clone)
209211
@provider.should_receive(:checkout)
210212
@provider.should_receive(:enable_submodules)
211213
@resource.should_receive(:updated=).at_least(1).times.with(true)
212214
@provider.action_checkout
213215
end
214216

217+
it "should not checkout if the destination exists or is a non empty directory" do
218+
::File.stub!(:exist?).with("/my/deploy/dir").and_return(true)
219+
::Dir.stub!(:entries).with("/my/deploy/dir").and_return(['.','..','foo','bar'])
220+
@provider.should_not_receive(:clone)
221+
@provider.should_not_receive(:checkout)
222+
@provider.should_not_receive(:enable_submodules)
223+
@resource.should_not_receive(:updated=)
224+
Chef::Log.should_receive(:info).with("Taking no action, checkout destination /my/deploy/dir already exists or is a non-empty directory")
225+
@provider.action_checkout
226+
end
227+
215228
it "does a sync by running the sync command" do
216229
::File.stub!(:exist?).with("/my/deploy/dir").and_return(true)
217230
::Dir.stub!(:entries).and_return(['.','..',"lib", "spec"])

0 commit comments

Comments
 (0)