diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/file_system/git_repo.cpp | 29 | ||||
-rw-r--r-- | src/buildtool/file_system/git_repo.hpp | 7 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp index 78ae1c86..2c27cda9 100644 --- a/src/buildtool/file_system/git_repo.cpp +++ b/src/buildtool/file_system/git_repo.cpp @@ -1744,6 +1744,35 @@ auto GitRepo::ImportToGit( return *std::move(result_tree); } +auto GitRepo::IsTreeInRepo(std::filesystem::path const& repo, + std::string const& tree_id) noexcept + -> expected<bool, std::string> { + auto git_cas = GitCAS::Open(repo); + if (git_cas == nullptr) { + return unexpected( + fmt::format("Failed to open Git ODB at {}", repo.string())); + } + auto git_repo = GitRepo::Open(git_cas); + if (not git_repo.has_value()) { + return unexpected{ + fmt::format("Failed to open Git repository at {}", repo.string())}; + } + + std::string err; + auto logger = std::make_shared<GitRepo::anon_logger_t>( + [&err](auto const& msg, bool fatal) { + if (fatal) { + err = msg; + } + }); + + auto result = git_repo->CheckTreeExists(tree_id, logger); + if (not result.has_value()) { + return unexpected{std::move(err)}; + } + return *result; +} + auto GitRepo::IsRepoFake() const noexcept -> bool { return is_repo_fake_; } diff --git a/src/buildtool/file_system/git_repo.hpp b/src/buildtool/file_system/git_repo.hpp index 1e403fbe..f8591d75 100644 --- a/src/buildtool/file_system/git_repo.hpp +++ b/src/buildtool/file_system/git_repo.hpp @@ -330,6 +330,13 @@ class GitRepo { gsl::not_null<std::mutex*> const& tagging_lock) noexcept -> expected<std::string, std::string>; + /// \brief Check that the given repository contains the given tree + /// \returns Flag reflecting whether the tree is present in the repository + /// or an error message on failure. + [[nodiscard]] static auto IsTreeInRepo(std::filesystem::path const& repo, + std::string const& tree_id) noexcept + -> expected<bool, std::string>; + private: GitCASPtr git_cas_; // default to real repo, as that is non-thread-safe |