@Override
 protected void render(ColoredTreeCellRenderer renderer) {
   SimpleTextAttributes rootAttributes;
   SimpleTextAttributes branchAttributes;
   if (remoteName != null && commits.size() != 0 && remoteCommits != 0
       || currentBranch == null) {
     rootAttributes =
         SimpleTextAttributes.ERROR_ATTRIBUTES.derive(
             SimpleTextAttributes.STYLE_BOLD, null, null, null);
     branchAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
   } else if (remoteName == null || commits.size() == 0) {
     rootAttributes = SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES;
     branchAttributes = SimpleTextAttributes.GRAYED_ATTRIBUTES;
   } else {
     branchAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
     rootAttributes = SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES;
   }
   renderer.append(root.getPresentableUrl(), rootAttributes);
   if (currentBranch != null) {
     renderer.append(" [" + currentBranch, branchAttributes);
     if (remoteName != null) {
       renderer.append(" -> " + remoteName + "#" + remoteBranch, branchAttributes);
     }
     renderer.append("]", branchAttributes);
   }
 }
  @Nullable
  public static Pair<AbstractHash, AbstractHash> getStashTop(
      @NotNull Project project, @NotNull VirtualFile root) throws VcsException {
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.STASH.readLockingCommand());
    GitLogParser parser = new GitLogParser(project, SHORT_HASH, SHORT_PARENTS);
    h.setSilent(true);
    h.setNoSSH(true);
    h.addParameters("list");
    h.addParameters("-n1");
    h.addParameters(parser.getPretty());

    String out;
    h.setCharset(Charset.forName(GitConfigUtil.getLogEncoding(project, root)));
    out = h.run();
    final List<GitLogRecord> gitLogRecords = parser.parse(out);
    for (GitLogRecord gitLogRecord : gitLogRecords) {
      ProgressManager.checkCanceled();

      GitSimpleHandler h1 = new GitSimpleHandler(project, root, GitCommand.LOG);
      GitLogParser parser1 = new GitLogParser(project, SHORT_HASH, SHORT_PARENTS, SUBJECT);
      h1.setSilent(true);
      h1.setNoSSH(true);
      h1.addParameters("-n1");
      h1.addParameters(parser1.getPretty());
      // h1.endOptions();
      h1.addParameters(gitLogRecord.getShortHash());

      String out1;
      out1 = h1.run();
      final List<GitLogRecord> gitLogRecords1 = parser1.parse(out1);
      assert gitLogRecords1.size() == 1;
      final GitLogRecord logRecord = gitLogRecords1.get(0);
      final String[] parentsShortHashes = logRecord.getParentsShortHashes();
      String indexCommit = null;
      // heuristics
      if (parentsShortHashes.length == 2) {
        if (logRecord.getSubject().contains(parentsShortHashes[0])) {
          indexCommit = parentsShortHashes[1];
        }
        if (logRecord.getSubject().contains(parentsShortHashes[1])) {
          indexCommit = parentsShortHashes[0];
        }
      }
      return new Pair<AbstractHash, AbstractHash>(
          AbstractHash.create(gitLogRecord.getShortHash()),
          indexCommit == null ? null : AbstractHash.create(indexCommit));
    }
    return null;
  }
示例#3
0
 /**
  * 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
  * @deprecated because uses the java.io.File.
  * @use GitRepositoryManager#getRepositoryForFile().
  */
 @NotNull
 public static List<VirtualFile> getGitRoots(Project project, GitVcs vcs) throws VcsException {
   final VirtualFile[] contentRoots =
       ProjectLevelVcsManager.getInstance(project).getRootsUnderVcs(vcs);
   if (contentRoots == null || contentRoots.length == 0) {
     throw new VcsException(
         GitBundle.getString("repository.action.missing.roots.unconfigured.message"));
   }
   final List<VirtualFile> roots =
       new ArrayList<VirtualFile>(gitRootsForPaths(Arrays.asList(contentRoots)));
   if (roots.size() == 0) {
     throw new VcsException(GitBundle.getString("repository.action.missing.roots.misconfigured"));
   }
   Collections.sort(roots, VIRTUAL_FILE_COMPARATOR);
   return roots;
 }