diff --git a/swh/web/browse/snapshot_context.py b/swh/web/browse/snapshot_context.py --- a/swh/web/browse/snapshot_context.py +++ b/swh/web/browse/snapshot_context.py @@ -740,6 +740,13 @@ browse_rev_link = gen_revision_link(revision_id) browse_snp_link = gen_snapshot_link(snapshot_id) + revision_found = True + if sha1_git is None: + try: + service.lookup_revision(revision_id) + except NotFoundExc: + revision_found = False + dir_metadata = { "directory": sha1_git, "context-independent directory": browse_dir_link, @@ -748,6 +755,7 @@ "sum of regular file sizes": sum_file_sizes, "path": dir_path, "revision": revision_id, + "revision_found": revision_found, "context-independent revision": browse_rev_link, "snapshot": snapshot_id, "context-independent snapshot": browse_snp_link, diff --git a/swh/web/templates/includes/directory-display.html b/swh/web/templates/includes/directory-display.html --- a/swh/web/templates/includes/directory-display.html +++ b/swh/web/templates/includes/directory-display.html @@ -53,6 +53,11 @@
+{% elif "revision_found" in swh_object_metadata and + swh_object_metadata.revision_found is False %} + Revision {{ swh_object_metadata.revision }} could not be found in the archive. +
+ Its associated directory can not be displayed. {% elif dirs|length == 0 and files|length == 0 %} Directory is empty {% endif %} diff --git a/swh/web/tests/browse/views/test_origin.py b/swh/web/tests/browse/views/test_origin.py --- a/swh/web/tests/browse/views/test_origin.py +++ b/swh/web/tests/browse/views/test_origin.py @@ -3,6 +3,7 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information +from datetime import datetime import random import re import string @@ -12,7 +13,11 @@ from hypothesis import given from swh.model.hashutil import hash_to_bytes -from swh.model.model import Snapshot +from swh.model.model import ( + Snapshot, + SnapshotBranch, + TargetType, +) from swh.web.browse.snapshot_context import process_snapshot_branches from swh.web.common.exc import NotFoundExc from swh.web.common.identifiers import get_swh_persistent_id @@ -34,6 +39,7 @@ revisions, origin_with_releases, release as existing_release, + unknown_revision, ) @@ -648,6 +654,39 @@ ) +@given(new_origin(), unknown_revision()) +def test_origin_browse_directory_branch_with_non_resolvable_revision( + client, archive_data, new_origin, unknown_revision +): + branch_name = "master" + snapshot = Snapshot( + branches={ + branch_name.encode(): SnapshotBranch( + target=hash_to_bytes(unknown_revision), target_type=TargetType.REVISION, + ) + } + ) + new_origin = archive_data.origin_add([new_origin])[0] + archive_data.snapshot_add([snapshot]) + visit = archive_data.origin_visit_add(new_origin["url"], datetime.now(), type="git") + archive_data.origin_visit_update( + new_origin["url"], visit.visit, status="full", snapshot=snapshot.id + ) + + url = reverse( + "browse-origin-directory", + url_args={"origin_url": new_origin["url"]}, + query_params={"branch": branch_name}, + ) + + resp = client.get(url) + + assert resp.status_code == 200 + assert_contains( + resp, f"Revision {unknown_revision } could not be found in the archive." + ) + + def _origin_content_view_test_helper( client, origin_info,