From 09961788e3279d1048f4261454260840cb675c95 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Sun, 8 Dec 2024 21:15:12 +0100 Subject: [PATCH] fix: copy only subdir when base template is not in the root of the repo --- otterdog/jsonnet.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/otterdog/jsonnet.py b/otterdog/jsonnet.py index 1a32c627..4095355c 100644 --- a/otterdog/jsonnet.py +++ b/otterdog/jsonnet.py @@ -355,7 +355,26 @@ async def _init_base_template(self) -> None: await rmtree(f"{self.org_dir}/vendor") # copy over the cloned template repository - await copytree(template_dir, self.template_dir, ignore=ignore_patterns(".git")) + base_template_directory = os.path.dirname(self.base_template_file_name) + if len(base_template_directory) > 0: + # if the base template is in a subdir, only copy this subdir + pattern = f"{base_template_directory}/**" + + def _include_pattern(path, names): + from pathlib import PurePath + + ignored_names = [] + for name in names: + p = PurePath(os.path.join(path, name)) + relative_path = p.relative_to(template_dir) + if not base_template_directory.startswith(str(relative_path)) and not p.match(pattern): + ignored_names.append(name) + return set(ignored_names) + + ignore = _include_pattern + else: + ignore = ignore_patterns(".git") + await copytree(template_dir, self.template_dir, ignore=ignore) def __repr__(self) -> str: return f"JsonnetConfig('{self.base_dir}, '{self._base_template_file}')"