From 0717dc174a6ed1e5346a62c21e8291f8aae4f04e Mon Sep 17 00:00:00 2001 From: Max Hohenegger Date: Mon, 24 Oct 2016 21:41:46 +0200 Subject: [PATCH] Avoid NPE that can occur during finishing a Gitflow release At the moment it is unclear how this NPE can be reproduced. Presumably it happens due to a failed merge. Fail early, and added logging to provide information about which of the merges failed. https://dev.eclipse.org/recommenders/committers/aeri/v2/#!/problems/5806eda2e4b0596435bd7852 Change-Id: I4e5f1c2faebc0c1cb3a05ede049eec7e64da05f3 Signed-off-by: Max Hohenegger --- .../src/org/eclipse/egit/core/op/MergeOperation.java | 3 ++- .../src/org/eclipse/egit/gitflow/internal/CoreText.java | 3 +++ .../org/eclipse/egit/gitflow/internal/coretext.properties | 1 + .../src/org/eclipse/egit/gitflow/op/GitFlowOperation.java | 12 ++++++++++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/MergeOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/MergeOperation.java index c3487d321..238530173 100644 --- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/MergeOperation.java +++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/MergeOperation.java @@ -37,6 +37,7 @@ import org.eclipse.egit.core.internal.CoreText; import org.eclipse.egit.core.internal.job.RuleUtil; import org.eclipse.egit.core.internal.util.ProjectUtil; import org.eclipse.jgit.annotations.NonNull; +import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.MergeCommand; import org.eclipse.jgit.api.MergeCommand.FastForwardMode; @@ -220,7 +221,7 @@ public class MergeOperation implements IEGitOperation { * @return the merge result, or null if this has not been * executed or if an exception occurred */ - public MergeResult getResult() { + public @Nullable MergeResult getResult() { return this.mergeResult; } diff --git a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/CoreText.java b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/CoreText.java index 71bb85b61..619c5c74f 100644 --- a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/CoreText.java +++ b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/CoreText.java @@ -74,6 +74,9 @@ public class CoreText extends NLS { public static String GitFlowOperation_unableToCheckout; /** */ + public static String GitFlowOperation_unableToMerge; + + /** */ public static String GitFlowRepository_gitFlowRepositoryMayNotBeEmpty; /** */ diff --git a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/coretext.properties b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/coretext.properties index 12caacb7d..2406741ac 100644 --- a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/coretext.properties +++ b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/internal/coretext.properties @@ -21,6 +21,7 @@ FeatureTrackOperation_unableToStoreGitConfig=Unable to store git config. GitFlowOperation_branchMissing=Branch %s missing GitFlowOperation_branchNotFound=No branch '%s' found. GitFlowOperation_unableToCheckout=Unable to checkout '%s': %s +GitFlowOperation_unableToMerge=Unable to merge '%s' into '%s'. MergeResult was null. GitFlowRepository_gitFlowRepositoryMayNotBeEmpty=Git flow repository may not be empty. HotfixFinishOperation_hotfix=Hotifx {0} HotfixFinishOperation_mergeFromHotfixToMasterFailed=Merge from Hotfix to Master branch failed. This shouldn't happen in GitFlow. diff --git a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/GitFlowOperation.java b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/GitFlowOperation.java index 41648921f..54759b884 100644 --- a/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/GitFlowOperation.java +++ b/org.eclipse.egit.gitflow/src/org/eclipse/egit/gitflow/op/GitFlowOperation.java @@ -28,6 +28,7 @@ import org.eclipse.egit.core.op.IEGitOperation; import org.eclipse.egit.core.op.MergeOperation; import org.eclipse.egit.gitflow.GitFlowRepository; import org.eclipse.egit.gitflow.internal.CoreText; +import org.eclipse.jgit.annotations.NonNull; import org.eclipse.jgit.api.CheckoutResult; import org.eclipse.jgit.api.CheckoutResult.Status; import org.eclipse.jgit.api.MergeResult; @@ -162,7 +163,7 @@ abstract public class GitFlowOperation implements IEGitOperation { * @throws CoreException * @since 4.1 */ - protected MergeResult mergeTo(IProgressMonitor monitor, String branchName, + protected @NonNull MergeResult mergeTo(IProgressMonitor monitor, String branchName, String targetBranchName, boolean squash, boolean fastForwardSingleCommit) throws CoreException { try { if (!repository.hasBranch(targetBranchName)) { @@ -192,7 +193,14 @@ abstract public class GitFlowOperation implements IEGitOperation { } mergeOperation.execute(monitor); - return mergeOperation.getResult(); + MergeResult result = mergeOperation.getResult(); + if (result == null) { + throw new CoreException(error(format( + CoreText.GitFlowOperation_unableToMerge, branchName, + targetBranchName))); + } + + return result; } catch (GitAPIException | IOException e) { throw new RuntimeException(e); } -- 2.11.4.GIT