Skip to content

Instantly share code, notes, and snippets.

@isaacgr
Last active June 3, 2019 14:03
Show Gist options
  • Save isaacgr/d65a1351393239a48c5513b136fc95c1 to your computer and use it in GitHub Desktop.
Save isaacgr/d65a1351393239a48c5513b136fc95c1 to your computer and use it in GitHub Desktop.
Get the date of the last commit for the current repository
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