Skip to content

Commit

Permalink
fix broken test cases and revert _config.yml exclusion check
Browse files Browse the repository at this point in the history
I couldn't figure out how to make rspec change dir to the root of
the site, so I couldn't make it pass the test. Just ended up reverting
to the original method name :(.

Also didn't realise the regexps used by listen_ignore_paths began with
a ^, my bad. Fixed now.
  • Loading branch information
mohkale committed Dec 30, 2019
1 parent a46993c commit 45f1dfe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
19 changes: 7 additions & 12 deletions lib/jekyll/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,8 @@ def custom_excludes(options)
end

def config_files(options)
# only check to exclude config file when config file is within our src directory
# which can only happen if our src directory is the same as our cwd.
if Pathname.new(options["source"]).expand_path.eql?(Pathname.new(".").expand_path)
%w(yml yaml toml).map(&"^_config\.".method(:+))
else
[]
%w(yml yaml toml).map do |ext|
Jekyll.sanitized_path(options["source"], "_config.#{ext}")
end
end

Expand All @@ -115,23 +111,22 @@ def to_exclude(options)
# to ignore.
def listen_ignore_paths(options)
source = Pathname.new(options["source"]).expand_path
exclusion_fnmatch_paths = Array.new()
exclusion_fnmatch_paths = []

exclusion_regexps = to_exclude(options).map do |path|
# convert to absolute path from the source directory
absolute_path = Pathname.new(path).expand_path
relative_path = absolute_path.relative_path_from(source)
relative_path = absolute_path.relative_path_from(source).to_s

unless absolute_path.exist?
if !absolute_path.exist?
# maybe wildcard, or just a file that doesn't exist.
exclusion_fnmatch_paths << relative_path.to_s
nil
nil.tap { exclusion_fnmatch_paths << relative_path }
else
relative_path = File.join(relative_path, "") if absolute_path.directory?

begin
unless relative_path.start_with?("../")
Regexp.new(Regexp.escape(relative_path)).tap do |pattern|
%r!^#{Regexp.escape(relative_path)}!.tap do |pattern|
Jekyll.logger.debug "Watcher:", "Ignoring #{pattern}"
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/watcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
require "spec_helper"

describe(Jekyll::Watcher) do
Expand Down Expand Up @@ -97,7 +98,7 @@
end

context "#listen_ignore_paths" do
let(:ignored) { subject.send(:listen_ignore_paths, options) }
let(:ignored) { subject.send(:listen_ignore_paths, options)[0] }
let(:metadata_path) { Jekyll.sanitized_path(options["source"], ".jekyll-metadata") }

before(:each) { FileUtils.touch(metadata_path) }
Expand Down

0 comments on commit 45f1dfe

Please sign in to comment.