[git] Fix unstash.

Root cause: after unstash dialog became non-modal, the synchronous execution in GitUnstashDialog.showUnstashDialog became non-functional.

* Move all stuff to doOKAction().
* Mark GitUnstash action as asynchronous (VFS is refreshed inside GitUnstashDialog anyway).
* DRY GitHandlerUtil.ERROR_INDICATORS.
* Add "unable" to ERROR_INDICATORS to display a common unstash error better.
This commit is contained in:
Kirill Likhodedov
2012-06-06 18:49:27 +04:00
parent e76b6f8dec
commit 35f63d6d5a
5 changed files with 28 additions and 39 deletions
@@ -20,7 +20,6 @@ import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vfs.VirtualFile;
import git4idea.i18n.GitBundle;
import git4idea.repo.GitRepositoryManager;
import git4idea.ui.GitUnstashDialog;
import org.jetbrains.annotations.NotNull;
@@ -50,6 +49,11 @@ public class GitUnstash extends GitRepositoryAction {
final List<VcsException> exceptions) throws VcsException {
final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
if (changeListManager.isFreezedWithNotification("Can not unstash changes now")) return;
GitUnstashDialog.showUnstashDialog(project, gitRoots, defaultRoot, affectedRoots);
GitUnstashDialog.showUnstashDialog(project, gitRoots, defaultRoot);
}
@Override
protected boolean executeFinalTasksSynchronously() {
return false;
}
}
@@ -372,12 +372,6 @@ public class GitHandlerUtil {
}
}
}
/**
* Error indicators for the line
*/
@NonNls private static final String[] ERROR_INDICATORS =
{"ERROR:", "error", "FATAL:", "fatal", "Cannot apply", "Could not", "Interactive rebase already started", "refusing to pull",
"cannot rebase:"};
/**
* Check if the line is an error line
@@ -386,7 +380,7 @@ public class GitHandlerUtil {
* @return true if the error line
*/
protected static boolean isErrorLine(String text) {
for (String prefix : ERROR_INDICATORS) {
for (String prefix : GitImpl.ERROR_INDICATORS) {
if (text.startsWith(prefix)) {
return true;
}
@@ -339,14 +339,14 @@ public class GitImpl implements Git {
}
}
private GitCommandResult run(@NotNull GitLineHandler handler) {
private static GitCommandResult run(@NotNull GitLineHandler handler) {
return run(handler, false);
}
/**
* Runs the given {@link GitLineHandler} in the current thread and returns the {@link GitCommandResult}.
*/
private GitCommandResult run(@NotNull GitLineHandler handler, boolean remote) {
private static GitCommandResult run(@NotNull GitLineHandler handler, boolean remote) {
handler.setNoSSH(!remote);
final List<String> errorOutput = new ArrayList<String>();
@@ -387,7 +387,7 @@ public class GitImpl implements Git {
/**
* Check if the line looks line an error message
*/
private boolean isError(String text) {
private static boolean isError(String text) {
for (String indicator : ERROR_INDICATORS) {
if (text.startsWith(indicator.toLowerCase())) {
return true;
@@ -397,8 +397,9 @@ public class GitImpl implements Git {
}
// could be upper-cased, so should check case-insensitively
private final String[] ERROR_INDICATORS = {
"error", "fatal", "Cannot apply", "Could not", "Interactive rebase already started", "refusing to pull", "cannot rebase:", "conflict"
public static final String[] ERROR_INDICATORS = {
"error", "fatal", "Cannot apply", "Could not", "Interactive rebase already started", "refusing to pull", "cannot rebase:", "conflict",
"unable"
};
}
@@ -99,7 +99,7 @@ public class GitStashChangesSaver extends GitChangesSaver {
@Override
protected void showSavedChanges() {
GitUnstashDialog.showUnstashDialog(myProject, new ArrayList<VirtualFile>(myStashedRoots), myStashedRoots.iterator().next(), new HashSet<VirtualFile>());
GitUnstashDialog.showUnstashDialog(myProject, new ArrayList<VirtualFile>(myStashedRoots), myStashedRoots.iterator().next());
}
@Override
@@ -216,8 +216,8 @@ public class GitStashChangesSaver extends GitChangesSaver {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (event.getDescription().equals("saver")) {
// we don't use #showSavedChanges to specify unmerged root first
GitUnstashDialog.showUnstashDialog(myProject, new ArrayList<VirtualFile>(myStashedRoots), myStashedRoots.iterator().next(),
new HashSet<VirtualFile>());
GitUnstashDialog.showUnstashDialog(myProject, new ArrayList<VirtualFile>(myStashedRoots), myStashedRoots.iterator().next()
);
} else if (event.getDescription().equals("resolve")) {
mergeNoProceed();
}
@@ -390,26 +390,10 @@ public class GitUnstashDialog extends DialogWrapper {
return myStashList;
}
/**
* Show unstash dialog and process its result
*
* @param project the context project
* @param gitRoots the git roots
* @param defaultRoot the default git root
* @param affectedRoots the affected roots
*/
public static void showUnstashDialog(Project project,
List<VirtualFile> gitRoots,
VirtualFile defaultRoot,
Set<VirtualFile> affectedRoots) {
GitUnstashDialog d = new GitUnstashDialog(project, gitRoots, defaultRoot);
d.show();
if (!d.isOK()) {
return;
}
VirtualFile root = d.getGitRoot();
affectedRoots.add(root);
GitLineHandler h = d.handler();
@Override
protected void doOKAction() {
VirtualFile root = getGitRoot();
GitLineHandler h = handler();
final AtomicBoolean conflict = new AtomicBoolean();
h.addLineListener(new GitLineHandlerAdapter() {
@@ -423,11 +407,17 @@ public class GitUnstashDialog extends DialogWrapper {
root.refresh(true, true);
if (conflict.get()) {
boolean conflictsResolved = new UnstashConflictResolver(project, root, d.getSelectedStash()).merge();
boolean conflictsResolved = new UnstashConflictResolver(myProject, root, getSelectedStash()).merge();
LOG.info("loadRoot " + root + ", conflictsResolved: " + conflictsResolved);
} else if (rc != 0) {
GitUIUtil.showOperationErrors(project, h.errors(), h.printableCommandLine());
GitUIUtil.showOperationErrors(myProject, h.errors(), h.printableCommandLine());
}
super.doOKAction();
}
public static void showUnstashDialog(Project project, List<VirtualFile> gitRoots, VirtualFile defaultRoot) {
new GitUnstashDialog(project, gitRoots, defaultRoot).show();
// d is not modal=> everything else in doOKAction.
}
private static class UnstashConflictResolver extends GitConflictResolver {