Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions aab/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import logging
import re
import sys

from .utils import call_shell

Expand Down Expand Up @@ -81,13 +83,33 @@ def modtime(self, version):
if version == "dev":
# Get timestamps of uncommitted changes and return the most recent.
# https://stackoverflow.com/a/14142413
cmd = (
"git status -s | while read mode file;"
" do echo $(stat -c %Y $file); done"
)
modtimes = call_shell(cmd).splitlines()
if sys.platform.startswith("linux"):
cmd = (
"git status -s | while read mode file;"
" do echo $(stat -c %Y $file); done"
)
elif sys.platform.startswith("darwin"):
cmd = (
"git status -s | while read mode file;"
" do echo $mode $(stat -f \"%m\" $file) $file; done|sort"
)
elif sys.platform.startswith("win32"):
cmd = (
"git status -s | while read mode file;"
" do echo $mode $(date --reference=$file"
" +\"%Y-%m-%d %H:%M:%S\") $file; done"
)
else:
raise OSError(
"Getting timestamps of uncommitted changes on your OS"
f" ({sys.platform}) isn't supported."
)

# Converting output of the form "M 1618523117 designer/options.ui"
# to just the timestamp
# https://stackoverflow.com/a/12010656
modtimes = [int(modtime) for modtime in modtimes]
modtimes = [int(re.search(r"[\d]+", output).group())
for output in call_shell(cmd).splitlines()]
return max(modtimes)
else:
return int(call_shell("git log -1 -s --format=%ct {}".format(version)))