From 49b27767aac1786ea08fbbcce509f2ec2a19c388 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Wed, 17 Jul 2024 18:59:02 +0200 Subject: [PATCH] download_strategy: fix UID handling for Git submodules Source builds that use Git checkouts with submodules can choke when the process UID does not match its EUID. We can fix this by using the `reset_uid` option added in #17782. --- Library/Homebrew/download_strategy.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 7f9f275d0e..b74815b2e6 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -1040,13 +1040,15 @@ class GitDownloadStrategy < VCSDownloadStrategy sig { params(timeout: T.nilable(Time)).void } def update_submodules(timeout: nil) command! "git", - args: ["submodule", "foreach", "--recursive", "git submodule sync"], - chdir: cached_location, - timeout: Utils::Timer.remaining(timeout) + args: ["submodule", "foreach", "--recursive", "git submodule sync"], + chdir: cached_location, + timeout: Utils::Timer.remaining(timeout), + reset_uid: true command! "git", - args: ["submodule", "update", "--init", "--recursive"], - chdir: cached_location, - timeout: Utils::Timer.remaining(timeout) + args: ["submodule", "update", "--init", "--recursive"], + chdir: cached_location, + timeout: Utils::Timer.remaining(timeout), + reset_uid: true fix_absolute_submodule_gitdir_references! end @@ -1059,8 +1061,9 @@ class GitDownloadStrategy < VCSDownloadStrategy # See https://github.com/Homebrew/homebrew-core/pull/1520 for an example. def fix_absolute_submodule_gitdir_references! submodule_dirs = command!("git", - args: ["submodule", "--quiet", "foreach", "--recursive", "pwd"], - chdir: cached_location).stdout + args: ["submodule", "--quiet", "foreach", "--recursive", "pwd"], + chdir: cached_location, + reset_uid: true).stdout submodule_dirs.lines.map(&:chomp).each do |submodule_dir| work_dir = Pathname.new(submodule_dir)