27 lines
695 B
Python
27 lines
695 B
Python
from datetime import datetime
|
|
from subprocess import check_output
|
|
|
|
from jweb.content import Content
|
|
|
|
|
|
def git_creation_date(content: Content) -> datetime:
|
|
git_dir = check_output(["git", "rev-parse", "--show-toplevel"], encoding="utf-8")
|
|
git_dir = git_dir.strip()
|
|
log = check_output(
|
|
[
|
|
"git",
|
|
"log",
|
|
"--pretty=format:%ad",
|
|
"--date=iso-strict",
|
|
"--diff-filter=A",
|
|
"--",
|
|
str(content.path.relative_to(git_dir)),
|
|
],
|
|
encoding="utf-8",
|
|
)
|
|
log_lines = log.splitlines()
|
|
if len(log_lines) == 0:
|
|
return datetime.now()
|
|
|
|
return datetime.fromisoformat(log_lines[0])
|