MCPcopy
hub / github.com/copier-org/copier / run_update

Method run_update

copier/_main.py:1304–1353  ·  view source on GitHub ↗

Update a subproject that was already generated. See [updating a project][updating-a-project].

(self)

Source from the content-addressed store, hash-verified

1302
1303 @as_operation("update")
1304 def run_update(self) -> None:
1305 """Update a subproject that was already generated.
1306
1307 See [updating a project][updating-a-project].
1308 """
1309 self._check_unsafe("update")
1310 # Check all you need is there
1311 if self.subproject.vcs != "git":
1312 raise UserMessageError(
1313 "Updating is only supported in git-tracked subprojects."
1314 )
1315 if self.subproject.is_dirty():
1316 raise UserMessageError(
1317 "Destination repository is dirty; cannot continue. "
1318 "Please commit or stash your local changes and retry."
1319 )
1320 if self.subproject.template is None or self.subproject.template.ref is None:
1321 raise UserMessageError(
1322 "Cannot update because cannot obtain old template references "
1323 f"from `{self.subproject.answers_relpath}`."
1324 )
1325 if self.template.commit is None:
1326 raise UserMessageError(
1327 "Updating is only supported in git-tracked templates."
1328 )
1329 if not self.subproject.template.version:
1330 raise UserMessageError(
1331 "Cannot update: version from last update not detected."
1332 )
1333 if not self.template.version:
1334 raise UserMessageError("Cannot update: version from template not detected.")
1335 if self.subproject.template.version > self.template.version:
1336 raise UserMessageError(
1337 f"You are downgrading from {self.subproject.template.version} to {self.template.version}. "
1338 "Downgrades are not supported."
1339 )
1340 if not self.overwrite:
1341 # Only git-tracked subprojects can be updated, so the user can
1342 # review the diff before committing; so we can safely avoid
1343 # asking for confirmation
1344 raise UserMessageError("Enable overwrite to update a subproject.")
1345 self._print_message(self.template.message_before_update)
1346 self._print_template_update_info(self.subproject.template)
1347 with suppress(AttributeError):
1348 # We might have switched operation context, ensure the cached property
1349 # is regenerated to re-render templates.
1350 del self.match_exclude
1351
1352 self._apply_update()
1353 self._print_message(self.template.message_after_update)
1354
1355 def _apply_update(self) -> None: # noqa: C901
1356 git = get_git()

Calls 6

_check_unsafeMethod · 0.95
_print_messageMethod · 0.95
_apply_updateMethod · 0.95
UserMessageErrorClass · 0.85
is_dirtyMethod · 0.80