diff --git a/copier/main.py b/copier/main.py index 3d90e853f..499cd95d4 100644 --- a/copier/main.py +++ b/copier/main.py @@ -675,7 +675,7 @@ def _render_path(self, relpath: Path) -> Optional[Path]: rendered_parts.append(part) result = Path(*rendered_parts) # Skip excluded paths. - if result != Path(".") and self.match_exclude(relpath): + if result != Path(".") and self.match_exclude(result): return None if not is_template: templated_sibling = ( diff --git a/tests/test_exclude.py b/tests/test_exclude.py index 4a1faaae8..73867f0d5 100644 --- a/tests/test_exclude.py +++ b/tests/test_exclude.py @@ -205,3 +205,28 @@ def test_config_exclude_file_with_bad_jinja_syntax_without_templates_suffix( run_copy(str(src), dst, quiet=True) assert not (dst / "copier.yml").exists() assert not (dst / "exclude-me.txt").exists() + + +def test_config_exclude_with_templated_path( + tmp_path_factory: pytest.TempPathFactory, +) -> None: + src, dst = map(tmp_path_factory.mktemp, ("src", "dst")) + build_file_tree( + { + (src / "copier.yml"): ( + """\ + _exclude: + - "*" + - "!keep-me.txt" + + filename_keep: keep-me.txt + filename_exclude: exclude-me.txt + """ + ), + (src / "{{ filename_keep }}.jinja"): "", + (src / "{{ filename_exclude }}.jinja"): "", + } + ) + run_copy(str(src), dst, defaults=True, quiet=True) + assert (dst / "keep-me.txt").exists() + assert not (dst / "exclude-me.txt").exists()