Skip to content

Commit

Permalink
pw_cli: Add in option to retrieve commit date
Browse files Browse the repository at this point in the history
Adding in a function to get a datetime object of
the commit author time.
Test: Passes presubmit checks

Change-Id: I1818e2f8453fe4dd0c687d7c8e83f8992f08ca69
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/216275
Reviewed-by: Erik Gilling <[email protected]>
Reviewed-by: Samuel Liu <[email protected]>
Lint: Lint 🤖 <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Reviewed-by: Anthony DiGirolamo <[email protected]>
Pigweed-Auto-Submit: Armando Montanez <[email protected]>
  • Loading branch information
harjani authored and CQ Bot Account committed Sep 4, 2024
1 parent 1140641 commit dbbbad5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pw_cli/py/pw_cli/git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit dbbbad5

Please sign in to comment.