for (GitLineHandlerListener listener : listeners) {
h.addLineListener(listener);
}
- if (!pushSpec.isPushAll()) {
- GitRemote remote = pushSpec.getRemote();
- LOG.assertTrue(remote != null, "Remote can't be null: " + pushSpec);
- h.addParameters(remote.getName());
- GitBranch remoteBranch = pushSpec.getDest();
- String destination = remoteBranch.getName().replaceFirst(remote.getName() + "/", "");
- h.addParameters(pushSpec.getSource().getName() + ":" + destination);
- }
+ GitRemote remote = pushSpec.getRemote();
+ h.addParameters(remote.getName());
+ GitBranch remoteBranch = pushSpec.getDest();
+ String destination = remoteBranch.getName().replaceFirst(remote.getName() + "/", "");
+ h.addParameters(pushSpec.getSource().getName() + ":" + destination);
return run(h, true);
}
import javax.swing.*;
import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
private static final Logger LOG = Logger.getInstance(GitPushDialog.class);
private static final String DEFAULT_REMOTE = "origin";
- private JComponent myRootPanel;
private Project myProject;
private final GitPusher myPusher;
private final GitPushLog myListPanel;
private Map<GitRepository, GitPushSpec> myPushSpecs;
private final Collection<GitRepository> myRepositories;
private final JBLoadingPanel myLoadingPanel;
- private final JCheckBox myPushAllCheckbox;
private final Object COMMITS_LOADING_LOCK = new Object();
private final GitManualPushToBranch myRefspecPanel;
private final AtomicReference<String> myDestBranchInfoOnRefresh = new AtomicReference<String>();
myRepositories = GitRepositoryManager.getInstance(myProject).getRepositories();
myLoadingPanel = new JBLoadingPanel(new BorderLayout(), this.getDisposable());
- myPushAllCheckbox = new JCheckBox("Push all branches", false);
- myPushAllCheckbox.setMnemonic('p');
- myPushAllCheckbox.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- loadCommitsInBackground();
- }
- });
- /* hidden: it may confuse users, the target is not clear, hidden until really needed,
- not removed completely because it is default behavior for 'git push' in command line. */
- myPushAllCheckbox.setVisible(false);
myListPanel = new GitPushLog(myProject, myRepositories, new RepositoryCheckboxListener());
myRefspecPanel = new GitManualPushToBranch(myRepositories, new RefreshButtonListener());
init();
setOKButtonText("Push");
setTitle("Git Push");
-
}
@Override
protected JComponent createCenterPanel() {
JPanel optionsPanel = new JPanel(new BorderLayout());
- optionsPanel.add(myPushAllCheckbox, BorderLayout.NORTH);
optionsPanel.add(myRefspecPanel);
- myRootPanel = new JPanel(new BorderLayout(0, 15));
- myRootPanel.add(createCommitListPanel(), BorderLayout.CENTER);
- myRootPanel.add(optionsPanel, BorderLayout.SOUTH);
- return myRootPanel;
+ JComponent rootPanel = new JPanel(new BorderLayout(0, 15));
+ rootPanel.add(createCommitListPanel(), BorderLayout.CENTER);
+ rootPanel.add(optionsPanel, BorderLayout.SOUTH);
+ return rootPanel;
}
@Nullable
private String collectInfoToPush() {
try {
- boolean pushAll = myPushAllCheckbox.isSelected();
- myPushSpecs = pushAll ? pushSpecsForPushAll() : pushSpecsForCurrentOrEnteredBranches();
+ myPushSpecs = pushSpecsForCurrentOrEnteredBranches();
myGitCommitsToPush = myPusher.collectCommitsToPush(myPushSpecs);
return null;
}
return null;
}
- private Map<GitRepository, GitPushSpec> pushSpecsForPushAll() {
- Map<GitRepository, GitPushSpec> specs = new HashMap<GitRepository, GitPushSpec>();
- for (GitRepository repository : myRepositories) {
- specs.put(repository, GitPushSpec.pushAllSpec());
- }
- return specs;
- }
-
@Override
public JComponent getPreferredFocusedComponent() {
return myListPanel.getPreferredFocusComponent();
*/
package git4idea.push;
-import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vcs.VcsException;
import git4idea.GitBranch;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* @author Kirill Likhodedov
*/
public class GitPushSpec {
- private static final Logger LOG = Logger.getInstance(GitPushSpec.class);
-
- private final GitRemote myRemote;
+ @NotNull private final GitRemote myRemote;
@NotNull private final GitBranch mySource;
@NotNull private final GitBranch myDest;
- private final boolean myPushAll;
GitPushSpec(@NotNull GitRemote remote, @NotNull GitBranch source, @NotNull GitBranch dest) {
myRemote = remote;
mySource = source;
myDest = dest;
- myPushAll = false;
- }
-
- private GitPushSpec() {
- myRemote = null;
- mySource = null;
- myDest = null;
- myPushAll = true;
}
- static GitPushSpec pushAllSpec() {
- return new GitPushSpec();
- }
-
- @Nullable
+ @NotNull
public GitRemote getRemote() {
return myRemote;
}
return myDest;
}
- /**
- * Parses the refspec to identify local branches that are to be pushed together with remote "destination" branches.
- * @throws VcsException When looking for thacking branches.
- * TODO read tracking information from the config file, i.e. getting rid from the possible exception here.
- */
- @NotNull
- static List<GitBranchPair> getBranchesForPushAll(@NotNull GitRepository repository) throws VcsException {
- List<GitBranchPair> sourceDests = new ArrayList<GitBranchPair>();
- for (GitBranch branch : repository.getBranches().getLocalBranches()) {
- GitBranchPair forBranch = findSourceDestForBranch(repository, branch);
- if (forBranch != null) {
- sourceDests.add(forBranch);
- }
- }
- return sourceDests;
- }
-
- public boolean isPushAll() {
- return myPushAll;
- }
-
@Nullable
private static GitBranchPair findSourceDestForBranch(GitRepository repository, GitBranch branch) throws VcsException {
GitBranch trackedBranch = branch.tracked(repository.getProject(), repository.getRoot());
}
/**
- *
- *
- *
- * @param pushSpec which branches in which repositories should be pushed.
+ * @param pushSpecs which branches in which repositories should be pushed.
* The most common situation is all repositories in the project with a single currently active branch for
* each of them.
* @throws VcsException if couldn't query 'git log' about commits to be pushed.
if (pushSpec == null) {
continue;
}
- if (!pushSpec.isPushAll()) {
- res.put(repository, Collections.singletonList(new GitBranchPair(pushSpec.getSource(), pushSpec.getDest())));
- } else {
- res.put(repository, GitPushSpec.getBranchesForPushAll(repository));
- }
+ res.put(repository, Collections.singletonList(new GitBranchPair(pushSpec.getSource(), pushSpec.getDest())));
}
return res;
}
return GitSimplePushResult.notPushed();
}
- if (pushSpec.isPushAll()) {
- // TODO support pushing to different branches with http remotes from one and ssh from other.
- // Currently it is a hack - get just one remote url and hope that others are the same type and the same server.
- String remoteUrl = null;
- for (GitBranch branch : commitsByBranch.getBranches()) {
- if (remoteUrl != null) {
- break;
- }
- try {
- String remoteName = branch.getTrackedRemoteName(repository.getProject(), repository.getRoot());
- GitRemote remote = GitUtil.findRemoteByName(repository, remoteName);
- if (remote != null) {
- if (!remote.getPushUrls().isEmpty()) {
- remoteUrl = remote.getPushUrls().iterator().next();
- }
- }
- }
- catch (VcsException e) {
- LOG.info(e);
- }
- }
-
- if (remoteUrl == null) {
- return pushNatively(repository, pushSpec);
- }
- else {
- return GitHttpAdapter.shouldUseJGit(remoteUrl) ? GitHttpAdapter.push(repository, null, remoteUrl, null) : pushNatively(repository, pushSpec);
+ GitRemote remote = pushSpec.getRemote();
+ String httpUrl = null;
+ for (String pushUrl : remote.getPushUrls()) {
+ if (GitHttpAdapter.shouldUseJGit(pushUrl)) {
+ httpUrl = pushUrl;
+ break; // TODO support http and ssh urls in one origin
}
}
+ if (httpUrl != null) {
+ return GitHttpAdapter.push(repository, remote, httpUrl, formPushSpec(pushSpec, remote));
+ }
else {
- GitRemote remote = pushSpec.getRemote();
- assert remote != null : "Remote can't be null for pushSpec " + pushSpec;
- String httpUrl = null;
- for (String pushUrl : remote.getPushUrls()) {
- if (GitHttpAdapter.shouldUseJGit(pushUrl)) {
- httpUrl = pushUrl;
- break; // TODO support http and ssh urls in one origin
- }
- }
- if (httpUrl != null) {
- return GitHttpAdapter.push(repository, remote, httpUrl, formPushSpec(pushSpec, remote));
- }
- else {
- return pushNatively(repository, pushSpec);
- }
+ return pushNatively(repository, pushSpec);
}
}