-
-
Save evandrocoan/5e952238bfcf22df6a28046e4a2fb0ec to your computer and use it in GitHub Desktop.
Get timestamp of the last commit in git 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
#!/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