Пример #1
0
  /**
   * Returns absolute paths which have changed remotely comparing to the current branch, i.e.
   * performs <code>git diff --name-only master..origin/master</code>
   *
   * <p>Paths are absolute, Git-formatted (i.e. with forward slashes).
   */
  @NotNull
  public static Collection<String> getPathsDiffBetweenRefs(
      @NotNull Git git,
      @NotNull GitRepository repository,
      @NotNull String beforeRef,
      @NotNull String afterRef)
      throws VcsException {
    List<String> parameters = Arrays.asList("--name-only", "--pretty=format:");
    String range = beforeRef + ".." + afterRef;
    GitCommandResult result = git.diff(repository, parameters, range);
    if (!result.success()) {
      LOG.info(
          String.format(
              "Couldn't get diff in range [%s] for repository [%s]",
              range, repository.toLogString()));
      return Collections.emptyList();
    }

    final Collection<String> remoteChanges = new HashSet<String>();
    for (StringScanner s = new StringScanner(result.getOutputAsJoinedString()); s.hasMoreData(); ) {
      final String relative = s.line();
      if (StringUtil.isEmptyOrSpaces(relative)) {
        continue;
      }
      final String path = repository.getRoot().getPath() + "/" + unescapePath(relative);
      remoteChanges.add(path);
    }
    return remoteChanges;
  }
 public UnstashConflictResolver(Project project, VirtualFile root, StashInfo stashInfo) {
   super(
       project,
       ServiceManager.getService(Git.class),
       ServiceManager.getService(PlatformFacade.class),
       Collections.singleton(root),
       makeParams(stashInfo));
   myRoot = root;
   myStashInfo = stashInfo;
 }
Пример #3
0
 @NotNull
 public static Map<VirtualFile, List<VirtualFile>> sortFilesByGitRootsIgnoringOthers(
     @NotNull Collection<VirtualFile> files) {
   try {
     return sortFilesByGitRoot(files, true);
   } catch (VcsException e) {
     LOG.error("Should never happen, since we passed 'ignore non-git' parameter", e);
     return Collections.emptyMap();
   }
 }
 /**
  * Update the tree according to the list of loaded roots
  *
  * @param roots the list of roots to add to the tree
  * @param uncheckedCommits the map from vcs root to commit identifiers that should be
  *     uncheckedCommits
  */
 private void updateTree(List<Root> roots, Map<VirtualFile, Set<String>> uncheckedCommits) {
   myTreeRoot.removeAllChildren();
   if (roots == null) {
     roots = Collections.emptyList();
   }
   for (Root r : roots) {
     CheckedTreeNode rootNode = new CheckedTreeNode(r);
     Status status = new Status();
     status.root = r;
     rootNode.add(new DefaultMutableTreeNode(status, false));
     Set<String> unchecked =
         uncheckedCommits != null && uncheckedCommits.containsKey(r.root)
             ? uncheckedCommits.get(r.root)
             : Collections.<String>emptySet();
     for (Commit c : r.commits) {
       CheckedTreeNode child = new CheckedTreeNode(c);
       rootNode.add(child);
       child.setChecked(r.remoteName != null && !unchecked.contains(c.commitId()));
     }
     myTreeRoot.add(rootNode);
   }
 }
Пример #5
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;
 }
  private RebaseInfo collectRebaseInfo() {
    final Set<VirtualFile> roots = new HashSet<VirtualFile>();
    final Set<VirtualFile> rootsWithMerges = new HashSet<VirtualFile>();
    final Map<VirtualFile, List<String>> reorderedCommits =
        new HashMap<VirtualFile, List<String>>();
    final Map<VirtualFile, Set<String>> uncheckedCommits = new HashMap<VirtualFile, Set<String>>();
    for (int i = 0; i < myTreeRoot.getChildCount(); i++) {
      CheckedTreeNode node = (CheckedTreeNode) myTreeRoot.getChildAt(i);
      Root r = (Root) node.getUserObject();
      Set<String> unchecked = new HashSet<String>();
      uncheckedCommits.put(r.root, unchecked);
      if (r.commits.size() == 0) {
        if (r.remoteCommits > 0) {
          roots.add(r.root);
        }
        continue;
      }
      boolean seenCheckedNode = false;
      boolean reorderNeeded = false;
      boolean seenMerges = false;
      for (int j = 0; j < node.getChildCount(); j++) {
        if (node.getChildAt(j) instanceof CheckedTreeNode) {
          CheckedTreeNode commitNode = (CheckedTreeNode) node.getChildAt(j);
          Commit commit = (Commit) commitNode.getUserObject();
          seenMerges |= commit.isMerge;
          if (commitNode.isChecked()) {
            seenCheckedNode = true;
          } else {
            unchecked.add(commit.commitId());
            if (seenCheckedNode) {
              reorderNeeded = true;
            }
          }
        }
      }
      if (seenMerges) {
        rootsWithMerges.add(r.root);
      }
      if (r.remoteCommits > 0 || reorderNeeded) {
        roots.add(r.root);
      }
      if (reorderNeeded) {
        List<String> reordered = new ArrayList<String>();
        for (int j = 0; j < node.getChildCount(); j++) {
          if (node.getChildAt(j) instanceof CheckedTreeNode) {
            CheckedTreeNode commitNode = (CheckedTreeNode) node.getChildAt(j);
            if (!commitNode.isChecked()) {
              Commit commit = (Commit) commitNode.getUserObject();
              reordered.add(commit.revision.asString());
            }
          }
        }
        for (int j = 0; j < node.getChildCount(); j++) {
          if (node.getChildAt(j) instanceof CheckedTreeNode) {
            CheckedTreeNode commitNode = (CheckedTreeNode) node.getChildAt(j);
            if (commitNode.isChecked()) {
              Commit commit = (Commit) commitNode.getUserObject();
              reordered.add(commit.revision.asString());
            }
          }
        }
        Collections.reverse(reordered);
        reorderedCommits.put(r.root, reordered);
      }
    }
    final GitVcsSettings.UpdateChangesPolicy p =
        UpdatePolicyUtils.getUpdatePolicy(myStashRadioButton, myShelveRadioButton);
    assert p == GitVcsSettings.UpdateChangesPolicy.STASH
        || p == GitVcsSettings.UpdateChangesPolicy.SHELVE;

    return new RebaseInfo(reorderedCommits, rootsWithMerges, uncheckedCommits, roots, p);
  }