IDEA-89881 git push to an alternative branch pushed to the tracked branch instead
authorKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Thu, 9 Aug 2012 11:03:33 +0000 (15:03 +0400)
committerKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Thu, 9 Aug 2012 11:03:33 +0000 (15:03 +0400)
Merge remote-tracking branch 'idea_release/fix_for_11.1'

Conflicts:
plugins/git4idea/src/git4idea/push/GitPushDialog.java

1  2 
plugins/git4idea/src/git4idea/push/GitPushDialog.java

index c4172595676b588c3cec2e04eed2b14ae2108876,8d665304b9382dbb614140ba79ca9c114a10d250..53fd94158637463cd4008f31c6b8acd8cf9ec475
@@@ -27,18 -27,17 +27,18 @@@ import com.intellij.util.Consumer
  import com.intellij.util.ui.UIUtil;
  import git4idea.GitBranch;
  import git4idea.GitUtil;
 +import git4idea.branch.GitBranchUtil;
  import git4idea.history.browser.GitCommit;
  import git4idea.repo.GitRemote;
  import git4idea.repo.GitRepository;
 +import git4idea.repo.GitRepositoryManager;
  import org.jetbrains.annotations.NotNull;
  import org.jetbrains.annotations.Nullable;
  
  import javax.swing.*;
  import java.awt.*;
 -import java.util.Collection;
 -import java.util.HashMap;
 -import java.util.Map;
 +import java.util.*;
 +import java.util.List;
  import java.util.concurrent.atomic.AtomicReference;
  
  /**
@@@ -50,7 -49,6 +50,7 @@@ public class GitPushDialog extends Dial
    private static final String DEFAULT_REMOTE = "origin";
  
    private Project myProject;
 +  private final GitRepositoryManager myRepositoryManager;
    private final GitPusher myPusher;
    private final GitPushLog myListPanel;
    private GitCommitsByRepoAndBranch myGitCommitsToPush;
@@@ -67,9 -65,8 +67,9 @@@
      super(project);
      myProject = project;
      myPusher = new GitPusher(myProject, new EmptyProgressIndicator());
 +    myRepositoryManager = GitUtil.getRepositoryManager(myProject);
  
 -    myRepositories = GitUtil.getRepositoryManager(myProject).getRepositories();
 +    myRepositories = getRepositoriesWithRemotes();
  
      myLoadingPanel = new JBLoadingPanel(new BorderLayout(), this.getDisposable());
  
  
      init();
      setOKButtonText("Push");
 +    setOKButtonMnemonic('P');
      setTitle("Git Push");
    }
  
 +  @NotNull
 +  private List<GitRepository> getRepositoriesWithRemotes() {
 +    List<GitRepository> repositories = new ArrayList<GitRepository>();
 +    for (GitRepository repository : myRepositoryManager.getRepositories()) {
 +      if (!repository.getRemotes().isEmpty()) {
 +        repositories.add(repository);
 +      }
 +    }
 +    return repositories;
 +  }
 +
    @Override
    protected JComponent createCenterPanel() {
      JPanel optionsPanel = new JPanel(new BorderLayout());
        LOG.info("collectInfoToPush...");
        myPushSpecs = pushSpecsForCurrentOrEnteredBranches();
        myGitCommitsToPush = myPusher.collectCommitsToPush(myPushSpecs);
-       LOG.info("collectInfoToPush | Collected commits to push: " + logMessageForCommits(myGitCommitsToPush));
+       LOG.info(String.format("collectInfoToPush | Collected commits to push. Push spec: %s, commits: %s",
+                              myPushSpecs, logMessageForCommits(myGitCommitsToPush)));
        return null;
      }
      catch (VcsException e) {
        String remoteName = currentBranch.getTrackedRemoteName(repository.getProject(), repository.getRoot());
        String trackedBranchName = currentBranch.getTrackedBranchName(repository.getProject(), repository.getRoot());
        GitRemote remote = GitUtil.findRemoteByName(repository, remoteName);
-       GitBranch tracked = GitBranchUtil.findRemoteBranchByName(repository, remote, trackedBranchName);
-       if (remote == null || tracked == null) {
 -      GitBranch targetBranch = findRemoteBranchByName(repository, remote, trackedBranchName);
++      GitBranch targetBranch = GitBranchUtil.findRemoteBranchByName(repository, remote, trackedBranchName);
+       if (remote == null || targetBranch == null) {
          Pair<GitRemote,GitBranch> remoteAndBranch = GitUtil.findMatchingRemoteBranch(repository, currentBranch);
          if (remoteAndBranch == null) {
            remote = myRefspecPanel.getSelectedRemote();
-           tracked = GitPusher.NO_TARGET_BRANCH;
+           targetBranch = GitPusher.NO_TARGET_BRANCH;
          } else {
            remote = remoteAndBranch.getFirst();
-           tracked = remoteAndBranch.getSecond();
+           targetBranch = remoteAndBranch.getSecond();
          }
        }
  
        if (myRefspecPanel.turnedOn()) {
          String manualBranchName = myRefspecPanel.getBranchToPush();
          remote = myRefspecPanel.getSelectedRemote();
 -        GitBranch manualBranch = findRemoteBranchByName(repository, remote, manualBranchName);
 +        GitBranch manualBranch = GitBranchUtil.findRemoteBranchByName(repository, remote, manualBranchName);
          if (manualBranch == null) {
            if (!manualBranchName.startsWith("refs/remotes/")) {
              manualBranchName = myRefspecPanel.getSelectedRemote().getName() + "/" + manualBranchName;
            }
            manualBranch = new GitBranch(manualBranchName, false, true);
          }
-         tracked = manualBranch;
+         targetBranch = manualBranch;
        }
  
-       GitPushSpec pushSpec = new GitPushSpec(remote, currentBranch, tracked);
+       GitPushSpec pushSpec = new GitPushSpec(remote, currentBranch, targetBranch);
        defaultSpecs.put(repository, pushSpec);
      }
      return defaultSpecs;
    }
  
 -  @Nullable
 -  private static GitBranch findRemoteBranchByName(@NotNull GitRepository repository, @Nullable GitRemote remote, @Nullable String name) {
 -    if (name == null || remote == null) {
 -      return null;
 -    }
 -    final String BRANCH_PREFIX = "refs/heads/";
 -    if (name.startsWith(BRANCH_PREFIX)) {
 -      name = name.substring(BRANCH_PREFIX.length());
 -    }
 -
 -    for (GitBranch branch : repository.getBranches().getRemoteBranches()) {
 -      if (branch.getName().equals(remote.getName() + "/" + name)) {
 -        return branch;
 -      }
 -    }
 -    return null;
 -  }
 -
    @Override
    public JComponent getPreferredFocusedComponent() {
      return myListPanel.getPreferredFocusComponent();
      if (savedValue == null) {
        return currentDestBranchValue != null;
      }
-     return !savedValue.equals(myDestBranchInfoOnRefresh.get());
+     return !savedValue.equals(currentDestBranchValue);
    }
  
    private class RepositoryCheckboxListener implements Consumer<Boolean> {