示例#1
0
 /**
  * Get git roots for the selected paths
  *
  * @param filePaths the context paths
  * @return a set of git roots
  */
 public static Set<VirtualFile> gitRoots(final Collection<FilePath> filePaths) {
   HashSet<VirtualFile> rc = new HashSet<VirtualFile>();
   for (FilePath path : filePaths) {
     final VirtualFile root = getGitRootOrNull(path);
     if (root != null) {
       rc.add(root);
     }
   }
   return rc;
 }
示例#2
0
 /**
  * Get git roots from content roots
  *
  * @param roots git content roots
  * @return a content root
  */
 public static Set<VirtualFile> gitRootsForPaths(final Collection<VirtualFile> roots) {
   HashSet<VirtualFile> rc = new HashSet<VirtualFile>();
   for (VirtualFile root : roots) {
     VirtualFile f = root;
     do {
       if (f.findFileByRelativePath(DOT_GIT) != null) {
         rc.add(f);
         break;
       }
       f = f.getParent();
     } while (f != null);
   }
   return rc;
 }
 /** Update state dialog depending on the current state of the fields */
 private void updateDialogState() {
   String branch = myBranchTextField.getText();
   if (branch.length() != 0) {
     setOKButtonText(GitBundle.getString("unstash.button.branch"));
     myPopStashCheckBox.setEnabled(false);
     myPopStashCheckBox.setSelected(true);
     myReinstateIndexCheckBox.setEnabled(false);
     myReinstateIndexCheckBox.setSelected(true);
     if (!GitBranchNameValidator.INSTANCE.checkInput(branch)) {
       setErrorText(GitBundle.getString("unstash.error.invalid.branch.name"));
       setOKActionEnabled(false);
       return;
     }
     if (myBranches.contains(branch)) {
       setErrorText(GitBundle.getString("unstash.error.branch.exists"));
       setOKActionEnabled(false);
       return;
     }
   } else {
     if (!myPopStashCheckBox.isEnabled()) {
       myPopStashCheckBox.setSelected(false);
     }
     myPopStashCheckBox.setEnabled(true);
     setOKButtonText(
         myPopStashCheckBox.isSelected()
             ? GitBundle.getString("unstash.button.pop")
             : GitBundle.getString("unstash.button.apply"));
     if (!myReinstateIndexCheckBox.isEnabled()) {
       myReinstateIndexCheckBox.setSelected(false);
     }
     myReinstateIndexCheckBox.setEnabled(true);
   }
   if (myStashList.getModel().getSize() == 0) {
     myViewButton.setEnabled(false);
     myDropButton.setEnabled(false);
     myClearButton.setEnabled(false);
     setErrorText(null);
     setOKActionEnabled(false);
     return;
   } else {
     myClearButton.setEnabled(true);
   }
   if (myStashList.getSelectedIndex() == -1) {
     myViewButton.setEnabled(false);
     myDropButton.setEnabled(false);
     setErrorText(null);
     setOKActionEnabled(false);
     return;
   } else {
     myViewButton.setEnabled(true);
     myDropButton.setEnabled(true);
   }
   setErrorText(null);
   setOKActionEnabled(true);
 }
 /** Refresh stash list */
 private void refreshStashList() {
   final DefaultListModel listModel = (DefaultListModel) myStashList.getModel();
   listModel.clear();
   GitStashUtils.loadStashStack(
       myProject,
       getGitRoot(),
       new Consumer<StashInfo>() {
         @Override
         public void consume(StashInfo stashInfo) {
           listModel.addElement(stashInfo);
         }
       });
   myBranches.clear();
   try {
     GitBranch.listAsStrings(myProject, getGitRoot(), false, true, myBranches, null);
   } catch (VcsException e) {
     // ignore error
   }
   myStashList.setSelectedIndex(0);
 }