diff --git a/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseEditorHandler.java b/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseEditorHandler.java index d2e12f0b786f..c048c464ca48 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseEditorHandler.java +++ b/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseEditorHandler.java @@ -15,8 +15,10 @@ */ package git4idea.rebase; +import com.intellij.CommonBundle; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Ref; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ui.UIUtil; @@ -116,18 +118,32 @@ public class GitInteractiveRebaseEditorHandler implements Closeable, GitRebaseEd } } else { - GitInteractiveRebaseFile rebaseFile = new GitInteractiveRebaseFile(myProject, myRoot, path); - List entries = rebaseFile.load(); setRebaseEditorShown(); - GitRebaseEditor editor = new GitRebaseEditor(myProject, myRoot, entries); - if (editor.showAndGet()) { - rebaseFile.save(editor.getEntries()); - isSuccess.set(true); - return; + GitInteractiveRebaseFile rebaseFile = new GitInteractiveRebaseFile(myProject, myRoot, path); + try { + List entries = rebaseFile.load(); + GitRebaseEditor editor = new GitRebaseEditor(myProject, myRoot, entries); + if (editor.showAndGet()) { + rebaseFile.save(editor.getEntries()); + isSuccess.set(true); + return; + } + else { + rebaseFile.cancel(); + isSuccess.set(true); + } } - else { - rebaseFile.cancel(); - isSuccess.set(true); + catch (GitInteractiveRebaseFile.NoopException e) { + LOG.info("Noop situation while rebasing " + myRoot); + String message = "There are no commits to rebase because the current branch is directly below the base branch " + + "(the 'noop' situation).\n" + + "Do you want to continue (this will reset the current branch to the base branch)?"; + int rebase = Messages.showOkCancelDialog(myProject, message, "Git Rebase", CommonBundle.getOkButtonText(), + CommonBundle.getCancelButtonText(), Messages.getQuestionIcon()); + if (rebase == Messages.OK) { + isSuccess.set(true); + return; + } } } } diff --git a/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseFile.java b/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseFile.java index e23920fc311f..6964fb73bb55 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseFile.java +++ b/plugins/git4idea/src/git4idea/rebase/GitInteractiveRebaseFile.java @@ -42,12 +42,18 @@ class GitInteractiveRebaseFile { } @NotNull - public List load() throws IOException { + public List load() throws IOException, NoopException { String encoding = GitConfigUtil.getLogEncoding(myProject, myRoot); List entries = ContainerUtil.newArrayList(); final StringScanner s = new StringScanner(FileUtil.loadFile(new File(myFile), encoding)); + boolean noop = false; while (s.hasMoreData()) { - if (s.isEol() || s.startsWith('#') || s.startsWith("noop")) { + if (s.isEol() || s.startsWith('#')) { + s.nextLine(); + continue; + } + if (s.startsWith("noop")) { + noop = true; s.nextLine(); continue; } @@ -57,6 +63,9 @@ class GitInteractiveRebaseFile { entries.add(new GitRebaseEntry(action, hash, comment)); } + if (noop && entries.isEmpty()) { + throw new NoopException(); + } return entries; } @@ -93,4 +102,7 @@ class GitInteractiveRebaseFile { } return file; } + + static class NoopException extends Exception { + } }