diff --git a/pw_cli/py/pw_cli/git_repo.py b/pw_cli/py/pw_cli/git_repo.py index 57773fb189..84138f2aa2 100644 --- a/pw_cli/py/pw_cli/git_repo.py +++ b/pw_cli/py/pw_cli/git_repo.py @@ -13,6 +13,7 @@ # the License. """Helpful commands for working with a Git repository.""" +from datetime import datetime import logging from pathlib import Path import re @@ -276,6 +277,18 @@ def commit_author(self, commit: str = 'HEAD') -> str: """ return self._git('log', '--format=%ae', '-n1', commit) + def commit_date(self, commit: str = 'HEAD') -> datetime: + """Returns the datetime of the specified commit. + + Defaults to ``HEAD`` if no commit specified. + + Returns: + Commit datetime as a datetime object. + """ + return datetime.fromisoformat( + self._git('log', '--format=%aI', '-n1', commit) + ) + def commit_hash( self, commit: str = 'HEAD',