]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Make sure git doesn't fail when running as root
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 22 May 2025 12:26:14 +0000 (14:26 +0200)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 22 May 2025 15:32:29 +0000 (17:32 +0200)
We have to mark the .git directory we're checking as safe otherwise
git operate on it.

mkosi/config.py

index 45a4c178b808c00d06ba8c5ffe57573651d9af86..0172ebe8bfd6afb4f88a26515d05eff64b727bde 100644 (file)
@@ -1484,9 +1484,13 @@ def config_parse_minimum_version(value: Optional[str], old: Optional[str]) -> Op
             if not (gitdir / ".git").exists():
                 die("Cannot check mkosi git version, not running mkosi from a git repository")
 
-            current = run(["git", "-C", gitdir, "rev-parse", "HEAD"], stdout=subprocess.PIPE).stdout.strip()
+            git: list[PathString] = ["git", "-C", gitdir]
+            if os.getuid() == 0:
+                git += ["-c", f"safe.directory={gitdir}"]
 
-            result = run(["git", "-C", gitdir, "merge-base", "--is-ancestor", hash, current], check=False)
+            current = run([*git, "rev-parse", "HEAD"], stdout=subprocess.PIPE).stdout.strip()
+
+            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",