Last active
June 3, 2019 14:03
-
-
Save isaacgr/d65a1351393239a48c5513b136fc95c1 to your computer and use it in GitHub Desktop.
Get the date of the last commit for the current repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import re | |
from optparse import OptionParser | |
def last_commit(): | |
p = subprocess.Popen(["git", "log", '-1', '--date=iso'], stdout=subprocess.PIPE) | |
out, err = p.communicate() | |
m = re.search('\d{4}-\d{2}-\d{2}\s', out) | |
return m.group(0) | |
usage = "usage: %prog -f filepath" | |
parser = OptionParser(usage=usage) | |
parser.add_option("-f", default='last_commit.txt') | |
(options, args) = parser.parse_args() | |
path = options.f | |
with open(path, 'w+') as f: | |
timestamp = last_commit().replace('-', '.') | |
f.write(timestamp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment