Skip to content

Commit a0b4e1a

Browse files
DaanDeMeyerbehrmann
authored andcommitted
Make sure git doesn't fail when running as root
We have to mark the .git directory we're checking as safe otherwise git operate on it.
1 parent 585a477 commit a0b4e1a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

mkosi/config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,9 +1484,13 @@ def config_parse_minimum_version(value: Optional[str], old: Optional[str]) -> Op
14841484
if not (gitdir / ".git").exists():
14851485
die("Cannot check mkosi git version, not running mkosi from a git repository")
14861486

1487-
current = run(["git", "-C", gitdir, "rev-parse", "HEAD"], stdout=subprocess.PIPE).stdout.strip()
1487+
git: list[PathString] = ["git", "-C", gitdir]
1488+
if os.getuid() == 0:
1489+
git += ["-c", f"safe.directory={gitdir}"]
14881490

1489-
result = run(["git", "-C", gitdir, "merge-base", "--is-ancestor", hash, current], check=False)
1491+
current = run([*git, "rev-parse", "HEAD"], stdout=subprocess.PIPE).stdout.strip()
1492+
1493+
result = run([*git, "merge-base", "--is-ancestor", hash, current], check=False)
14901494
if result.returncode == 1:
14911495
die(
14921496
f"mkosi commit {hash} or newer is required by this configuration",

0 commit comments

Comments
 (0)