Skip to content

Commit

Permalink
fix(exclude): apply exclude matcher to rendered path
Browse files Browse the repository at this point in the history
  • Loading branch information
sisp committed Feb 8, 2024
1 parent 5aa0273 commit 934dedd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion copier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
25 changes: 25 additions & 0 deletions tests/test_exclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 934dedd

Please sign in to comment.