From 329100b23fc0b49ee055badec1daaa3a9e25ce94 Mon Sep 17 00:00:00 2001 From: Xavier Shay Date: Mon, 2 Jan 2017 08:51:02 +1100 Subject: [PATCH 1/2] Anchor excludes to start of string. Fixes #44. Before this change, excluding a directory (`bin`) would also exclude posts that include that name (`scrubbing`), which is very unexpected. While this may start listening to files that were previously ignored, it more closely matches the behaviour of jekyll on it's initial build (which _would_ include `scrubbing`). The consequences of being overly aggressive on listening to changes seem less important than missing something. This change is a bandaid. A proper fix would be to unify with Jekyll's exclusion logic (Jekyll::EntryFilter maybe?) to ensure they will always be the same. In the meantime, it _may_ be advisable to not include Jekyll's `exclude` config in the watchers ignore list and take the hit of overly aggressive reloads. I leave that decision to someone more experienced than I. --- lib/jekyll/watcher.rb | 4 ++-- spec/watcher_spec.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/jekyll/watcher.rb b/lib/jekyll/watcher.rb index 2f3fb16..371ae93 100644 --- a/lib/jekyll/watcher.rb +++ b/lib/jekyll/watcher.rb @@ -99,14 +99,14 @@ def listen_ignore_paths(options) begin relative_path = absolute_path.relative_path_from(source).to_s unless relative_path.start_with?('../') - path_to_ignore = Regexp.new(Regexp.escape(relative_path)) + path_to_ignore = Regexp.new("^" + Regexp.escape(relative_path)) Jekyll.logger.debug "Watcher:", "Ignoring #{path_to_ignore}" path_to_ignore end rescue ArgumentError # Could not find a relative path end - end.compact + [/\.jekyll\-metadata/] + end.compact + [/^\.jekyll\-metadata/] end def sleep_forever diff --git a/spec/watcher_spec.rb b/spec/watcher_spec.rb index 18afecf..dd6c222 100644 --- a/spec/watcher_spec.rb +++ b/spec/watcher_spec.rb @@ -10,7 +10,7 @@ let(:options) { base_opts } let(:site) { instance_double(Jekyll::Site) } - let(:default_ignored) { [/_config\.yml/, /_site/, /\.jekyll\-metadata/] } + let(:default_ignored) { [/^_config\.yml/, /^_site/, /^\.jekyll\-metadata/] } subject { described_class } before(:each) do FileUtils.mkdir(options['destination']) if options['destination'] @@ -104,13 +104,13 @@ after(:each) { FileUtils.rm(excluded_absolute) } it "ignores the excluded files" do - expect(ignored).to include(/README\.md/) - expect(ignored).to include(/LICENSE/) + expect(ignored).to include(/^README\.md/) + expect(ignored).to include(/^LICENSE/) end end context "with a custom destination" do - let(:default_ignored) { [/_config\.yml/, /_dest/, /\.jekyll\-metadata/] } + let(:default_ignored) { [/^_config\.yml/, /^_dest/, /^\.jekyll\-metadata/] } context "when source is absolute" do context "when destination is absolute" do From d1ddd776302676622e970fae74cb7b4bf87c54e9 Mon Sep 17 00:00:00 2001 From: Xavier Shay Date: Sat, 28 Jan 2017 14:40:47 -0800 Subject: [PATCH 2/2] Redo ignore spec to actually check the regexes match as expected. --- spec/watcher_spec.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/spec/watcher_spec.rb b/spec/watcher_spec.rb index dd6c222..2c4cc36 100644 --- a/spec/watcher_spec.rb +++ b/spec/watcher_spec.rb @@ -98,14 +98,21 @@ context "with something excluded" do let(:excluded) { ['README.md', 'LICENSE'] } - let(:excluded_absolute) { excluded.map { |p| Jekyll.sanitized_path(options['source'], p) }} + let(:included) { ['OTHER-LICENSE'] } + let(:test_files) {(excluded + included).map { |p| + Jekyll.sanitized_path(options['source'], p) + }} let(:options) { base_opts.merge('exclude' => excluded) } - before(:each) { FileUtils.touch(excluded_absolute) } - after(:each) { FileUtils.rm(excluded_absolute) } + before(:each) { FileUtils.touch(test_files) } + after(:each) { FileUtils.rm(test_files) } it "ignores the excluded files" do - expect(ignored).to include(/^README\.md/) - expect(ignored).to include(/^LICENSE/) + expect(ignored).to include( match("README.md") ) + expect(ignored).to include( match("LICENSE") ) + end + + it "does not exclude files that submatch the exclude list" do + expect(ignored).to_not include( match("OTHER-LICENSE") ) end end