From a62cc0f2dee9b6b54dbe2aa4852ebe122b34275b Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Sun, 27 Aug 2017 11:50:17 +0300 Subject: [PATCH] IDEA-168392 Don't warn about rebasing a merge which had no conflicts Rebasing over a merge is a normal procedure, and the only annoying thing which may happen is resolving conflicts again, if they happened during the previous merge. Therefore the warning should be shown only if the user tries to rebase over a merge with conflicts. Additionally, the warning itself is made a bit less frightening. --- .../update/GitRebaseOverMergeProblem.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/plugins/git4idea/src/git4idea/update/GitRebaseOverMergeProblem.java b/plugins/git4idea/src/git4idea/update/GitRebaseOverMergeProblem.java index 2b807025cba7..72d5e6b257db 100644 --- a/plugins/git4idea/src/git4idea/update/GitRebaseOverMergeProblem.java +++ b/plugins/git4idea/src/git4idea/update/GitRebaseOverMergeProblem.java @@ -23,27 +23,26 @@ import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Ref; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.Consumer; -import com.intellij.util.EmptyConsumer; import com.intellij.util.ObjectUtils; import com.intellij.util.containers.ContainerUtil; -import com.intellij.vcs.log.TimedVcsCommit; import git4idea.DialogManager; +import git4idea.GitCommit; import git4idea.history.GitLogUtil; +import one.util.streamex.StreamEx; import org.jetbrains.annotations.NotNull; -import java.util.Arrays; +import java.util.List; public class GitRebaseOverMergeProblem { private static final Logger LOG = Logger.getInstance(GitRebaseOverMergeProblem.class); public static final String DESCRIPTION = - "You are about to rebase merge commits. \n" + - "This can lead to duplicate commits in history, or even data loss.\n" + - "It is recommended to merge instead of rebase in this case."; + "You are about to rebase a merge commit with conflicts.\n\n" + + "Choose 'Merge' if you don't want to resolve conflicts again, " + + "or you still can rebase if you want to linearize the history."; public enum Decision { MERGE_INSTEAD("Merge"), - REBASE_ANYWAY("Rebase Anyway"), + REBASE_ANYWAY("Rebase"), CANCEL_OPERATION(CommonBundle.getCancelButtonText()); private final String myButtonText; @@ -67,7 +66,7 @@ public class GitRebaseOverMergeProblem { } private static int getFocusedButtonIndex() { - return CANCEL_OPERATION.ordinal(); + return REBASE_ANYWAY.ordinal(); } } @@ -75,18 +74,15 @@ public class GitRebaseOverMergeProblem { @NotNull VirtualFile root, @NotNull String baseRef, @NotNull String currentRef) { - final Ref mergeFound = Ref.create(Boolean.FALSE); - Consumer detectingConsumer = commit -> mergeFound.set(true); - String range = baseRef + ".." + currentRef; try { - GitLogUtil.readTimedCommits(project, root, Arrays.asList(range, "--merges"), - EmptyConsumer.getInstance(), EmptyConsumer.getInstance(), detectingConsumer); + List commits = GitLogUtil.collectFullDetails(project, root, range, "--merges"); + return StreamEx.of(commits).anyMatch(commit -> !commit.getChanges().isEmpty()); } catch (VcsException e) { LOG.warn("Couldn't get git log --merges " + range, e); + return false; } - return mergeFound.get(); } @NotNull