diff --git a/src/poetry/console/commands/config.py b/src/poetry/console/commands/config.py index 8ccc50b938c..ed8cf60811e 100644 --- a/src/poetry/console/commands/config.py +++ b/src/poetry/console/commands/config.py @@ -348,6 +348,12 @@ def _migrate(self) -> None: from poetry.toml.file import TOMLFile config_file = TOMLFile(CONFIG_DIR / "config.toml") + + if self.option("local"): + config_file = TOMLFile(self.poetry.file.path.parent / "poetry.toml") + if not config_file.exists(): + raise RuntimeError("No local config file found") + config_source = FileConfigSource(config_file) for migration in CONFIG_MIGRATIONS: diff --git a/tests/console/commands/test_config.py b/tests/console/commands/test_config.py index 9661f09c1c4..506351eebf9 100644 --- a/tests/console/commands/test_config.py +++ b/tests/console/commands/test_config.py @@ -24,6 +24,7 @@ from pytest_mock import MockerFixture from poetry.config.dict_config_source import DictConfigSource + from poetry.poetry import Poetry from tests.types import CommandTesterFactory from tests.types import FixtureDirGetter from tests.types import ProjectFactory @@ -590,3 +591,36 @@ def test_config_migrate( with config_file.open("r") as fh: assert fh.read() == expected_config + + +def test_config_migrate_local_config(tester: CommandTester, poetry: Poetry) -> None: + local_config = poetry.file.path.parent / "poetry.toml" + config_data = textwrap.dedent("""\ + [experimental] + system-git-client = true + + [virtualenvs] + prefer-active-python = false + """) + + with local_config.open("w") as fh: + fh.write(config_data) + + tester.execute("--migrate --local") + + expected_config = textwrap.dedent("""\ + system-git-client = true + + [virtualenvs] + use-poetry-python = true + """) + + with local_config.open("r") as fh: + assert fh.read() == expected_config + + +def test_config_migrate_local_config_should_raise_if_not_found( + tester: CommandTester, +) -> None: + with pytest.raises(RuntimeError, match="No local config file found"): + tester.execute("--migrate --local")