From 747f1f60bac1cd578968f0056aa66c82b784fa3b Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 26 Jan 2017 16:30:39 +0100 Subject: [PATCH] #42 - Maintenance branch creation does not try to update just created branch. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduced an overload for GitOperations.checkout(…) to allow to define whether a branch about to be created is supposed to be updated right away. The already existing method keeps the old behavior (immediate update) while the maintenance branch creation forces a create only as by definition a branch about to be created is not going to be available in the remote repo. --- .../data/release/git/GitOperations.java | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/release-tools/src/main/java/org/springframework/data/release/git/GitOperations.java b/release-tools/src/main/java/org/springframework/data/release/git/GitOperations.java index 0e6b6ef..3ff8b7e 100644 --- a/release-tools/src/main/java/org/springframework/data/release/git/GitOperations.java +++ b/release-tools/src/main/java/org/springframework/data/release/git/GitOperations.java @@ -67,6 +67,10 @@ import org.springframework.util.Assert; @FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) public class GitOperations { + private enum BranchCheckoutMode { + CREATE_ONLY, CREATE_AND_UPDATE; + } + GitServer server = new GitServer(); Workspace workspace; Logger logger; @@ -429,12 +433,26 @@ public class GitOperations { /** * Checks out the given {@link Branch} of the given {@link Project}. If the given branch doesn't exist yet, a tracking * branch is created assuming the branch exists in the {@code origin} remote. Pulls the latest changes from the - * checked out branch to make sure we see the latest changes. + * checked out branch will be pulled to make sure we see them. * * @param project must not be {@literal null}. * @param branch must not be {@literal null}. */ public void checkout(Project project, Branch branch) { + checkout(project, branch, BranchCheckoutMode.CREATE_AND_UPDATE); + } + + /** + * Checks out the given {@link Branch} of the given {@link Project}. If the given branch doesn't exist yet, a tracking + * branch is created assuming the branch exists in the {@code origin} remote. If the {@link BranchCheckoutMode} is set + * to {@code CREATE_AND_UPDATE} the latest changes from the checked out branch will be pulled to make sure we see + * them. + * + * @param project must not be {@literal null}. + * @param branch must not be {@literal null}. + * @param mode must not be {@literal null}. + */ + private void checkout(Project project, Branch branch, BranchCheckoutMode mode) { Assert.notNull(project, "Project must not be null!"); Assert.notNull(branch, "Branch must not be null!"); @@ -465,13 +483,21 @@ public class GitOperations { // TODO: } - // Pull latest changes to make sure the branch is up to date - logger.log(project, "git pull origin %s", branch); + switch (mode) { - git.pull()// - .setRemote("origin")// - .setRemoteBranchName(branch.toString())// - .call(); + case CREATE_ONLY: + break; + case CREATE_AND_UPDATE: + default: + // Pull latest changes to make sure the branch is up to date + logger.log(project, "git pull origin %s", branch); + + git.pull()// + .setRemote("origin")// + .setRemoteBranchName(branch.toString())// + .call(); + break; + } }); logger.log(project, "Checkout done!"); @@ -488,7 +514,7 @@ public class GitOperations { ExecutionUtils.run(iteration, module -> { Branch branch = createMaintenanceBranch(module); - checkout(module.getProject(), branch); + checkout(module.getProject(), branch, BranchCheckoutMode.CREATE_ONLY); }); }