Skip to content

Commit 134472f

Browse files
committed
fix(render): only expose _copier_operation within an active operationEOF
git log --oneline -2
1 parent 04da30f commit 134472f

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

copier/_main.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,20 @@ def _render_context(self) -> AnyByStrMutableMapping:
461461
"os": lambda: OS,
462462
}
463463
)
464-
return dict(
464+
context = dict(
465465
**self.answers.combined,
466466
_copier_answers=self._answers_to_remember(),
467467
_copier_conf=conf,
468468
_folder_name=self.subproject.local_abspath.name,
469469
_copier_python=sys.executable,
470470
_copier_phase=Phase.current(),
471-
_copier_operation=_operation.get(),
472471
)
472+
# ``_copier_operation`` is only defined within a copy/update/recopy run.
473+
# Outside of one (e.g. ``check_update`` or other bare-``Worker`` use),
474+
# leave it unset so rendering doesn't require an active operation.
475+
if (operation := _operation.get(None)) is not None:
476+
context["_copier_operation"] = operation
477+
return context
473478

474479
def _path_matcher(self, patterns: Iterable[str]) -> Callable[[Path], bool]:
475480
"""Produce a function that matches against specified patterns."""

0 commit comments

Comments
 (0)