git4idea: "Commit and Push" action now invokes "Push Active Branches" dialog instead of silent pushing.

This commit is contained in:
Constantine Plotnikov
2010-06-03 20:15:43 +04:00
parent 926c94b75e
commit d9b4f71de6
3 changed files with 62 additions and 41 deletions
@@ -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<VirtualFile> roots = new ArrayList<VirtualFile>(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<VirtualFile> 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<VirtualFile> 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<VirtualFile> roots = new ArrayList<VirtualFile>(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
*
@@ -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<VcsException> 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());
@@ -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<VirtualFile> roots = GitRepositoryAction.getGitRoots(project, vcs);
if (roots == null) {
return;
}
List<VcsException> pushExceptions = new ArrayList<VcsException>();
showDialog(project, roots, pushExceptions);
vcs.showErrors(pushExceptions, GitBundle.getString("push.active.action.name"));
}
/**
* Show the dialog
*