mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] IDEA-138787 Handle 'noop' situation: show a confirmation message
This commit is contained in:
@@ -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 {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user