diff --git a/semver/get_version.py b/semver/get_version.py index 0a4533b..12ed552 100644 --- a/semver/get_version.py +++ b/semver/get_version.py @@ -26,15 +26,16 @@ def get_version(build=0,version_format=None,dot=False): logger.debug("merged branch is: {}".format(semver.merged_branch)) version_type = semver.get_version_type() logger.debug("version type is: {}".format(version_type)) - p = subprocess.Popen(['bumpversion', '--dry-run', '--verbose', '--current-version', get_tag_version(), version_type], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd='.') - bump_output = p.stdout.read().decode('utf-8').rstrip() - next_version = re.search("new_version=([0-9]*.[0-9]*.[0-9]*)", bump_output).group(1) + if version_type: + p = subprocess.Popen(['bumpversion', '--dry-run', '--verbose', '--current-version', get_tag_version(), version_type], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd='.') + bump_output = p.stdout.read().decode('utf-8').rstrip() + next_version = re.search("new_version=([0-9]*.[0-9]*.[0-9]*)", bump_output).group(1) - if version_format == 'npm': - return "{}-{}.{}".format(next_version,branch.replace('/','-'),build) - if version_format == 'maven': - qualifier = 'SNAPSHOT' if build == 0 else build - return "{}-{}-{}".format(next_version,branch.replace('/','-'),qualifier) + if version_format == 'npm': + return "{}-{}.{}".format(next_version,branch.replace('/','-'),build) + if version_format == 'maven': + qualifier = 'SNAPSHOT' if build == 0 else build + return "{}-{}-{}".format(next_version,branch.replace('/','-'),qualifier) if dot: branch = branch.replace('/','.') return branch diff --git a/semver/tests.py b/semver/tests.py index b32f0ec..523a5b6 100644 --- a/semver/tests.py +++ b/semver/tests.py @@ -63,14 +63,14 @@ class TestGetVersion(unittest.TestCase): self.assertEqual(branch, "test/branch") def test_branch_npm_pre_release(self): create_git_environment() - subprocess.call(['git', 'checkout', '-b', 'test/branch']) + subprocess.call(['git', 'checkout', '-b', 'patch/branch']) branch = get_version.get_version(version_format='npm') - self.assertEqual(branch, "0.0.0-test-branch.0") + self.assertEqual(branch, "0.0.0-patch-branch.0") def test_branch_maven_pre_release(self): create_git_environment() - subprocess.call(['git', 'checkout', '-b', 'test/branch']) + subprocess.call(['git', 'checkout', '-b', 'minor/branch']) branch = get_version.get_version(version_format='npm') - self.assertEqual(branch, "0.0.0-test-branch-SNAPSHOT") + self.assertEqual(branch, "0.0.0-minor-branch-SNAPSHOT") def test_get_version_run(self): create_git_environment() val = subprocess.Popen(['python', '../get_version.py', '-d'], stdout=subprocess.PIPE,