Remove check with hardcoded GERRIT_NEXT_VERSION Checking against a fixed GERRIT_NEXT_VERSION is a very short-sighted approach, as the next version is evolving continuously. Fix the issue where a stable next version was incorrectly detected as master, just because the Gerrit versions moved on. Bug: Issue 11264 Change-Id: I3c3c0fd5e485ec53a5cbd21ae76154a558f2bd9f
diff --git a/src/main/java/com/googlesource/gerrit/plugins/manager/GerritVersionBranch.java b/src/main/java/com/googlesource/gerrit/plugins/manager/GerritVersionBranch.java index 6a36133..ab75730 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/manager/GerritVersionBranch.java +++ b/src/main/java/com/googlesource/gerrit/plugins/manager/GerritVersionBranch.java
@@ -15,13 +15,11 @@ package com.googlesource.gerrit.plugins.manager; public class GerritVersionBranch { - private static final String GERRIT_NEXT_VERSION = "3.0"; public static String getBranch(String gerritVersion) { if (gerritVersion == null || gerritVersion.trim().isEmpty() - || !Character.isDigit(gerritVersion.trim().charAt(0)) - || gerritVersion.startsWith(GERRIT_NEXT_VERSION)) { + || !Character.isDigit(gerritVersion.trim().charAt(0))) { return "master"; } String[] versionNumbers = gerritVersion.split("\\."); @@ -34,12 +32,8 @@ if (versionNumbers.length > 2) { String fixVersionNumber = versionNumbers[2]; - if (fixVersionNumber.contains("-")) { - String nextVersion = - String.format("%s.%d", versionNumbers[0], Integer.parseInt(versionNumbers[1]) + 1); - if (nextVersion.equals(GERRIT_NEXT_VERSION)) { - return "master"; - } + if (fixVersionNumber.contains("-") && !fixVersionNumber.contains("-rc")) { + return "master"; } }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/manager/GerritVersionBranchTest.java b/src/test/java/com/googlesource/gerrit/plugins/manager/GerritVersionBranchTest.java index f0f6a4b..2c91b6a 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/manager/GerritVersionBranchTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/manager/GerritVersionBranchTest.java
@@ -44,12 +44,13 @@ @Test public void getBranchReturnsCorrectBranchForDevelopmentOnStableBranches() throws Exception { - assertBranch("2.16.8-17-gc8b633d5ce", "stable-2.16"); + assertBranch("2.16.8", "stable-2.16"); + assertBranch("3.0.0-rc2", "stable-3.0"); } @Test public void getBranchReturnsCorrectBranchForDevelopmentOnMaster() throws Exception { - assertBranch("3.0.0-rc2-237-gae0124c68e", "master"); + assertBranch("3.0.0-237-gae0124c68e", "master"); } @Test