Skip to content

Commit

Permalink
Include git hash in version when available
Browse files Browse the repository at this point in the history
  • Loading branch information
anishathalye committed Feb 27, 2021
1 parent 5f849ad commit eb7f3fb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions dotbot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
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',
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit eb7f3fb

Please sign in to comment.