]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Run git operations as user running mkosi 960/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 7 May 2022 18:58:38 +0000 (20:58 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 7 May 2022 18:58:38 +0000 (20:58 +0200)
Latest git complains when executed as root on a user owned directory.
Let's run the git operations as the user running mkosi to avoid the
error.

mkosi/__init__.py

index c24052095a9452e183f34fdaebffaa80d9d41358..b9777f361926063d3cb0d1e044a7a9147200e868 100644 (file)
@@ -3604,7 +3604,9 @@ def copy_git_files(src: Path, dest: Path, *, source_file_transfer: SourceFileTra
     if source_file_transfer == SourceFileTransfer.copy_git_others:
         what_files += ["--others", "--exclude=.mkosi-*"]
 
-    c = run(["git", "-C", src, "ls-files", "-z", *what_files], stdout=PIPE, text=False)
+    uid = int(os.getenv("SUDO_UID", 0))
+
+    c = run(["git", "-C", src, "ls-files", "-z", *what_files], stdout=PIPE, text=False, user=uid)
     files = {x.decode("utf-8") for x in c.stdout.rstrip(b"\0").split(b"\0")}
 
     # Add the .git/ directory in as well.
@@ -3617,7 +3619,7 @@ def copy_git_files(src: Path, dest: Path, *, source_file_transfer: SourceFileTra
                 files.add(fr)
 
     # Get submodule files
-    c = run(["git", "-C", src, "submodule", "status", "--recursive"], stdout=PIPE, text=True)
+    c = run(["git", "-C", src, "submodule", "status", "--recursive"], stdout=PIPE, text=True, user=uid)
     submodules = {x.split()[1] for x in c.stdout.splitlines()}
 
     # workaround for git-ls-files returning the path of submodules that we will
@@ -3629,6 +3631,7 @@ def copy_git_files(src: Path, dest: Path, *, source_file_transfer: SourceFileTra
             ["git", "-C", os.path.join(src, sm), "ls-files", "-z"] + what_files,
             stdout=PIPE,
             text=False,
+            user=uid,
         )
         files |= {os.path.join(sm, x.decode("utf-8")) for x in c.stdout.rstrip(b"\0").split(b"\0")}
         files -= submodules