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_operations.cpp38
-rw-r--r--src/other_tools/git_operations/git_ops_types.hpp15
2 files changed, 44 insertions, 9 deletions
diff --git a/src/other_tools/git_operations/git_operations.cpp b/src/other_tools/git_operations/git_operations.cpp
index bfd1d18f..5135743f 100644
--- a/src/other_tools/git_operations/git_operations.cpp
+++ b/src/other_tools/git_operations/git_operations.cpp
@@ -25,6 +25,19 @@
auto CriticalGitOps::GitInitialCommit(GitOpParams const& crit_op_params,
AsyncMapConsumerLoggerPtr const& logger)
-> GitOpValue {
+#ifndef NDEBUG
+ // Check required fields have been set
+ if (not crit_op_params.message) {
+ (*logger)("missing message for operation creating commit",
+ true /*fatal*/);
+ return {.git_cas = nullptr, .result = std::nullopt};
+ }
+ if (not crit_op_params.source_path) {
+ (*logger)("missing source_path for operation creating commit",
+ true /*fatal*/);
+ return {.git_cas = nullptr, .result = std::nullopt};
+ }
+#endif
// Create and open a GitRepoRemote at given target location
auto git_repo = GitRepoRemote::InitAndOpen(crit_op_params.target_path,
/*is_bare=*/false);
@@ -41,10 +54,11 @@ auto CriticalGitOps::GitInitialCommit(GitOpParams const& crit_op_params,
fmt::format("While doing initial commit Git op:\n{}", msg),
fatal);
});
- // Stage and commit all at the target location
- auto commit_hash = git_repo->CommitDirectory(crit_op_params.target_path,
- crit_op_params.message.value(),
- wrapped_logger);
+ // Commit all at the target directory
+ auto commit_hash =
+ git_repo->CommitDirectory(crit_op_params.source_path.value(),
+ crit_op_params.message.value(),
+ wrapped_logger);
if (commit_hash == std::nullopt) {
return {.git_cas = nullptr, .result = std::nullopt};
}
@@ -81,6 +95,14 @@ auto CriticalGitOps::GitEnsureInit(GitOpParams const& crit_op_params,
auto CriticalGitOps::GitKeepTag(GitOpParams const& crit_op_params,
AsyncMapConsumerLoggerPtr const& logger)
-> GitOpValue {
+#ifndef NDEBUG
+ // Check required fields have been set
+ if (not crit_op_params.message) {
+ (*logger)("missing message for operation tagging a commit",
+ true /*fatal*/);
+ return {.git_cas = nullptr, .result = std::nullopt};
+ }
+#endif
// 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!",
@@ -149,6 +171,14 @@ auto CriticalGitOps::GitGetHeadId(GitOpParams const& crit_op_params,
auto CriticalGitOps::GitKeepTree(GitOpParams const& crit_op_params,
AsyncMapConsumerLoggerPtr const& logger)
-> GitOpValue {
+#ifndef NDEBUG
+ // Check required fields have been set
+ if (not crit_op_params.message) {
+ (*logger)("missing message for operation keeping a tree comitted",
+ true /*fatal*/);
+ return {.git_cas = nullptr, .result = std::nullopt};
+ }
+#endif
// 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!",
diff --git a/src/other_tools/git_operations/git_ops_types.hpp b/src/other_tools/git_operations/git_ops_types.hpp
index 3dfdd4a8..2c60b086 100644
--- a/src/other_tools/git_operations/git_ops_types.hpp
+++ b/src/other_tools/git_operations/git_ops_types.hpp
@@ -28,16 +28,21 @@ struct GitOpParams {
std::filesystem::path target_path{}; /*key*/
std::string git_hash{}; /*key*/
std::optional<std::string> message{
- std::nullopt}; // useful for commits and tags
+ std::nullopt}; // mandatory for commits and tags
+ std::optional<std::filesystem::path> source_path{
+ std::nullopt}; // mandatory for commits
std::optional<bool> init_bare{std::nullopt}; // useful for git init
- GitOpParams(std::filesystem::path const& target_path_,
- std::string git_hash_,
- std::optional<std::string> message_ = std::nullopt,
- std::optional<bool> init_bare_ = std::nullopt)
+ GitOpParams(
+ std::filesystem::path const& target_path_,
+ std::string git_hash_,
+ std::optional<std::string> message_ = std::nullopt,
+ std::optional<std::filesystem::path> source_path_ = std::nullopt,
+ std::optional<bool> init_bare_ = std::nullopt)
: target_path{std::filesystem::absolute(ToNormalPath(target_path_))},
git_hash{std::move(git_hash_)},
message{std::move(message_)},
+ source_path{std::move(source_path_)},
init_bare{init_bare_} {};
[[nodiscard]] auto operator==(GitOpParams const& other) const noexcept