Skip to content

Commit

Permalink
Add: Add Git method for getting the commit log
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoernricks committed Dec 5, 2022
1 parent 39c334b commit cea7b2e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pontos/git/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,17 @@ def checkout(
args = ["checkout", branch]

exec_git(*args, cwd=self._cwd)

def log(self, *log_args: str, oneline: Optional[bool] = None) -> List[str]:
"""
Get log of a git repository
Args:
"""
args = ["log"]
if oneline:
args.append("--oneline")

args.extend(log_args)

return exec_git(*args, cwd=self._cwd).splitlines()
45 changes: 45 additions & 0 deletions tests/git/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,48 @@ def test_remote_url_with_default(self, exec_git_mock):
)

self.assertEqual(remote, url)

@patch("pontos.git.git.exec_git")
def test_log(self, exec_git_mock):
# pylint: disable=line-too-long
exec_git_mock.return_value = """commit 68c6c3785bbb049df63dc51f8b5b709eb19f8517
Author: Björn Ricks <[email protected]>
Date: Wed Apr 8 15:16:05 2020 +0200
Add a draft for a README.md document
commit 464f24d43d7293091b168c6b37ee37978a650958
Author: Björn Ricks <[email protected]>
Date: Wed Apr 8 14:28:53 2020 +0200
Initial commit
"""

git = Git()
logs = git.log()

exec_git_mock.assert_called_once_with("log", cwd=None)

self.assertEqual(
logs[0], "commit 68c6c3785bbb049df63dc51f8b5b709eb19f8517"
)
self.assertEqual(
logs[6], "commit 464f24d43d7293091b168c6b37ee37978a650958"
)

@patch("pontos.git.git.exec_git")
def test_log_with_oneline(self, exec_git_mock):
exec_git_mock.return_value = """50f9963 Add CircleCI config for pontos
9a8feaa Rename to pontos only
047cfae Update README for installation and development
e6ea80d Update README
68c6c37 Add a draft for a README.md document
464f24d Initial commit"""

git = Git()
logs = git.log(oneline=True)

exec_git_mock.assert_called_once_with("log", "--oneline", cwd=None)

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

0 comments on commit cea7b2e

Please sign in to comment.