diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-02-20 12:00:57 +0100 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2024-02-20 17:18:10 +0100 |
commit | a7cc305a3a6e2886a4f7ec7b8fd9943ff45f286d (patch) | |
tree | 544d491293fae297478f959ad84be731f469b02d /src/other_tools/just_mr/update.cpp | |
parent | ca54778751856d77f7da2dba051c473a488f7d1e (diff) | |
download | justbuild-a7cc305a3a6e2886a4f7ec7b8fd9943ff45f286d.tar.gz |
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.
Diffstat (limited to 'src/other_tools/just_mr/update.cpp')
-rw-r--r-- | src/other_tools/just_mr/update.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
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<Configuration> const& config, return kExitUpdateError; } // gather repos to update - std::vector<std::pair<std::string, std::string>> repos_to_update{}; + std::vector<RepoDescriptionForUpdating> 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<Configuration> 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<std::string> 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, |