Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ignore file if file.tmpl exist in subdir #1892

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion copier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,9 @@ def _render_path(self, relpath: Path) -> Path | None:
"""
is_template = relpath.name.endswith(self.template.templates_suffix)
templated_sibling = (
self.template.local_abspath / f"{relpath}{self.template.templates_suffix}"
self.template.local_abspath
/ self._render_string(self.template.subdirectory)
/ f"{relpath}{self.template.templates_suffix}"
)
# With an empty suffix, the templated sibling always exists.
if templated_sibling.exists() and self.template.templates_suffix:
Expand Down
16 changes: 16 additions & 0 deletions tests/test_subdirectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ def template_path(tmp_path_factory: pytest.TempPathFactory) -> str:
"[[ _copier_answers|to_nice_yaml ]]"
),
(root / "conf_project" / "conf_readme.md"): (
"""\
# Template subdirectory

This is the template README.
"""
),
(root / "conf_project" / "conf_readme.md.tmpl"): (
"""\
# Demo subdirectory

Expand Down Expand Up @@ -68,6 +75,15 @@ def test_copy_subdirectory_config(template_path: str, tmp_path: Path) -> None:
assert not (tmp_path / "api_readme.md").exists()


def test_copy_subdirectory_config_no_overwrite(
template_path: str, tmp_path: Path
) -> None:
copier.run_copy(template_path, tmp_path, defaults=True, overwrite=False)
assert (tmp_path / "conf_readme.md").exists()
assert "# Demo" in (tmp_path / "conf_readme.md").read_text()
assert not (tmp_path / "api_readme.md").exists()


def test_update_subdirectory(template_path: str, tmp_path: Path) -> None:
copier.run_copy(template_path, tmp_path, defaults=True, overwrite=True)

Expand Down