Skip to content

Commit

Permalink
Merge pull request #176 from nebula-plugins/fail-on-branches-ending-w…
Browse files Browse the repository at this point in the history
…ith-dash

ReleasePlugin.checkForBadBranchNames should fail if branch ends with dash
  • Loading branch information
rpalcolea committed Jan 23, 2020
2 parents cb0d6eb + 641e6cb commit 5091618
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Expand Up @@ -1102,6 +1102,33 @@ class ReleasePluginIntegrationSpec extends GitVersioningIntegrationSpec {
!result.wasSkipped(':prepare')
}


def 'fails when branch ends with dash'() {
given:
buildFile << """
ext.dryRun = true
group = 'test'
${applyPlugin(ReleasePlugin)}
${applyPlugin(JavaPlugin)}
nebulaRelease {
checkRemoteBranchOnRelease = true
}
""".stripIndent()
def file = new File(projectDir, "test_file.txt")
file.text = "DUMMY"
git.add(patterns: ['.'] as Set)
git.commit(message: "Add file")
git.push(all: true)
git.checkout(branch: 'my-branch-with-dash-', createBranch: true)

when:
def result = runTasksWithFailure('candidate', '-Drelease.configurePrepareTaskEnabled=true')

then:
result.standardError.contains('Nebula Release plugin does not support branches that end with dash (-)')
}

private void replaceDevWithImmutableSnapshot() {
new File(buildFile.parentFile, "gradle.properties").text = """
nebula.release.features.replaceDevWithImmutableSnapshot=true
Expand Down
7 changes: 6 additions & 1 deletion src/main/groovy/nebula/plugin/release/ReleasePlugin.groovy
Expand Up @@ -21,6 +21,7 @@ import nebula.plugin.release.git.base.ReleasePluginExtension
import nebula.plugin.release.git.base.ReleaseVersion
import nebula.plugin.release.git.base.TagStrategy
import nebula.plugin.release.git.semver.SemVerStrategy
import org.ajoberstar.grgit.Branch
import org.ajoberstar.grgit.Commit
import org.ajoberstar.grgit.Grgit
import org.ajoberstar.grgit.Status
Expand Down Expand Up @@ -387,7 +388,11 @@ class ReleasePlugin implements Plugin<Project> {
}

void checkForBadBranchNames() {
if (git.branch.current().name ==~ /release\/\d+(\.\d+)?/) {
Branch currentBranch = git.branch.current()
if(currentBranch.name.endsWith('-')) {
throw new GradleException('Nebula Release plugin does not support branches that end with dash (-)')
}
if (currentBranch.name ==~ /release\/\d+(\.\d+)?/) {
throw new GradleException('Branches with pattern release/<version> are used to calculate versions. The version must be of form: <major>.x, <major>.<minor>.x, or <major>.<minor>.<patch>')
}
}
Expand Down

0 comments on commit 5091618

Please sign in to comment.