Skip to content

Commit

Permalink
Add: Add rev_list method to the Git class
Browse files Browse the repository at this point in the history
The rev_list method currently only implements parts of the possible
arguments.
  • Loading branch information
bjoernricks committed Feb 24, 2023
1 parent ed15734 commit cbb7c92
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pontos/git/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,41 @@ def log(self, *log_args: str, oneline: Optional[bool] = None) -> List[str]:
args.extend(log_args)

return self.exec(*args).splitlines()

def rev_list(
self,
*commit: str,
max_parents: Optional[int] = None,
abbrev_commit: Optional[bool] = False,
) -> List[str]:
"""
Lists commit objects in reverse chronological order
Args:
commit: commit objects.
max_parents: Only list nth oldest commits
abbrev_commit: Set to True to show prefix that names the commit
object uniquely instead of the full commit ID.
Examples:
.. code-block:: python
git = Git()
git.rev_list("foo", "bar", "^baz")
This will "list all the commits which are reachable from foo or bar,
but not from baz".
git = Git()
git.rev_list("foo", max_parents=0)
This will return the first commit of foo.
"""
args = ["rev-list"]
if max_parents is not None:
args.append(f"--max-parents={max_parents}")
if abbrev_commit:
args.append("--abbrev-commit")

args.extend(commit)
return self.exec(*args).splitlines()
15 changes: 15 additions & 0 deletions tests/git/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,18 @@ def test_log_with_oneline(self, exec_git_mock):

self.assertEqual(logs[0], "50f9963 Add CircleCI config for pontos")
self.assertEqual(logs[5], "464f24d Initial commit")

@patch("pontos.git.git.exec_git")
def test_rev_list(self, exec_git_mock):
git = Git()
git.rev_list("foo", "bar", "baz", max_parents=123, abbrev_commit=True)

exec_git_mock.assert_called_once_with(
"rev-list",
"--max-parents=123",
"--abbrev-commit",
"foo",
"bar",
"baz",
cwd=None,
)

0 comments on commit cbb7c92

Please sign in to comment.