This commit is contained in:
hkoziak 2025-03-25 09:49:29 +02:00
parent ad4d56e607
commit aa01e0b83d
3 changed files with 32 additions and 2 deletions

View file

@ -155,3 +155,26 @@ class TestGetRepoChangeset(object):
response = api_call(self.app, params)
expected = "commit_id must be a string value got <class 'int'> instead"
assert_error(id_, expected, given=response.body)
@pytest.mark.parametrize("details", ["basic", "extended", "full"])
def test_get_repo_changeset_empty_revs(self, details, backend_svn):
"""
Test case for repositories with empty revisions.
Ensures that no crashes occur and an empty list is returned.
"""
empty_rev_id = "1000"
__, params = build_data(
self.apikey,
"get_repo_changesets",
repoid=backend_svn.repo_name,
start_rev=empty_rev_id,
limit=10,
details=details,
)
response = api_call(self.app, params)
result = response.json["result"]
assert isinstance(result, list)
assert len(result) == 0

View file

@ -43,7 +43,7 @@ from rhodecode.lib.utils2 import str2bool, time_to_datetime, safe_str, safe_int
from rhodecode.lib.ext_json import json
from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError, CommentVersionMismatch
from rhodecode.lib.vcs import RepositoryError
from rhodecode.lib.vcs.exceptions import NodeDoesNotExistError
from rhodecode.lib.vcs.exceptions import NodeDoesNotExistError, EmptyRepositoryError
from rhodecode.model.changeset_status import ChangesetStatusModel
from rhodecode.model.comment import CommentsModel
from rhodecode.model.db import Session, ChangesetStatus, RepositoryField, Repository, RepoGroup, ChangesetComment
@ -393,6 +393,8 @@ def get_repo_changesets(request, apiuser, repoid, start_rev, limit, details=Opti
commits = vcs_repo.get_commits(start_id=start_rev, pre_load=pre_load, translate_tags=False)
except TypeError as e:
raise JSONRPCError(safe_str(e))
except EmptyRepositoryError:
return []
except Exception:
log.exception("Fetching of commits failed")
raise JSONRPCError("Error occurred during commit fetching")

View file

@ -306,8 +306,13 @@ class SubversionRepository(base.BaseRepository):
self._validate_commit_id(end_id)
start_raw_id = self._sanitize_commit_id(start_id)
start_pos = self.commit_ids.index(start_raw_id) if start_id else None
end_raw_id = self._sanitize_commit_id(end_id)
if start_raw_id not in self.commit_ids or end_raw_id not in self.commit_ids:
return base.CollectionGenerator(self, [])
start_pos = self.commit_ids.index(start_raw_id) if start_id else None
end_pos = max(0, self.commit_ids.index(end_raw_id)) if end_id else None
if None not in [start_id, end_id] and start_pos > end_pos: