Skip to content

Commit 01146fc

Browse files
chmltnclaude
andauthored
Fix merged filter patterns being discarded during per-folder config init (#17)
In load_for_directory and merge_with, merged patterns were passed via legacy exclude/include fields, but __post_init__ overwrites those from mode-specific lists (which were empty). This caused .git/, node_modules/ and other excluded paths to be indexed for any directory with a .cosmaconfig. Populate the correct mode-specific fields instead so _sync_legacy_fields preserves merged patterns. Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a8faf13 commit 01146fc

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

packages/cosma-backend/src/cosma_backend/filter/filter_config.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,21 @@ def load_for_directory(cls, directory: Path, global_config: Optional[FilterConfi
587587
if pattern not in merged_include:
588588
merged_include.append(pattern)
589589

590-
merged = cls(
591-
mode=global_config.mode, # Mode always from global
592-
exclude=merged_exclude,
593-
include=merged_include,
594-
config_path=folder_config_path,
595-
)
590+
# Populate mode-specific fields so __post_init__ preserves them
591+
if global_config.mode == FilterMode.BLACKLIST:
592+
merged = cls(
593+
mode=global_config.mode,
594+
blacklist_exclude=merged_exclude,
595+
blacklist_include=merged_include,
596+
config_path=folder_config_path,
597+
)
598+
else:
599+
merged = cls(
600+
mode=global_config.mode,
601+
whitelist_exclude=merged_exclude,
602+
whitelist_include=merged_include,
603+
config_path=folder_config_path,
604+
)
596605

597606
logger.info("Merged filter config for directory",
598607
directory=str(directory),
@@ -626,12 +635,21 @@ def merge_with(self, other: FilterConfig) -> FilterConfig:
626635
if pattern not in merged_include:
627636
merged_include.append(pattern)
628637

629-
return FilterConfig(
630-
mode=self.mode,
631-
exclude=merged_exclude,
632-
include=merged_include,
633-
config_path=other.config_path or self.config_path,
634-
)
638+
# Populate mode-specific fields so __post_init__ preserves them
639+
if self.mode == FilterMode.BLACKLIST:
640+
return FilterConfig(
641+
mode=self.mode,
642+
blacklist_exclude=merged_exclude,
643+
blacklist_include=merged_include,
644+
config_path=other.config_path or self.config_path,
645+
)
646+
else:
647+
return FilterConfig(
648+
mode=self.mode,
649+
whitelist_exclude=merged_exclude,
650+
whitelist_include=merged_include,
651+
config_path=other.config_path or self.config_path,
652+
)
635653

636654

637655
class FilterConfigManager:

0 commit comments

Comments
 (0)