diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-11-15 17:45:12 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-11-15 17:52:41 +0100 |
commit | 01ffd4d9a5f824a74b0e86750e9145fb623ccbcd (patch) | |
tree | a3ae5656966a96f2e87fbf8efab9c40ececae36a | |
parent | 808352e5473f90b4042370e037788d3793f4b8c3 (diff) | |
download | justbuild-01ffd4d9a5f824a74b0e86750e9145fb623ccbcd.tar.gz |
git tree repository: Creating absent roots should not run the command
Also extended absent-roots test with this scenario.
-rw-r--r-- | src/other_tools/root_maps/tree_id_git_map.cpp | 11 | ||||
-rw-r--r-- | test/end-to-end/just-mr/absent-roots.sh | 31 |
2 files changed, 41 insertions, 1 deletions
diff --git a/src/other_tools/root_maps/tree_id_git_map.cpp b/src/other_tools/root_maps/tree_id_git_map.cpp index ce2fe5e5..752f224d 100644 --- a/src/other_tools/root_maps/tree_id_git_map.cpp +++ b/src/other_tools/root_maps/tree_id_git_map.cpp @@ -96,7 +96,16 @@ auto CreateTreeIdGitMap( auto logger, auto /*unused*/, auto const& key) { - // first, check whether tree exists already in CAS + // if root is absent, no work needs to be done + if (key.absent) { + auto root = nlohmann::json::array( + {key.ignore_special ? FileRoot::kGitTreeIgnoreSpecialMarker + : FileRoot::kGitTreeMarker, + key.hash}); + (*setter)(std::pair(std::move(root), false)); + return; + } + // check whether tree exists already in CAS // ensure Git cache // define Git operation to be done GitOpKey op_key = {.params = diff --git a/test/end-to-end/just-mr/absent-roots.sh b/test/end-to-end/just-mr/absent-roots.sh index 7f3154a6..ad4846e1 100644 --- a/test/end-to-end/just-mr/absent-roots.sh +++ b/test/end-to-end/just-mr/absent-roots.sh @@ -109,4 +109,35 @@ test $(jq -r '.repositories.test.workspace_root | length' "${CONF}") = 2 # Check the tree was correctly set via 'just serve' remote test "$(jq -r '.repositories.test.workspace_root[1]' "${CONF}")" = "${GIT_ROOT_ID}" +# Now check that an absent git tree repository works without running the command +rm -rf "${LBR}" + +cat > repos.json <<EOF +{ "repositories": + { "test": + { "repository": + { "type": "git tree" + , "id": "${GIT_ROOT_ID}" + , "cmd": ["non_existent_script.sh"] + , "pragma": {"absent": true} + } + } + } +} +EOF +echo "Repository configuration:" +cat repos.json + +# Compute the repository configuration +CONF=$("${JUST_MR}" --norc --local-build-root "${LBR}" --remote-serve-address localhost:${PORT} setup) +cat "${CONF}" +echo + +# Check that an absent root was created +test "$(jq -r '.repositories.test.workspace_root[0]' "${CONF}")" = "git tree" +test $(jq -r '.repositories.test.workspace_root | length' "${CONF}") = 2 + +# Check the tree was correctly set via 'just serve' remote +test "$(jq -r '.repositories.test.workspace_root[1]' "${CONF}")" = "${GIT_ROOT_ID}" + echo OK |