diff --git a/plugins/git4idea/src/git4idea/actions/GitRepositoryAction.java b/plugins/git4idea/src/git4idea/actions/GitRepositoryAction.java index a1baf54e9073..6690da0abc1a 100644 --- a/plugins/git4idea/src/git4idea/actions/GitRepositoryAction.java +++ b/plugins/git4idea/src/git4idea/actions/GitRepositoryAction.java @@ -33,6 +33,7 @@ import git4idea.GitUtil; import git4idea.GitVcs; import git4idea.i18n.GitBundle; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; @@ -62,19 +63,8 @@ public abstract class GitRepositoryAction extends DumbAwareAction { return; } GitVcs vcs = GitVcs.getInstance(project); - final VirtualFile[] contentRoots = ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(vcs); - if (contentRoots == null || contentRoots.length == 0) { - Messages.showErrorDialog(project, GitBundle.getString("repository.action.missing.roots.unconfigured.message"), - GitBundle.getString("repository.action.missing.roots.title")); - return; - } - final List roots = new ArrayList(GitUtil.gitRootsForPaths(Arrays.asList(contentRoots))); - if (roots.size() == 0) { - Messages.showErrorDialog(project, GitBundle.getString("repository.action.missing.roots.misconfigured"), - GitBundle.getString("repository.action.missing.roots.title")); - return; - } - Collections.sort(roots, GitUtil.VIRTUAL_FILE_COMPARATOR); + final List roots = getGitRoots(project, vcs); + if (roots == null) return; // get default root final VirtualFile[] vFiles = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY); VirtualFile defaultRootVar = null; @@ -114,6 +104,32 @@ public abstract class GitRepositoryAction extends DumbAwareAction { vcs.showErrors(exceptions, actionName); } + /** + * Get git roots for the project. The method shows dialogs in the case when roots cannot be retrieved, so it should be called + * from the event dispatch thread. + * + * @param project the project + * @param vcs the git Vcs + * @return the list of the roots, or null + */ + @Nullable + public static List getGitRoots(Project project, GitVcs vcs) { + final VirtualFile[] contentRoots = ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(vcs); + if (contentRoots == null || contentRoots.length == 0) { + Messages.showErrorDialog(project, GitBundle.getString("repository.action.missing.roots.unconfigured.message"), + GitBundle.getString("repository.action.missing.roots.title")); + return null; + } + final List roots = new ArrayList(GitUtil.gitRootsForPaths(Arrays.asList(contentRoots))); + if (roots.size() == 0) { + Messages.showErrorDialog(project, GitBundle.getString("repository.action.missing.roots.misconfigured"), + GitBundle.getString("repository.action.missing.roots.title")); + return null; + } + Collections.sort(roots, GitUtil.VIRTUAL_FILE_COMPARATOR); + return roots; + } + /** * Delay task to be executed after refresh * diff --git a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java index 594b5a6102a9..9ad56f51a41f 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java +++ b/plugins/git4idea/src/git4idea/checkin/GitCheckinEnvironment.java @@ -30,9 +30,12 @@ import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager; import com.intellij.openapi.vcs.checkin.CheckinEnvironment; import com.intellij.openapi.vcs.ui.RefreshableOnComponent; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.ui.UIUtil; import com.intellij.vcsUtil.VcsUtil; import git4idea.GitUtil; -import git4idea.commands.*; +import git4idea.commands.GitCommand; +import git4idea.commands.GitFileUtils; +import git4idea.commands.GitSimpleHandler; import git4idea.config.GitConfigUtil; import git4idea.config.GitVcsSettings; import git4idea.i18n.GitBundle; @@ -216,19 +219,6 @@ public class GitCheckinEnvironment implements CheckinEnvironment { log.warn("Failed to remove temporary file: " + messageFile); } } - if (myNextCommitIsPushed != null && myNextCommitIsPushed.booleanValue()) { - // push - GitLineHandler pushHandler = GitPushUtils.preparePush(myProject, root); - if (pushHandler != null) { - Collection problems = GitHandlerUtil.doSynchronouslyWithExceptions(pushHandler); - for (VcsException e : problems) { - if (!isNoOrigin(e)) { - // no origin exception just means that push was not applicable to the repository - exceptions.add(e); - } - } - } - } } catch (VcsException e) { exceptions.add(e); @@ -240,6 +230,14 @@ public class GitCheckinEnvironment implements CheckinEnvironment { } } } + if (myNextCommitIsPushed != null && myNextCommitIsPushed.booleanValue() && exceptions.isEmpty()) { + // push + UIUtil.invokeLaterIfNeeded(new Runnable() { + public void run() { + GitPushActiveBranchesDialog.showDialogForProject(myProject); + } + }); + } return exceptions; } @@ -327,7 +325,7 @@ public class GitCheckinEnvironment implements CheckinEnvironment { GitBundle.getString("commit.partial.merge.title"), null); } - } ); + }); } catch (RuntimeException ex) { throw ex; @@ -378,17 +376,6 @@ public class GitCheckinEnvironment implements CheckinEnvironment { return -1 != ex.getMessage().indexOf("fatal: cannot do a partial commit during a merge."); } - /** - * Check if the exception means that no origin was found for pus operation - * - * @param ex an exception to use - * @return true if exception means that changes cannot be pushed because repository is entirely local. - */ - private static boolean isNoOrigin(final VcsException ex) { - //noinspection HardCodedStringLiteral - return ex.getMessage().indexOf("': unable to chdir or not a git archive") != -1; - } - /** * Update index (delete and remove files) * @@ -497,7 +484,8 @@ public class GitCheckinEnvironment implements CheckinEnvironment { handler.setNoSSH(true); if (isFirst) { isFirst = false; - } else { + } + else { handler.addParameters("--amend"); } handler.addParameters("--only", "-F", message.getAbsolutePath()); diff --git a/plugins/git4idea/src/git4idea/checkin/GitPushActiveBranchesDialog.java b/plugins/git4idea/src/git4idea/checkin/GitPushActiveBranchesDialog.java index 92ee3727b197..ed9abf9d6b1f 100644 --- a/plugins/git4idea/src/git4idea/checkin/GitPushActiveBranchesDialog.java +++ b/plugins/git4idea/src/git4idea/checkin/GitPushActiveBranchesDialog.java @@ -30,6 +30,7 @@ import git4idea.GitBranch; import git4idea.GitRevisionNumber; import git4idea.GitUtil; import git4idea.GitVcs; +import git4idea.actions.GitRepositoryAction; import git4idea.actions.GitShowAllSubmittedFilesAction; import git4idea.commands.*; import git4idea.config.GitVcsSettings; @@ -430,7 +431,7 @@ public class GitPushActiveBranchesDialog extends DialogWrapper { */ @Override protected String getHelpId() { - return "reference?.?VersionControl?.?Git?.?PushActiveBranches"; + return "reference.VersionControl.Git.PushActiveBranches"; } /** @@ -511,6 +512,22 @@ public class GitPushActiveBranchesDialog extends DialogWrapper { return rc; } + /** + * Show dialog for the project + * + * @param project the project to show dialog for + */ + public static void showDialogForProject(final Project project) { + GitVcs vcs = GitVcs.getInstance(project); + List roots = GitRepositoryAction.getGitRoots(project, vcs); + if (roots == null) { + return; + } + List pushExceptions = new ArrayList(); + showDialog(project, roots, pushExceptions); + vcs.showErrors(pushExceptions, GitBundle.getString("push.active.action.name")); + } + /** * Show the dialog *