]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Check that commit exists in config_parse_minimum_version()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 28 May 2025 11:27:10 +0000 (13:27 +0200)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 29 May 2025 10:48:21 +0000 (12:48 +0200)
merge-base will blow up when given a commit that does not exist in
the checked out repository, so let's check that first before checking
whether the currently checked out commit has the minimum version one as
its ancestor.

mkosi/config.py

index 7f25484f1d038fe494c60745f9a0e43371bcd123..7a479db2bdfc4846b61a7786114cf0eb76c341d0 100644 (file)
@@ -1490,7 +1490,14 @@ def config_parse_minimum_version(value: Optional[str], old: Optional[str]) -> Op
 
             current = run([*git, "rev-parse", "HEAD"], stdout=subprocess.PIPE).stdout.strip()
 
-            result = run([*git, "merge-base", "--is-ancestor", hash, current], check=False)
+            result = run(
+                [*git, "rev-parse", "--quiet", "--verify", f"{hash}^{{commit}}"],
+                # git rev-parse seems to produce output even with --quiet added to the options.
+                stdout=subprocess.DEVNULL,
+                check=False,
+            )
+            if result.returncode == 0:
+                result = run([*git, "merge-base", "--is-ancestor", hash, current], check=False)
             if result.returncode == 1:
                 die(
                     f"mkosi commit {hash} or newer is required by this configuration",