diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 96d4ac7..9497194 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -2,7 +2,7 @@ current_version = 1.0.5 commit = True tag = True -tag_name = v{new_version} +tag_name = {new_version} message = Bump version: {current_version} -> {new_version} [bumpversion:file:semver.semver] diff --git a/semver/__init__.py b/semver/__init__.py index cf9d4bf..5e32823 100644 --- a/semver/__init__.py +++ b/semver/__init__.py @@ -7,7 +7,7 @@ except ImportError: # Python < 3 from ConfigParser import ConfigParser -version = "1.0.7" +version = "1.0.8" # Define common exceptions; diff --git a/semver/get_version.py b/semver/get_version.py index f28cfc4..18b00a9 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -1,3 +1,4 @@ +import subprocess try: from configparser import ConfigParser except ImportError: @@ -9,6 +10,18 @@ def get_version(): config = ConfigParser() config.read('./.bumpversion.cfg') version = config.get('bumpversion', 'current_version') + # Get the commit hash of the version + v_hash = subprocess.Popen(['git', 'rev-list', '-n', '1', version], stdout=subprocess.PIPE, + cwd='.').stdout.read().decode('utf-8').rstrip() + # Get the current commit hash + c_hash = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE, + cwd='.').stdout.read().decode('utf-8').rstrip() + # If the version commit hash and current commit hash + # do not match return the branch name else return the version + if v_hash != c_hash: + b = subprocess.Popen(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], stdout=subprocess.PIPE, + cwd='.').stdout.read().decode('utf-8').rstrip() + return b return version