Return commits in chronological order

Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
Václav Valíček 2022-08-02 20:53:29 +02:00
parent 8bc6a7b578
commit a2bf978fde
Signed by: valicek
GPG Key ID: FF05BDCA0C73BB31
2 changed files with 5 additions and 1 deletions

View File

@ -216,7 +216,7 @@ class RepoTool:
@__check_initialized
def list_commits(self, max_depth: Optional[int] = None):
return self._repo.iter_commits(all = True, max_count = max_depth)
return self._repo.iter_commits(all = True, max_count = max_depth, reverse = True)
@__check_initialized
def list_submodules(self, commit: str = "HEAD") -> Union[list, bool]:

View File

@ -467,10 +467,14 @@ def test_list_commits(cloned_base_repo_obj):
assert cloned_base_repo_obj.list_commits(3)
count = 0
commits = set()
last_commit = ""
for commit in cloned_base_repo_obj.list_commits(20):
count += 1
commits.add(commit.hexsha)
last_commit = commit.hexsha
assert count == 20
# should be newest commit in repo
assert last_commit == "e0c7e2a72579e24657c05e875201011d2b48bf94"
assert commits == {
'93e97409040f6e4ba5cebc4ddca679a2d3203efa', 'd8cd3257e05dc4a3d0061b5320ef5efd0b45d840',