diff --git a/docs/cli.md b/docs/cli.md index e3110d9821a..f77d2f851e7 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -303,6 +303,7 @@ You can do this using the `add` command. * `--dry-run` : Outputs the operations but will not execute anything (implicitly enables --verbose). * `--no-dev` : Do not update the development dependencies. (**Deprecated**, use `--only main` or `--without dev` instead) * `--lock` : Do not perform install (only update the lockfile). +* `--sync`: Synchronize the environment with the locked packages and the specified groups. {{% note %}} When `--only` is specified, `--with` and `--without` options are ignored. diff --git a/src/poetry/console/commands/update.py b/src/poetry/console/commands/update.py index 57b173000a9..59c17caaa9b 100644 --- a/src/poetry/console/commands/update.py +++ b/src/poetry/console/commands/update.py @@ -23,6 +23,12 @@ class UpdateCommand(InstallerCommand): "Do not update the development dependencies." " (Deprecated)", ), + option( + "sync", + None, + "Synchronize the environment with the locked packages and the specified" + " groups.", + ), option( "dry-run", None, @@ -41,6 +47,7 @@ def handle(self) -> int: self.installer.only_groups(self.activated_groups) self.installer.dry_run(self.option("dry-run")) + self.installer.requires_synchronization(self.option("sync")) self.installer.execute_operations(not self.option("lock")) # Force update diff --git a/tests/console/commands/test_update.py b/tests/console/commands/test_update.py index b8b2e06684b..6b48071d612 100644 --- a/tests/console/commands/test_update.py +++ b/tests/console/commands/test_update.py @@ -4,10 +4,13 @@ import pytest +from poetry.console.commands.update import UpdateCommand from tests.helpers import get_package if TYPE_CHECKING: + from pytest_mock import MockerFixture + from poetry.poetry import Poetry from tests.helpers import TestRepository from tests.types import CommandTesterFactory @@ -80,3 +83,20 @@ def test_update_prints_operations( assert ("Package operations:" in output) is expected assert ("Installing docker (4.3.1)" in output) is expected + + +def test_update_sync_option_is_passed_to_the_installer( + poetry_with_outdated_lockfile: Poetry, + command_tester_factory: CommandTesterFactory, + mocker: MockerFixture, +) -> None: + """ + The --sync option is passed properly to the installer from update. + """ + tester = command_tester_factory("update", poetry=poetry_with_outdated_lockfile) + assert isinstance(tester.command, UpdateCommand) + mocker.patch.object(tester.command.installer, "run", return_value=1) + + tester.execute("--sync") + + assert tester.command.installer._requires_synchronization