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.
This commit is contained in:
Kirill Likhodedov
2017-08-27 12:00:59 +03:00
parent 2aa85d1277
commit a62cc0f2de
@@ -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<Boolean> mergeFound = Ref.create(Boolean.FALSE);
Consumer<TimedVcsCommit> detectingConsumer = commit -> mergeFound.set(true);
String range = baseRef + ".." + currentRef;
try {
GitLogUtil.readTimedCommits(project, root, Arrays.asList(range, "--merges"),
EmptyConsumer.getInstance(), EmptyConsumer.getInstance(), detectingConsumer);
List<GitCommit> 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