From e0b8539670b9cbc24175d9816241567e9eea74ae Mon Sep 17 00:00:00 2001 From: Shinnosuke Kondo Date: Mon, 13 Jul 2015 17:47:42 -0500 Subject: [PATCH 1/4] Added a new case for test_clearner where a directory is not in keep_files, but its path contains a string in keep_files. --- test/test_cleaner.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/test_cleaner.rb b/test/test_cleaner.rb index 819dbf5c..c96394d7 100644 --- a/test/test_cleaner.rb +++ b/test/test_cleaner.rb @@ -37,6 +37,40 @@ class TestCleaner < JekyllUnitTest end end + context "not-nested directory in keep_files and similary named directory not in keep_files" do + setup do + clear_dest + + FileUtils.mkdir_p(dest_dir('.git/child_dir')) + FileUtils.mkdir_p(dest_dir('username.github.io')) + FileUtils.touch(File.join(dest_dir('.git'), 'index.html')) + FileUtils.touch(File.join(dest_dir('username.github.io'), 'index.html')) + + @site = fixture_site + @site.keep_files = ['.git'] + + @cleaner = Cleaner.new(@site) + @cleaner.cleanup! + end + + teardown do + FileUtils.rm_rf(dest_dir('.git')) + FileUtils.rm_rf(dest_dir('.username.github.io')) + end + + should "keep the file in the directory in keep_files" do + assert File.exist?(File.join(dest_dir('.git'), 'index.html')) + end + + should "delete the file in the directory not in keep_files" do + assert !File.exist?(File.join(dest_dir('username.github.io'), 'index.html')) + end + + should "delete the directory not in keep_files" do + assert !File.exist?(dest_dir('username.github.io')) + end + end + context "directory containing no files and non-empty directories" do setup do clear_dest From 3b60237cb152aa19526902d30bd02feb39a71f24 Mon Sep 17 00:00:00 2001 From: Shinnosuke Kondo Date: Mon, 13 Jul 2015 18:34:40 -0500 Subject: [PATCH 2/4] Fix keep_files to be used as paths relative to the destination. They were used as keywords to match files containing them in the paths. --- lib/jekyll/cleaner.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/cleaner.rb b/lib/jekyll/cleaner.rb index 70bd2f79..2a00a737 100644 --- a/lib/jekyll/cleaner.rb +++ b/lib/jekyll/cleaner.rb @@ -94,11 +94,12 @@ module Jekyll # Private: Creates a regular expression from the config's keep_files array # # Examples - # ['.git','.svn'] creates the following regex: /\/(\.git|\/.svn)/ + # ['.git','.svn'] with site.dest "/myblog/_site" creates + # the following regex: /\/myblog\/_site\/(\.git|\/.svn)/ # # Returns the regular expression def keep_file_regex - Regexp.union(site.keep_files) + /#{Regexp.quote(site.dest)}\/(#{Regexp.union(site.keep_files).source})/ end end end From 1eb626b1dfdcb90cbc6f48c0b67b665ed71fccbe Mon Sep 17 00:00:00 2001 From: Shinnosuke Kondo Date: Mon, 13 Jul 2015 19:08:11 -0500 Subject: [PATCH 3/4] Fix keep_files not to match a file with repeated path. --- lib/jekyll/cleaner.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/cleaner.rb b/lib/jekyll/cleaner.rb index 2a00a737..509cebb1 100644 --- a/lib/jekyll/cleaner.rb +++ b/lib/jekyll/cleaner.rb @@ -95,11 +95,11 @@ module Jekyll # # Examples # ['.git','.svn'] with site.dest "/myblog/_site" creates - # the following regex: /\/myblog\/_site\/(\.git|\/.svn)/ + # the following regex: /\A\/myblog\/_site\/(\.git|\/.svn)/ # # Returns the regular expression def keep_file_regex - /#{Regexp.quote(site.dest)}\/(#{Regexp.union(site.keep_files).source})/ + /\A#{Regexp.quote(site.dest)}\/(#{Regexp.union(site.keep_files).source})/ end end end From c27c669796adfc836fbaeda7c632b12b70731bf2 Mon Sep 17 00:00:00 2001 From: Shinn Kondo Date: Wed, 23 Mar 2016 20:37:13 -0500 Subject: [PATCH 4/4] Fix test teardown for cleaner. --- test/test_cleaner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_cleaner.rb b/test/test_cleaner.rb index 7b2fb641..2118c4f4 100644 --- a/test/test_cleaner.rb +++ b/test/test_cleaner.rb @@ -55,7 +55,7 @@ class TestCleaner < JekyllUnitTest teardown do FileUtils.rm_rf(dest_dir('.git')) - FileUtils.rm_rf(dest_dir('.username.github.io')) + FileUtils.rm_rf(dest_dir('username.github.io')) end should "keep the file in the directory in keep_files" do