semver to only output a version if the git tag for the version and the current commit hash match

This commit is contained in:
Derek DeJonghe 2018-06-05 17:10:32 -04:00
parent 7936a986e5
commit f456c928d7
3 changed files with 15 additions and 2 deletions

View File

@ -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]

View File

@ -7,7 +7,7 @@ except ImportError:
# Python < 3
from ConfigParser import ConfigParser
version = "1.0.7"
version = "1.0.8"
# Define common exceptions;

View File

@ -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