Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/jekyll/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ 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))
unless relative_path.start_with?('../')
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 + [%r!\.jekyll\-metadata!]
end.compact + [%r!^\.jekyll\-metadata!]
end

def sleep_forever
Expand Down
27 changes: 16 additions & 11 deletions spec/watcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

let(:options) { base_opts }
let(:site) { instance_double(Jekyll::Site) }
let(:default_ignored) { [%r!_config\.yml!, %r!_site!, %r!\.jekyll\-metadata!] }
let(:default_ignored) { [%r!^_config\.yml!, %r!^_site!, %r!^\.jekyll\-metadata!] }
subject { described_class }
before(:each) do
FileUtils.mkdir(options["destination"]) if options["destination"]
Expand Down Expand Up @@ -110,22 +110,27 @@
end

context "with something excluded" do
let(:excluded) { ["README.md", "LICENSE"] }
let(:excluded_absolute) do
excluded.map { |p| Jekyll.sanitized_path(options["source"], p) }
end
let(:options) { base_opts.merge("exclude" => excluded) }
before(:each) { FileUtils.touch(excluded_absolute) }
after(:each) { FileUtils.rm(excluded_absolute) }
let(:excluded) { ['README.md', 'LICENSE'] }
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(test_files) }
after(:each) { FileUtils.rm(test_files) }

it "ignores the excluded files" do
expect(ignored).to include(%r!README\.md!)
expect(ignored).to include(%r!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

context "with a custom destination" do
let(:default_ignored) { [%r!_config\.yml!, %r!_dest!, %r!\.jekyll\-metadata!] }
let(:default_ignored) { [%r!^_config\.yml!, %r!^_dest!, %r!^\.jekyll\-metadata!] }

context "when source is absolute" do
context "when destination is absolute" do
Expand Down