]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Don't use configured default value when empty string is assigned
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 27 Oct 2023 09:19:27 +0000 (11:19 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 27 Oct 2023 12:14:01 +0000 (14:14 +0200)
Currently, if a setting is assigned the empty string on the CLI, any
default value configured in the config file is still used. Let's change
this and not use any configured default value when the empty string is
assigned so that default values configured in config files can be
overridden from the CLI.

mkosi/config.py
tests/test_config.py

index 29d8a76f5074e1855ad081bf66a275c80e018998..6f3320b23432d2ff576d1f0c85862abd54349099 100644 (file)
@@ -2216,7 +2216,8 @@ def parse_config(argv: Sequence[str] = ()) -> tuple[MkosiArgs, tuple[MkosiConfig
         for d in setting.default_factory_depends:
             finalize_default(SETTINGS_LOOKUP_BY_DEST[d], namespace, defaults)
 
-        if setting.dest in defaults:
+        # If the setting was assigned the empty string, we don't use any configured default value.
+        if not hasattr(namespace, setting.dest) and setting.dest in defaults:
             default = getattr(defaults, setting.dest)
         elif setting.default_factory:
             default = setting.default_factory(namespace)
index 6c57a8d2669870b55dafdfe32c32a05dae90a087..ffa9625c4adc60f720a05f22f609866b919dc8ea 100644 (file)
@@ -252,6 +252,22 @@ def test_profiles(tmp_path: Path) -> None:
     assert config.qemu_kvm == ConfigFeature.enabled
 
 
+def test_override_default(tmp_path: Path) -> None:
+    d = tmp_path
+
+    (d / "mkosi.conf").write_text(
+        """\
+        [Host]
+        @ToolsTree=default
+        """
+    )
+
+    with chdir(d):
+        _, [config] = parse_config(["--tools-tree", ""])
+
+    assert config.tools_tree is None
+
+
 def test_parse_load_verb(tmp_path: Path) -> None:
     with chdir(tmp_path):
         assert parse_config(["build"])[0].verb == Verb.build