diff --git a/plugins/git4idea/src/git4idea/actions/GitFetch.java b/plugins/git4idea/src/git4idea/actions/GitFetch.java index 07d041f2f08e..b761aecac34a 100644 --- a/plugins/git4idea/src/git4idea/actions/GitFetch.java +++ b/plugins/git4idea/src/git4idea/actions/GitFetch.java @@ -51,4 +51,8 @@ public class GitFetch extends GitRepositoryAction { }); } + @Override + protected boolean executeFinalTasksSynchronously() { + return false; + } } diff --git a/plugins/git4idea/src/git4idea/actions/GitPull.java b/plugins/git4idea/src/git4idea/actions/GitPull.java index 23c62a27760c..874e7e2d0fc4 100644 --- a/plugins/git4idea/src/git4idea/actions/GitPull.java +++ b/plugins/git4idea/src/git4idea/actions/GitPull.java @@ -25,6 +25,7 @@ import com.intellij.openapi.vcs.update.ActionInfo; import com.intellij.openapi.vfs.VirtualFile; import git4idea.GitRevisionNumber; import git4idea.GitUtil; +import git4idea.GitVcs; import git4idea.commands.GitLineHandler; import git4idea.commands.GitStandardProgressAnalyzer; import git4idea.commands.GitTask; @@ -114,6 +115,7 @@ public class GitPull extends GitRepositoryAction { protected void onSuccess() { GitMergeUtil.showUpdates(GitPull.this, project, exceptions, root, currentRev, beforeLabel, getActionName(), ActionInfo.UPDATE); repositoryManager.updateRepository(root, GitRepository.TrackedTopic.ALL); + runFinalTasks(project, GitVcs.getInstance(project), affectedRoots, getActionName(), exceptions); } @Override @@ -126,4 +128,8 @@ public class GitPull extends GitRepositoryAction { }.queue(); } + @Override + protected boolean executeFinalTasksSynchronously() { + return false; + } } diff --git a/plugins/git4idea/src/git4idea/actions/GitRepositoryAction.java b/plugins/git4idea/src/git4idea/actions/GitRepositoryAction.java index 54d403158bff..15523cc1f65a 100644 --- a/plugins/git4idea/src/git4idea/actions/GitRepositoryAction.java +++ b/plugins/git4idea/src/git4idea/actions/GitRepositoryAction.java @@ -24,7 +24,6 @@ import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.vcs.AbstractVcsHelper; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.TransactionRunnable; import com.intellij.openapi.vcs.VcsException; @@ -89,27 +88,37 @@ public abstract class GitRepositoryAction extends DumbAwareAction { final VirtualFile defaultRoot = defaultRootVar; final Set affectedRoots = new HashSet(); String actionName = getActionName(); - AbstractVcsHelper helper = AbstractVcsHelper.getInstance(project); - //Runs the runnable inside the vcs transaction (if needed), collects all exceptions, commits/rollbacks transaction and returns all exceptions together. - List exceptions = helper.runTransactionRunnable(vcs, new TransactionRunnable() { - public void run(List exceptions) { - //noinspection unchecked - try { - perform(project, roots, defaultRoot, affectedRoots, exceptions); - } - catch (VcsException e) { - exceptions.add(e); - } - VcsFileUtil.refreshFiles(project, affectedRoots); - for (TransactionRunnable task : myDelayedTasks) { - task.run(exceptions); - } - } - }, null); + + List exceptions = new ArrayList(); + try { + perform(project, roots, defaultRoot, affectedRoots, exceptions); + } + catch (VcsException ex) { + exceptions.add(ex); + } + if (executeFinalTasksSynchronously()) { + runFinalTasks(project, vcs, affectedRoots, actionName, exceptions); + } + } + + protected final void runFinalTasks(Project project, GitVcs vcs, Set affectedRoots, String actionName, + List exceptions) { + VcsFileUtil.refreshFiles(project, affectedRoots); + for (TransactionRunnable task : myDelayedTasks) { + task.run(exceptions); + } myDelayedTasks.clear(); vcs.showErrors(exceptions, actionName); } + /** + * Return true to indicate that the final tasks should be executed after the action invocation, + * false if the task is responsible to call the final tasks manually via {@link #runFinalTasks(Project, GitVcs, Set, String, List)}. + */ + protected boolean executeFinalTasksSynchronously() { + return true; + } + protected static boolean isRebasing(AnActionEvent e) { final Project project = e.getData(PlatformDataKeys.PROJECT); if (project != null) { diff --git a/plugins/git4idea/src/git4idea/merge/GitMergeUtil.java b/plugins/git4idea/src/git4idea/merge/GitMergeUtil.java index bcdbe705db5f..86e9bef33299 100644 --- a/plugins/git4idea/src/git4idea/merge/GitMergeUtil.java +++ b/plugins/git4idea/src/git4idea/merge/GitMergeUtil.java @@ -31,6 +31,7 @@ import com.intellij.openapi.vcs.update.UpdatedFiles; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.ui.UIUtil; import git4idea.GitRevisionNumber; import git4idea.GitVcs; import git4idea.actions.GitRepositoryAction; @@ -141,10 +142,15 @@ public class GitMergeUtil { } action.delayTask(new TransactionRunnable() { public void run(List exceptionList) { - ProjectLevelVcsManagerEx manager = (ProjectLevelVcsManagerEx)ProjectLevelVcsManager.getInstance(project); - UpdateInfoTree tree = manager.showUpdateProjectInfo(files, actionName, actionInfo, false); - tree.setBefore(beforeLabel); - tree.setAfter(LocalHistory.getInstance().putSystemLabel(project, "After update")); + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + ProjectLevelVcsManagerEx manager = (ProjectLevelVcsManagerEx)ProjectLevelVcsManager.getInstance(project); + UpdateInfoTree tree = manager.showUpdateProjectInfo(files, actionName, actionInfo, false); + tree.setBefore(beforeLabel); + tree.setAfter(LocalHistory.getInstance().putSystemLabel(project, "After update")); + } + }); } }); final Collection unmergedNames = files.getGroupById(FileGroup.MERGED_WITH_CONFLICT_ID).getFiles(); @@ -159,7 +165,15 @@ public class GitMergeUtil { unmerged.add(f); } } - AbstractVcsHelper.getInstance(project).showMergeDialog(unmerged, GitVcs.getInstance(project).getMergeProvider()); + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + GitVcs vcs = GitVcs.getInstance(project); + if (vcs != null) { + AbstractVcsHelper.getInstance(project).showMergeDialog(unmerged, vcs.getMergeProvider()); + } + } + }); } }); }