[git] IDEA-138787 Handle 'noop' situation: show a confirmation message

This commit is contained in:
Kirill Likhodedov
2015-04-16 15:18:47 +03:00
parent c59e2edeff
commit 970dbb2adb
2 changed files with 40 additions and 12 deletions
@@ -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<GitRebaseEntry> 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<GitRebaseEntry> 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;
}
}
}
}
@@ -42,12 +42,18 @@ class GitInteractiveRebaseFile {
}
@NotNull
public List<GitRebaseEntry> load() throws IOException {
public List<GitRebaseEntry> load() throws IOException, NoopException {
String encoding = GitConfigUtil.getLogEncoding(myProject, myRoot);
List<GitRebaseEntry> 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 {
}
}