]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Require MinimumVersion= commit sha to be prefixed with commit:
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 8 Apr 2025 11:35:13 +0000 (13:35 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 8 Apr 2025 12:17:02 +0000 (14:17 +0200)
mkosi/config.py
mkosi/resources/man/mkosi.1.md

index 15bf568f28a5659eff96a5cb01fb0f08a4993de5..565a2d3e0068b47193c70ead89af458fa8b28d96 100644 (file)
@@ -1467,17 +1467,22 @@ def config_parse_minimum_version(value: Optional[str], old: Optional[str]) -> Op
     if not value:
         return old
 
-    if len(value) == 40 and all(c.isalnum() for c in value):
+    if hash := startswith(value, "commit:"):
         if not in_sandbox():
             gitdir = Path(__file__).parent.parent
             if not (gitdir / ".git").exists():
-                die("Cannot check mkosi git version, not running from a git repository")
+                die("Cannot check mkosi git version, not running mkosi from a git repository")
 
-            result = run(["git", "-C", gitdir, "merge-base", "--is-ancestor", value, "HEAD"], check=False)
+            current = run(["git", "-C", gitdir, "rev-parse", "HEAD"], stdout=subprocess.PIPE).stdout.strip()
+
+            result = run(["git", "-C", gitdir, "merge-base", "--is-ancestor", hash, current], check=False)
             if result.returncode == 1:
-                die(f"mkosi commit {value} or newer is required by this configuration")
+                die(
+                    f"mkosi commit {hash} or newer is required by this configuration",
+                    hint=f"Currently checked out commit is {current}"
+                )
             elif result.returncode != 0:
-                die(f"Failed to check if mkosi git checkout is newer than commit {value}")
+                die(f"Failed to check if mkosi git checkout is newer than commit {hash}")
 
         return value
 
index 700d2588294439e7e663f58468c8a0b7563eb5e2..73d134a8e9c3d2f3da1279514e9379853aa94862 100644 (file)
@@ -2166,11 +2166,11 @@ config file is read:
 :   The minimum **mkosi** version required to build this configuration. If
     specified multiple times, the highest specified version is used.
 
-    The minimum version can also be specified as a unabbreviated git
-    commit hash, in which case mkosi must be executed from a git
-    checkout and the specified git commit hash must be an ancestor of
-    the currently checked out git commit in the repository that mkosi is
-    being executed from.
+    The minimum version can also be specified as a git commit hash when
+    prefixed with `commit:`, in which case mkosi must be executed from a
+    git checkout and the specified git commit hash must be an ancestor
+    of the currently checked out git commit in the repository that mkosi
+    is being executed from.
 
 `ConfigureScripts=`, `--configure-script=`
 :   Takes a comma-separated list of paths to executables that are used as