From 1ebab891371c7d110f11fd2ba44a440742f7865d Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Fri, 21 Jun 2024 16:02:47 -0700 Subject: [PATCH] Handle scenario where branch name contains double hyphen --- .../plugin/release/ReleasePluginIntegrationSpec.groovy | 10 ++++++++++ .../groovy/nebula/plugin/release/ReleasePlugin.groovy | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/integTest/groovy/nebula/plugin/release/ReleasePluginIntegrationSpec.groovy b/src/integTest/groovy/nebula/plugin/release/ReleasePluginIntegrationSpec.groovy index cada306..3ba57e7 100644 --- a/src/integTest/groovy/nebula/plugin/release/ReleasePluginIntegrationSpec.groovy +++ b/src/integTest/groovy/nebula/plugin/release/ReleasePluginIntegrationSpec.groovy @@ -67,6 +67,16 @@ class ReleasePluginIntegrationSpec extends GitVersioningIntegrationTestKitSpec { version == dev('0.1.0-dev.2+testexample.') } + def 'build on non standard branch with double hyphen fails with right context'() { + git.checkout(branch: 'test--example', createBranch: true) + + when: + def result = runTasksAndFail('devSnapshot') + + then: + result.output.contains("Branch test--example is invalid. Nebula Release plugin does not support branches that contain double dash (-) as it leads to bad build metadata for SemVer") + } + def 'choose devSnapshot version'() { when: def version = inferredVersionForTask('devSnapshot') diff --git a/src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy b/src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy index 750af77..269acd0 100644 --- a/src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy +++ b/src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy @@ -395,7 +395,12 @@ class ReleasePlugin implements Plugin { return } if (currentBranch.endsWith('-')) { - throw new GradleException('Nebula Release plugin does not support branches that end with dash (-)') + throw new GradleException('Nebula Release plugin does not support branches that end with dash (-).' + + 'Please rename your branch') + } + if (currentBranch.contains('--')) { + throw new GradleException("Branch ${currentBranch} is invalid. Nebula Release plugin does not support branches that contain double dash (-) as it leads to bad build metadata for SemVer." + + " Please rename your branch") } if (currentBranch ==~ /release\/\d+(\.\d+)?/) { throw new GradleException('Branches with pattern release/ are used to calculate versions. The version must be of form: .x, ..x, or ..')