diff --git a/hyde/ext/plugins/git.py b/hyde/ext/plugins/git.py index be86bac..77970b6 100644 --- a/hyde/ext/plugins/git.py +++ b/hyde/ext/plugins/git.py @@ -5,8 +5,10 @@ Contains classes and utilities to extract information from git repository from hyde.plugin import Plugin -import subprocess +from datetime import datetime from dateutil.parser import parse +import os.path +import subprocess class GitDatesPlugin(Plugin): """ @@ -38,18 +40,24 @@ class GitDatesPlugin(Plugin): try: commits = subprocess.check_output(["git", "log", "--pretty=%ai", resource.path]).split("\n") + commits = commits[:-1] + if not commits: + self.logger.warning("No git history for [%s]" % resource) except subprocess.CalledProcessError: self.logger.warning("Unable to get git history for [%s]" % resource) - continue - commits = commits[:-1] - if not commits: - self.logger.warning("No git history for [%s]" % resource) - continue + commits = None + if created == "git": - created = parse(commits[-1].strip()) + if commits: + created = parse(commits[-1].strip()) + else: + created = datetime.utcfromtimestamp(os.path.getctime(resource.path)) created = created.replace(tzinfo=None) resource.meta.created = created if modified == "git": - modified = parse(commits[0].strip()) + if commits: + modified = parse(commits[0].strip()) + else: + modified = datetime.utcfromtimestamp(os.path.getmtime(resource.path)) modified = modified.replace(tzinfo=None) resource.meta.modified = modified