Skip to content

Instantly share code, notes, and snippets.

@evandrocoan
Forked from bitrut/last_commit.py
Last active June 27, 2019 13:30
Show Gist options
  • Save evandrocoan/5e952238bfcf22df6a28046e4a2fb0ec to your computer and use it in GitHub Desktop.
Save evandrocoan/5e952238bfcf22df6a28046e4a2fb0ec to your computer and use it in GitHub Desktop.
Get timestamp of the last commit in git repository
#!/usr/bin/python
import subprocess
import shlex
import re
from optparse import OptionParser
def git_version(repository_path):
commad = shlex.split( "git log -1 --pretty=format:%ci" )
p = subprocess.Popen(commad, stdout=subprocess.PIPE, cwd=repository_path)
out, err = p.communicate()
m = re.search('\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}', out)
return m.group(0)
usage = "usage: %prog -f folderpath"
parser = OptionParser(usage=usage)
parser.add_option("-f", help="the path to the git repository")
(options, args) = parser.parse_args()
path = options.f
if path:
print( "timestamp: " + git_version( path ) )
else:
parser.print_help()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment