mirror of
1
0
Fork 0

Include git hash in version when available

This commit is contained in:
Anish Athalye 2021-02-27 14:34:52 -05:00
parent 5f849ad07f
commit eb7f3fb7b1
1 changed files with 10 additions and 2 deletions

View File

@ -9,7 +9,8 @@ from .messenger import Level
from .util import module
import dotbot
import yaml
import os
import subprocess
def add_options(parser):
parser.add_argument('-Q', '--super-quiet', action='store_true',
@ -53,7 +54,14 @@ def main():
add_options(parser)
options = parser.parse_args()
if options.version:
print('Dotbot version %s (yaml: %s)' % (dotbot.__version__, yaml.__version__))
try:
with open(os.devnull) as devnull:
git_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'],
cwd=os.path.dirname(os.path.abspath(__file__)), stderr=devnull)
hash_msg = ' (git %s)' % git_hash[:10]
except (OSError, subprocess.CalledProcessError):
hash_msg = ''
print('Dotbot version %s%s' % (dotbot.__version__, hash_msg))
exit(0)
if options.super_quiet:
log.set_level(Level.WARNING)