From fb2a22eb4c36cfeddd3dc72fc2bd496b3a4a5686 Mon Sep 17 00:00:00 2001 From: Jeremiah Leary Date: Mon, 3 Aug 2020 19:26:28 -0500 Subject: [PATCH] Updates for issue #365: Adding commit SHA output to version option. The SHA will only be reported if the git repo has been cloned. When installed via PIP, the SHA will not be reported. --- vsg/tests/vsg/test_vsg.py | 3 +-- vsg/version.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/vsg/tests/vsg/test_vsg.py b/vsg/tests/vsg/test_vsg.py index a55e6b4c..ed399dab 100644 --- a/vsg/tests/vsg/test_vsg.py +++ b/vsg/tests/vsg/test_vsg.py @@ -277,11 +277,10 @@ class testVsg(unittest.TestCase): def test_version_command_line_argument(self): lExpected = [] lExpected.append('VHDL Style Guide (VSG) version ' + version.version) - lExpected.append('') lActual = subprocess.check_output(['bin/vsg','--version']) lActual = str(lActual.decode('utf-8')).split('\n') - self.assertEqual(lActual, lExpected) + self.assertEqual(lExpected[0], lActual[0]) def test_missing_configuration_file(self): lExpected = [] diff --git a/vsg/version.py b/vsg/version.py index 75ae1e95..46d459d8 100644 --- a/vsg/version.py +++ b/vsg/version.py @@ -1,8 +1,22 @@ version = '2.0.0' +import subprocess def print_version(oCommandLineArguments): if (oCommandLineArguments.version): print('VHDL Style Guide (VSG) version ' + str(version)) + + print(retrieve_git_sha()) + exit(0) + + +def retrieve_git_sha(): + + try: + sShaNum = subprocess.check_output(['git', 'log', '--pretty=%h', '-n', '1'], stderr=subprocess.STDOUT) + sShaNum = sShaNum.decode('utf-8').strip() + return f'Git commit SHA: {sShaNum}' + except subprocess.CalledProcessError: + return ''