merge: abort merge resolve in read-only documents

Ex: if the "Clear Read-Only Status" dialog was canceled

This is a possible cause of
EA-92767 - IOOBE: LineSet.checkLineIndex
EA-92274 - IOOBE: TextMergeViewer$MyThreesideViewer$MyMergeModel.processDocumentChange
EA-90298 - IOOBE: LineSet.checkLineIndex
EA-81265 - IOOBE: LineSet.checkLineIndex
This commit is contained in:
Aleksey Pivovarov
2016-12-14 14:17:00 +03:00
parent 4e59b680a5
commit f277f6aafd
@@ -290,7 +290,7 @@ public class TextMergeViewer implements MergeTool.MergeViewer {
return;
}
if (result == MergeResult.RESOLVED) {
if ((getChangesCount() != 0 || getConflictsCount() != 0) &&
if ((getChangesCount() > 0 || getConflictsCount() > 0) &&
Messages.showYesNoDialog(myPanel.getRootPane(),
DiffBundle.message("merge.dialog.apply.partially.resolved.changes.confirmation.message", getChangesCount(), getConflictsCount()),
DiffBundle.message("apply.partially.resolved.merge.dialog.title"),
@@ -312,11 +312,11 @@ public class TextMergeViewer implements MergeTool.MergeViewer {
// Diff
//
private void setInitialOutputContent() {
private boolean setInitialOutputContent() {
final Document baseDocument = ThreeSide.BASE.select(myMergeRequest.getContents()).getDocument();
final Document outputDocument = myMergeRequest.getOutputContent().getDocument();
DiffUtil.executeWriteCommand(outputDocument, getProject(), "Init merge content", () -> {
return DiffUtil.executeWriteCommand(outputDocument, getProject(), "Init merge content", () -> {
outputDocument.setText(baseDocument.getCharsSequence());
DiffUtil.putNonundoableOperation(getProject(), outputDocument);
@@ -423,14 +423,18 @@ public class TextMergeViewer implements MergeTool.MergeViewer {
private Runnable apply(@NotNull final List<MergeLineFragment> fragments,
@NotNull final List<MergeConflictType> conflictTypes) {
return () -> {
setInitialOutputContent();
clearDiffPresentation();
resetChangeCounters();
boolean success = setInitialOutputContent();
if (!success) {
myPanel.addNotification(DiffNotifications.createNotification("Can't resolve conflicts in a read-only file"));
return;
}
myModel.setChanges(ContainerUtil.map(fragments, f -> new LineRange(f.getStartLine(ThreeSide.BASE),
f.getEndLine(ThreeSide.BASE))));
resetChangeCounters();
for (int index = 0; index < fragments.size(); index++) {
MergeLineFragment fragment = fragments.get(index);
MergeConflictType conflictType = conflictTypes.get(index);