IDEA-80311 Git: Select repository with unmerged changes in GitBranchIsNotFullyMerged...
authorKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Fri, 27 Jan 2012 18:00:36 +0000 (22:00 +0400)
committerKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Fri, 27 Jan 2012 18:00:36 +0000 (22:00 +0400)
Instead of showing the first one which may have no unmerged commits.

plugins/git4idea/src/git4idea/branch/GitBranchIsNotFullyMergedDialog.java

index 74d90b17b641295786ee719a0a2aedd9964800a1..2f6e0d5960ee130604efa43db01d5dd82e280744 100644 (file)
@@ -28,7 +28,6 @@ import git4idea.i18n.GitBundle;
 import git4idea.repo.GitRepository;
 import git4idea.ui.GitCommitListWithDiffPanel;
 import git4idea.ui.GitRepositoryComboboxListCellRenderer;
-import git4idea.util.GitUIUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -94,7 +93,7 @@ public class GitBranchIsNotFullyMergedDialog extends DialogWrapper {
     myMergedToBranches = mergedToBranches;
     myRepositories = commits.keySet();
 
-    myInitialRepository = myRepositories.iterator().next();
+    myInitialRepository = calcInitiallySelectedRepository();
     myCommitListWithDiffPanel = new GitCommitListWithDiffPanel(myProject, new ArrayList<GitCommit>(myCommits.get(myInitialRepository)));
 
     init();
@@ -104,6 +103,16 @@ public class GitBranchIsNotFullyMergedDialog extends DialogWrapper {
     setCancelButtonText("Cancel");
   }
 
+  @NotNull
+  private GitRepository calcInitiallySelectedRepository() {
+    for (GitRepository repository : myRepositories) {
+      if (!myCommits.get(repository).isEmpty()) {
+        return repository;
+      }
+    }
+    throw new AssertionError("The dialog shouldn't be shown. Unmerged commits: " + myCommits);
+  }
+
   private String makeDescription() {
     String currentBranchOrRev;
     boolean onBranch;
@@ -111,8 +120,9 @@ public class GitBranchIsNotFullyMergedDialog extends DialogWrapper {
       LOG.assertTrue(myCurrentBranch != null, "Branches have unexpectedly diverged");
       currentBranchOrRev = myCurrentBranch;
       onBranch = true;
-    } else {
-      GitRepository repository = myRepositories.iterator().next();
+    } 
+    else {
+      GitRepository repository = myInitialRepository;
       if (repository.isOnBranch()) {
         GitBranch currentBranch = repository.getCurrentBranch();
         assert currentBranch != null;
@@ -151,7 +161,7 @@ public class GitBranchIsNotFullyMergedDialog extends DialogWrapper {
     
       final JComboBox repositorySelector = new JComboBox(ArrayUtil.toObjectArray(myRepositories, GitRepository.class));
     repositorySelector.setRenderer(new GitRepositoryComboboxListCellRenderer(repositorySelector));
-    repositorySelector.setSelectedItem(GitUIUtil.getShortRepositoryName(myInitialRepository));
+    repositorySelector.setSelectedItem(myInitialRepository);
     repositorySelector.addActionListener(new ActionListener() {
       @Override
       public void actionPerformed(ActionEvent e) {