diff --git a/features/create_sites.feature b/features/create_sites.feature index 346c0350..16e733b1 100644 --- a/features/create_sites.feature +++ b/features/create_sites.feature @@ -117,3 +117,14 @@ Feature: Create sites When I run jekyll Then the _site directory should exist And I should see "SomeDirective" in "_site/.htaccess" + + Scenario: File was replaced by a directory + Given I have a "test" file that contains "some stuff" + When I run jekyll + Then the _site directory should exist + When I delete the file "test" + Given I have a test directory + And I have a "test/index.html" file that contains "some other stuff" + When I run jekyll + Then the _site/test directory should exist + And I should see "some other stuff" in "_site/test/index.html" diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index c1f4347f..1dca32d9 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -131,6 +131,10 @@ When /^I change "(.*)" to contain "(.*)"$/ do |file, text| end end +When /^I delete the file "(.*)"$/ do |file| + File.delete(file) +end + Then /^the (.*) directory should exist$/ do |dir| assert File.directory?(dir), "The directory \"#{dir}\" does not exist" end diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index e1eb95e2..e8990b85 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -270,7 +270,11 @@ module Jekyll files.each { |file| dirs << File.dirname(file) } files.merge(dirs) - obsolete_files = dest_files - files + # files that are replaced by dirs should be deleted + files_to_delete = Set.new + dirs.each { |dir| files_to_delete << dir if File.file?(dir) } + + obsolete_files = dest_files - files + files_to_delete FileUtils.rm_rf(obsolete_files.to_a) end