summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-04-04 16:36:48 +0200
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-04-10 15:25:14 +0200
commitd3ec6b7294d44e1cd524ac5bbb9048d415950e99 (patch)
tree373735cc6edf9f78312c352aa3030742a42e22ac /test
parent4fe5fc8aec6e391a5e300e234bdc41375bff1d9e (diff)
downloadjustbuild-d3ec6b7294d44e1cd524ac5bbb9048d415950e99.tar.gz
GitRepo: Add method to keep tree alive by tagging
Also adds an appropriate test for this method.
Diffstat (limited to 'test')
-rw-r--r--test/buildtool/file_system/TARGETS1
-rw-r--r--test/buildtool/file_system/git_repo.test.cpp30
2 files changed, 31 insertions, 0 deletions
diff --git a/test/buildtool/file_system/TARGETS b/test/buildtool/file_system/TARGETS
index 8121b39a..e63bb06d 100644
--- a/test/buildtool/file_system/TARGETS
+++ b/test/buildtool/file_system/TARGETS
@@ -123,6 +123,7 @@
, ["@", "src", "src/buildtool/logging", "log_level"]
, ["@", "src", "src/buildtool/logging", "logging"]
, ["@", "src", "src/utils/cpp", "atomic"]
+ , ["@", "src", "src/utils/cpp", "hex_string"]
, ["utils", "shell_quoting"]
]
, "stage": ["test", "buildtool", "file_system"]
diff --git a/test/buildtool/file_system/git_repo.test.cpp b/test/buildtool/file_system/git_repo.test.cpp
index a6edfc8a..67ad19cd 100644
--- a/test/buildtool/file_system/git_repo.test.cpp
+++ b/test/buildtool/file_system/git_repo.test.cpp
@@ -31,6 +31,7 @@
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/utils/cpp/atomic.hpp"
+#include "src/utils/cpp/hex_string.hpp"
#include "test/utils/shell_quoting.hpp"
namespace {
@@ -44,6 +45,9 @@ auto const kBazId = std::string{"1868f82682c290f0b1db3cacd092727eef1fa57f"};
auto const kFooId = std::string{"19102815663d23f8b75a47e7a01965dcdc96468c"};
auto const kBarId = std::string{"ba0e162e1c47469e3fe4b393a8bf8c569f302116"};
+auto const kFooBarTreeId =
+ std::string{"27b32561185c2825150893774953906c6daa6798"};
+
} // namespace
class TestUtils {
@@ -240,6 +244,32 @@ TEST_CASE("Single-threaded real repository local operations", "[git_repo]") {
CHECK(repo_fetch_branch->FetchFromPath(
nullptr, *path_fetch_branch, "master", logger));
}
+
+ SECTION("Tag tree") {
+ auto repo_tag_path = TestUtils::CreateTestRepo(true);
+ REQUIRE(repo_tag_path);
+ auto repo_tag = GitRepo::Open(*repo_tag_path);
+ REQUIRE(repo_tag);
+ CHECK_FALSE(repo_tag->IsRepoFake());
+
+ // tag tree already root of a commit
+ CHECK(repo_tag->KeepTree(kRootId, "test tag 1", logger));
+
+ // tag tree part of another commit
+ CHECK(repo_tag->KeepTree(kBazId, "test tag 2", logger));
+
+ // tag uncommitted tree
+ auto foo_bar = GitRepo::tree_entries_t{
+ {FromHexString(kFooId).value_or<std::string>({}),
+ {GitRepo::tree_entry_t{"foo", ObjectType::File}}},
+ {FromHexString(kBarId).value_or<std::string>({}),
+ {GitRepo::tree_entry_t{"bar", ObjectType::Executable}}}};
+ auto foo_bar_id = repo_tag->CreateTree(foo_bar);
+ REQUIRE(foo_bar_id);
+ auto tree_id = ToHexString(*foo_bar_id);
+ CHECK(tree_id == kFooBarTreeId);
+ CHECK(repo_tag->KeepTree(tree_id, "test tag 3", logger));
+ }
}
// NOTE: "fake" repo ops tests split into two batches as workaround for