Skip to content

Commit

Permalink
Add: Extend git.log to allow setting a pretty format
Browse files Browse the repository at this point in the history
Allow formatting git log output.
  • Loading branch information
bjoernricks committed Jul 19, 2023
1 parent eb062d3 commit 3232adc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pontos/git/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,16 +524,26 @@ def checkout(

self.exec(*args)

def log(self, *log_args: str, oneline: Optional[bool] = None) -> List[str]:
def log(
self,
*log_args: str,
oneline: Optional[bool] = None,
format: Optional[str] = None,
) -> List[str]:
"""
Get log of a git repository
Args:
format: Pretty format the output.
log_args: Additional arguments for git log
oneline: Print the abbreviated commit id and commit message in one
line per commit
"""
args = ["log"]

if format:
args.append(f"--format={format}")

if oneline:
args.append("--oneline")

Expand Down
19 changes: 19 additions & 0 deletions tests/git/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,25 @@ 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_log_with_format(self, exec_git_mock):
exec_git_mock.return_value = """Add CircleCI config for pontos
Rename to pontos only
Update README for installation and development
Update README
Add a draft for a README.md document
Initial commit"""

git = Git()
logs = git.log(format="format:%s")

exec_git_mock.assert_called_once_with(
"log", "--format=format:%s", cwd=None
)

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

@patch("pontos.git.git.exec_git")
def test_rev_list(self, exec_git_mock):
git = Git()
Expand Down

0 comments on commit 3232adc

Please sign in to comment.