summaryrefslogtreecommitdiff
path: root/src/other_tools/git_operations/git_operations.cpp
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-08-19 16:01:16 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-08-26 12:12:00 +0200
commitc889b852a652115f4a6936a96ebdee9410571997 (patch)
treee553f21acab38fc4466adda19a378952df6a7eb6 /src/other_tools/git_operations/git_operations.cpp
parenta312e71b59340f7b6d8dc5aac9202137ae81d02b (diff)
downloadjustbuild-c889b852a652115f4a6936a96ebdee9410571997.tar.gz
GitOps: Pass source directory to GitInitialCommit operation
While there, ensure optional Git operation parameters are checked before use for the operations that require them.
Diffstat (limited to 'src/other_tools/git_operations/git_operations.cpp')
-rw-r--r--src/other_tools/git_operations/git_operations.cpp38
1 files changed, 34 insertions, 4 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!",