From 35e180b590c8af7c96864c14bbb170fe717c688d Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 16 Jun 2026 16:01:47 +0900 Subject: [PATCH] Apply exclude patterns when shoveling into FileList FileList#<< pushed the new entry after resolve and never ran it through excluded_from_list?, so a name added after #exclude (or one matching a default ignore pattern such as core or *.bak) leaked into the list while #include correctly dropped it. Filter the appended name so #<< shares the same exclusion semantics as #include, which also means default ignore patterns now apply to shoveled entries. https://github.com/ruby/rake/issues/637 Co-Authored-By: Claude Opus 4.8 (1M context) --- lib/rake/file_list.rb | 3 ++- test/test_rake_file_list.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/rake/file_list.rb b/lib/rake/file_list.rb index 76078d269..757f30a5f 100644 --- a/lib/rake/file_list.rb +++ b/lib/rake/file_list.rb @@ -202,7 +202,8 @@ def *(other) def <<(obj) resolve - @items << Rake.from_pathname(obj) + fn = Rake.from_pathname(obj) + @items << fn unless excluded_from_list?(fn) self end diff --git a/test/test_rake_file_list.rb b/test/test_rake_file_list.rb index 45f695d4f..fe01bf182 100644 --- a/test/test_rake_file_list.rb +++ b/test/test_rake_file_list.rb @@ -100,6 +100,21 @@ def test_append_pathname assert_equal ["a.rb"], fl end + def test_append_respects_exclude + fl = FileList.new + fl.exclude("abc.c") + fl << "abc.c" + assert_equal [], fl.to_a + end + + def test_append_respects_default_ignore_patterns + fl = FileList.new + fl << "core" + fl << "x.bak" + fl << "keep.rb" + assert_equal ["keep.rb"], fl.to_a + end + def test_add_many fl = FileList.new fl.include %w(a d c)