From 7f39ecfe16a893f212370b991fa614d08710b79c Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 15 Nov 2024 10:20:15 +0100 Subject: [PATCH] Update command to create branches. Closes #100 --- .../data/release/cli/ReleaseCommands.java | 15 +++++++++------ .../data/release/git/GitOperations.java | 17 ++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/springframework/data/release/cli/ReleaseCommands.java b/src/main/java/org/springframework/data/release/cli/ReleaseCommands.java index 8f9096c..8cc446e 100644 --- a/src/main/java/org/springframework/data/release/cli/ReleaseCommands.java +++ b/src/main/java/org/springframework/data/release/cli/ReleaseCommands.java @@ -35,6 +35,7 @@ import org.springframework.data.release.git.GitOperations; import org.springframework.data.release.issues.IssueTrackerCommands; import org.springframework.data.release.issues.github.GitHubCommands; import org.springframework.data.release.misc.ReleaseOperations; +import org.springframework.data.release.model.Iteration; import org.springframework.data.release.model.ModuleIteration; import org.springframework.data.release.model.Phase; import org.springframework.data.release.model.Project; @@ -203,7 +204,8 @@ class ReleaseCommands extends TimedCommand { if (iteration.getIteration().isGAIteration()) { // Create bugfix branches - BranchMapping branches = git.createMaintenanceBranches(iteration, true); + BranchMapping branches = git.createMaintenanceBranches(iteration, + iteration.getTrain().getIteration(Iteration.SR1)); // Set project version to maintenance once setupMaintenanceVersions(iteration, branches); @@ -212,18 +214,19 @@ class ReleaseCommands extends TimedCommand { } @CliCommand(value = "release create-branches") - public void createBranches(@CliOption(key = "", mandatory = true) TrainIteration iteration) throws Exception { + public void createBranches(@CliOption(key = "from", mandatory = true) TrainIteration from, + @CliOption(key = "from", mandatory = true) TrainIteration to) throws Exception { - if (!iteration.getTrain().isAlwaysUseBranch()) { + if (!to.getTrain().isAlwaysUseBranch()) { throw new IllegalArgumentException( - String.format("Cannot create branches as train %s does not use branches.", iteration.getTrain().getCalver())); + String.format("Cannot create branches as train %s does not use branches.", to.getTrain().getCalver())); } // Create bugfix branches - BranchMapping branchMapping = git.createMaintenanceBranches(iteration, false); + BranchMapping branchMapping = git.createMaintenanceBranches(from, to); // Set project version to maintenance once - setupMaintenanceVersions(iteration, branchMapping); + setupMaintenanceVersions(to, branchMapping); } @CliCommand(value = "release documentation") diff --git a/src/main/java/org/springframework/data/release/git/GitOperations.java b/src/main/java/org/springframework/data/release/git/GitOperations.java index 32073e4..711040c 100644 --- a/src/main/java/org/springframework/data/release/git/GitOperations.java +++ b/src/main/java/org/springframework/data/release/git/GitOperations.java @@ -926,26 +926,25 @@ public class GitOperations { logger.log(project, "Checkout done!"); } - public BranchMapping createMaintenanceBranches(TrainIteration iteration, boolean checkout) { + public BranchMapping createMaintenanceBranches(TrainIteration from, TrainIteration to) { - if (checkout && !iteration.getIteration().isGAIteration()) { + if (!from.getIteration().isGAIteration()) { return BranchMapping.NONE; } - if (checkout) { - checkout(iteration); - } + checkout(from); - return createBranch(iteration); + return createBranch(from, to); } - public BranchMapping createBranch(TrainIteration iteration) { + public BranchMapping createBranch(TrainIteration from, TrainIteration to) { BranchMapping branches = new BranchMapping(); - ExecutionUtils.run(executor, iteration, module -> { + ExecutionUtils.run(executor, to, module -> { - Branch current = getCurrentBranch(module); + ModuleIteration fromIteration = from.getModule(module.getProject()); + Branch current = from.getIteration().isGAIteration() ? Branch.MAIN : Branch.from(fromIteration.getVersion()); Branch newBranch = createBranch(module); checkout(module.getSupportedProject(), newBranch, BranchCheckoutMode.CREATE_ONLY);