diff --git a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/git/ProjectGitHandler.java b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/git/ProjectGitHandler.java index a3fa22be..a5d73876 100644 --- a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/git/ProjectGitHandler.java +++ b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/git/ProjectGitHandler.java @@ -233,8 +233,13 @@ public class ProjectGitHandler implements ReleaserPropertiesAware { // exists. If not, then we will assume that `master` contains it private String branchFromVersion(String version) { // 2.3.4.RELEASE -> 2.3.4 + // 2.3.4-RELEASE -> 2.3.4 // Camden.RELEASE -> Camden - String versionTillPatch = version.substring(0, version.lastIndexOf(".")); + // Camden-SR -> Camden + int indexOfDot = version.lastIndexOf("."); + int indexOfDash = version.indexOf("-"); + int indexToPick = indexOfDot > 0 ? indexOfDot : indexOfDash; + String versionTillPatch = version.substring(0, indexToPick); // 2.3.4 -> [2,3,4] // Camden -> [Camden] String[] splitVersion = versionTillPatch.split("\\."); diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/ProjectGitHandlerTests.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/ProjectGitHandlerTests.java index 9c875fc6..02ab5670 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/ProjectGitHandlerTests.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/ProjectGitHandlerTests.java @@ -161,6 +161,29 @@ public class ProjectGitHandlerTests { then(this.gitRepo).should().checkout("Finchley"); } + @Test + public void should_check_out_a_branch_if_it_exists_when_cloning_from_org_and_its_a_release_train_version_with_a_dash() { + this.properties.getFixedVersions().put("spring-cloud-release", "Finchley-SR6"); + given(this.gitRepo.hasBranch(anyString())).willReturn(false); + given(this.gitRepo.hasBranch("Finchley")).willReturn(true); + + this.updater.cloneProjectFromOrg("spring-cloud-release"); + + then(this.gitRepo).should().checkout("Finchley"); + } + + @Test + public void should_check_out_a_branch_if_it_exists_when_cloning_from_org_and_its_a_release_train_version_with_at_least_one_dash() { + this.properties.getFixedVersions().put("spring-cloud-release", + "Finchley-BUILD-SNAPSHOT"); + given(this.gitRepo.hasBranch(anyString())).willReturn(false); + given(this.gitRepo.hasBranch("Finchley")).willReturn(true); + + this.updater.cloneProjectFromOrg("spring-cloud-release"); + + then(this.gitRepo).should().checkout("Finchley"); + } + @Test public void should_not_check_out_a_branch_if_it_does_not_exist_when_cloning_and_guessing_branch() { given(this.gitRepo.hasBranch(anyString())).willReturn(true);