diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-04-05 16:18:28 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-04-10 15:25:45 +0200 |
commit | c60eb6dfb22f28f638caff578b8815d3c4753bdc (patch) | |
tree | 86218d88394db7585377a0eb13a329101e79bd4a /src/other_tools/git_operations/git_operations.cpp | |
parent | d3ec6b7294d44e1cd524ac5bbb9048d415950e99 (diff) | |
download | justbuild-c60eb6dfb22f28f638caff578b8815d3c4753bdc.tar.gz |
Add KeepTree to critical Git operations
Also improves and extends accordingly the Git operations tests.
Diffstat (limited to 'src/other_tools/git_operations/git_operations.cpp')
-rw-r--r-- | src/other_tools/git_operations/git_operations.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/other_tools/git_operations/git_operations.cpp b/src/other_tools/git_operations/git_operations.cpp index 74f1d323..81375130 100644 --- a/src/other_tools/git_operations/git_operations.cpp +++ b/src/other_tools/git_operations/git_operations.cpp @@ -143,3 +143,37 @@ auto CriticalGitOps::GitGetHeadId(GitOpParams const& crit_op_params, // success return {.git_cas = git_repo->GetGitCAS(), .result = *head_commit}; } + +auto CriticalGitOps::GitKeepTree(GitOpParams const& crit_op_params, + AsyncMapConsumerLoggerPtr const& logger) + -> GitOpValue { + // Make sure folder we want to access exists + if (not FileSystemManager::Exists(crit_op_params.target_path)) { + (*logger)(fmt::format("target directory {} does not exist!", + crit_op_params.target_path.string()), + true /*fatal*/); + return {.git_cas = nullptr, .result = std::nullopt}; + } + // Open a GitRepo at given location + auto git_repo = GitRepoRemote::Open(crit_op_params.target_path); + if (git_repo == std::nullopt) { + (*logger)(fmt::format("could not open git repository {}", + crit_op_params.target_path.string()), + true /*fatal*/); + return {.git_cas = nullptr, .result = std::nullopt}; + } + // setup wrapped logger + auto wrapped_logger = std::make_shared<AsyncMapConsumerLogger>( + [logger](auto const& msg, bool fatal) { + (*logger)(fmt::format("While doing keep tree Git op:\n{}", msg), + fatal); + }); + // Create tag for given tree + if (not git_repo->KeepTree(crit_op_params.git_hash, + crit_op_params.message.value(), + wrapped_logger)) { + return {.git_cas = nullptr, .result = std::nullopt}; + } + // success + return {.git_cas = git_repo->GetGitCAS(), .result = ""}; +} |