From a7cc305a3a6e2886a4f7ec7b8fd9943ff45f286d Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 20 Feb 2024 12:00:57 +0100 Subject: git repo fetch: support "inherit env" When fetching git repositories, just-mr routinely shells out to git. In this case, allow the user to specify via "inherit env", which environment variables from the host environment should be made available in this action. Typical variables to inherit are ones providing credentials, like SSH_AUTH_SOCK. As the repository description specifies the commit that will be taken, and hence the resulting tree, correctness is not affected by the environement leaking in here. --- src/other_tools/just_mr/update.cpp | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'src/other_tools/just_mr/update.cpp') diff --git a/src/other_tools/just_mr/update.cpp b/src/other_tools/just_mr/update.cpp index 885f5421..a768e0e0 100644 --- a/src/other_tools/just_mr/update.cpp +++ b/src/other_tools/just_mr/update.cpp @@ -56,7 +56,7 @@ auto MultiRepoUpdate(std::shared_ptr const& config, return kExitUpdateError; } // gather repos to update - std::vector> repos_to_update{}; + std::vector repos_to_update{}; repos_to_update.reserve(update_args.repos_to_update.size()); for (auto const& repo_name : update_args.repos_to_update) { auto repo_desc_parent = repos->At(repo_name); @@ -142,9 +142,33 @@ auto MultiRepoUpdate(std::shared_ptr const& config, nlohmann::json(repo_name).dump()); return kExitUpdateError; } - repos_to_update.emplace_back( - std::make_pair(repo_desc_repository->get()->String(), - repo_desc_branch->get()->String())); + std::vector inherit_env{}; + auto repo_desc_inherit_env = + (*resolved_repo_desc) + ->Get("inherit env", Expression::kEmptyList); + if (not repo_desc_inherit_env->IsList()) { + Logger::Log(LogLevel::Error, + "GitCheckout: optional field \"inherit env\" " + "should be a list of strings, but found {}", + repo_desc_inherit_env->ToString()); + return kExitUpdateError; + } + for (auto const& var : repo_desc_inherit_env->List()) { + if (not var->IsString()) { + Logger::Log( + LogLevel::Error, + "GitCheckout: optional field \"inherit env\" " + "should be a list of strings, but found entry {}", + var->ToString()); + return kExitUpdateError; + } + inherit_env.emplace_back(var->String()); + } + + repos_to_update.emplace_back(RepoDescriptionForUpdating{ + .repo = repo_desc_repository->get()->String(), + .branch = repo_desc_branch->get()->String(), + .inherit_env = inherit_env}); } else { Logger::Log(LogLevel::Error, -- cgit v1.2.3