Skip to content
Snippets Groups Projects
Commit ce20a434 authored by Steven Danna's avatar Steven Danna
Browse files

Merge pull request #477 from chef/ssd/move-directory-get-out-the-way

Forcibly remove a non-empty project dir before cloning
parents 9d387525 3635f816
No related branches found
No related tags found
1 merge request!2omnibus version to v5.0.0
Loading
Loading
@@ -64,6 +64,7 @@ module Omnibus
if cloned?
git_fetch(resolved_version) unless same_revision?(resolved_version)
else
force_recreate_project_dir! unless dir_empty?(project_dir)
git_clone
git_checkout(resolved_version)
end
Loading
Loading
@@ -90,6 +91,24 @@ module Omnibus
source[:git]
end
 
#
# Determine if a directory is empty
#
# @return [true, false]
#
def dir_empty?(dir)
Dir.entries(dir).reject {|d| ['.', '..'].include?(d) }.empty?
end
#
# Forcibly remove and recreate the project directory
#
def force_recreate_project_dir!
log.warn(log_key) { "Removing exisitng directory #{project_dir} before cloning" }
FileUtils.rm_rf(project_dir)
Dir.mkdir(project_dir)
end
#
# Determine if the clone exists.
#
Loading
Loading
Loading
Loading
@@ -98,6 +98,7 @@ module Omnibus
allow(subject).to receive(:git_fetch)
allow(subject).to receive(:git_clone)
allow(subject).to receive(:git_checkout)
allow(subject).to receive(:dir_empty?).and_return(true)
allow(subject).to receive(:resolved_version).and_return("134aeba31234")
end
 
Loading
Loading
@@ -126,6 +127,16 @@ module Omnibus
context 'when the repository is not cloned' do
before { allow(subject).to receive(:cloned?).and_return(false) }
 
context "but a directory does exist" do
before { expect(subject).to receive(:dir_empty?).with(project_dir).and_return(false)}
it "forcefully removes and recreateds the directory" do
expect(FileUtils).to receive(:rm_rf).with(project_dir).and_return(project_dir)
expect(Dir).to receive(:mkdir).with(project_dir).and_return(0)
subject.fetch
end
end
it 'clones the repository' do
expect(subject).to receive(:git_clone).once
subject.fetch
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment