Skip to content

Instantly share code, notes, and snippets.

@minhlab
Created May 10, 2018 09:39
Show Gist options
  • Save minhlab/eff510f4c5c59a35eb023d41152c178d to your computer and use it in GitHub Desktop.
Save minhlab/eff510f4c5c59a35eb023d41152c178d to your computer and use it in GitHub Desktop.
import os
from datetime import date
# git diff --staged is faster than git diff (of everything) so let's do it first
changed = os.popen('git diff').read().strip() != ''
if changed:
version = date.today().strftime('%Y-%m-%d')
else:
version = (os.popen('git show -s --format=%ci').read()[:10] +
os.popen('git show -s --format=-%h').read().strip())
if __name__ == '__main__':
print(version)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment