From eb7f3fb7b1dd7966e4d105e9210787b7d96e58dd Mon Sep 17 00:00:00 2001 From: Anish Athalye Date: Sat, 27 Feb 2021 14:34:52 -0500 Subject: [PATCH] Include git hash in version when available --- dotbot/cli.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dotbot/cli.py b/dotbot/cli.py index f9fba73..8883a6b 100644 --- a/dotbot/cli.py +++ b/dotbot/cli.py @@ -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)