summaryrefslogtreecommitdiff
path: root/src/other_tools/git_operations
diff options
context:
space:
mode:
Diffstat (limited to 'src/other_tools/git_operations')
-rw-r--r--src/other_tools/git_operations/git_repo_remote.cpp24
-rw-r--r--src/other_tools/git_operations/git_repo_remote.hpp16
2 files changed, 28 insertions, 12 deletions
diff --git a/src/other_tools/git_operations/git_repo_remote.cpp b/src/other_tools/git_operations/git_repo_remote.cpp
index cb2ff7a0..ac4bc41c 100644
--- a/src/other_tools/git_operations/git_repo_remote.cpp
+++ b/src/other_tools/git_operations/git_repo_remote.cpp
@@ -395,6 +395,7 @@ auto GitRepoRemote::UpdateCommitViaTmpRepo(
std::filesystem::path const& tmp_dir,
std::string const& repo_url,
std::string const& branch,
+ std::vector<std::string> const& inherit_env,
std::string const& git_bin,
std::vector<std::string> const& launcher,
anon_logger_ptr const& logger) const noexcept
@@ -442,11 +443,18 @@ auto GitRepoRemote::UpdateCommitViaTmpRepo(
"Git commit update for remote {} must shell out. Running:\n{}",
repo_url,
nlohmann::json(cmdline).dump());
+ std::map<std::string, std::string> env{};
+ for (auto const& k : inherit_env) {
+ const char* v = std::getenv(k.c_str());
+ if (v != nullptr) {
+ env[k] = std::string(v);
+ }
+ }
// set up the system command
SystemCommand system{repo_url};
auto const command_output =
system.Execute(cmdline,
- {}, // default env
+ env,
GetGitPath(), // which path is not actually relevant
tmp_dir);
// output file can be read anyway
@@ -510,6 +518,7 @@ auto GitRepoRemote::UpdateCommitViaTmpRepo(
auto GitRepoRemote::FetchViaTmpRepo(std::filesystem::path const& tmp_dir,
std::string const& repo_url,
std::optional<std::string> const& branch,
+ std::vector<std::string> const& inherit_env,
std::string const& git_bin,
std::vector<std::string> const& launcher,
anon_logger_ptr const& logger) noexcept
@@ -580,12 +589,17 @@ auto GitRepoRemote::FetchViaTmpRepo(std::filesystem::path const& tmp_dir,
"Git fetch for remote {} must shell out. Running:\n{}",
repo_url,
nlohmann::json(cmdline).dump());
+ std::map<std::string, std::string> env{};
+ for (auto const& k : inherit_env) {
+ const char* v = std::getenv(k.c_str());
+ if (v != nullptr) {
+ env[k] = std::string(v);
+ }
+ }
// run command
SystemCommand system{repo_url};
- auto const command_output = system.Execute(cmdline,
- {}, // caller env
- GetGitPath(),
- tmp_dir);
+ auto const command_output =
+ system.Execute(cmdline, env, GetGitPath(), tmp_dir);
if (not command_output) {
std::string out_str{};
std::string err_str{};
diff --git a/src/other_tools/git_operations/git_repo_remote.hpp b/src/other_tools/git_operations/git_repo_remote.hpp
index ce818de6..614e7822 100644
--- a/src/other_tools/git_operations/git_repo_remote.hpp
+++ b/src/other_tools/git_operations/git_repo_remote.hpp
@@ -93,6 +93,7 @@ class GitRepoRemote : public GitRepo {
std::filesystem::path const& tmp_dir,
std::string const& repo_url,
std::string const& branch,
+ std::vector<std::string> const& inherit_env,
std::string const& git_bin,
std::vector<std::string> const& launcher,
anon_logger_ptr const& logger) const noexcept
@@ -108,13 +109,14 @@ class GitRepoRemote : public GitRepo {
/// Uses either a given branch, or fetches all (with base refspecs).
/// Returns a success flag.
/// It guarantees the logger is called exactly once with fatal if failure.
- [[nodiscard]] auto FetchViaTmpRepo(std::filesystem::path const& tmp_dir,
- std::string const& repo_url,
- std::optional<std::string> const& branch,
- std::string const& git_bin,
- std::vector<std::string> const& launcher,
- anon_logger_ptr const& logger) noexcept
- -> bool;
+ [[nodiscard]] auto FetchViaTmpRepo(
+ std::filesystem::path const& tmp_dir,
+ std::string const& repo_url,
+ std::optional<std::string> const& branch,
+ std::vector<std::string> const& inherit_env,
+ std::string const& git_bin,
+ std::vector<std::string> const& launcher,
+ anon_logger_ptr const& logger) noexcept -> bool;
private:
/// \brief Open "fake" repository wrapper for existing CAS.