From 1be2434c692b2277e660cd3204e63653a4ce71ab Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Sat, 7 May 2022 20:58:38 +0200 Subject: [PATCH] Run git operations as user running mkosi 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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index c24052095..b9777f361 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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 -- 2.47.2