コード例 #1
0
 private static boolean noBranchesToCompare(@NotNull GitRepository repository) {
   int locals = repository.getBranches().getLocalBranches().size();
   boolean haveRemotes = !repository.getBranches().getRemoteBranches().isEmpty();
   if (repository.isOnBranch()) { // there are other branches to compare
     return locals < 2 && !haveRemotes;
   }
   return locals == 0 && !haveRemotes; // there are at least 1 branch to compare
 }
  private String makeDescription() {
    String currentBranchOrRev;
    boolean onBranch;
    if (myRepositories.size() > 1) {
      LOG.assertTrue(myBaseBranch != null, "Branches have unexpectedly diverged");
      currentBranchOrRev = myBaseBranch;
      onBranch = true;
    } else {
      GitRepository repository = myInitialRepository;
      if (repository.isOnBranch()) {
        GitBranch currentBranch = repository.getCurrentBranch();
        assert currentBranch != null;
        currentBranchOrRev = currentBranch.getName();
        onBranch = true;
      } else {
        currentBranchOrRev = repository.getCurrentRevision();
        onBranch = false;
      }
    }

    StringBuilder description = new StringBuilder();
    if (onBranch) {
      description.append(
          GitBundle.message(
              "branch.delete.not_fully_merged.description", myBranchToDelete, myBaseBranch));
    } else {
      description.append(
          GitBundle.message(
              "branch.delete.not_fully_merged.description.not_on_branch",
              myBranchToDelete,
              currentBranchOrRev,
              myBaseBranch));
    }
    if (!myMergedToBranches.isEmpty()) {
      String listOfMergedBranches =
          StringUtil.join(
              StringUtil.surround(ArrayUtil.toStringArray(myMergedToBranches), "<b>", "</b>"),
              ", ");
      description.append("<br>");
      if (myMergedToBranches.size() == 1) {
        description.append(
            GitBundle.message(
                "branch.delete.merged_to.one", myBranchToDelete, listOfMergedBranches));
      } else {
        description.append(
            GitBundle.message(
                "branch.delete.merged_to.many", myBranchToDelete, listOfMergedBranches));
      }
    }
    description.append("<br>").append(GitBundle.message("branch.delete.warning", myBranchToDelete));
    return description.toString();
  }
コード例 #3
0
 /**
  * Scans the Git roots, selected for commit, for the root which is on a detached HEAD. Returns
  * null, if all repositories are on the branch. There might be several detached repositories, -
  * in that case only one is returned. This is because the situation is very rare, while it
  * requires a lot of additional effort of making a well-formed message.
  */
 @Nullable
 private DetachedRoot getDetachedRoot() {
   GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(myPanel.getProject());
   for (VirtualFile root : getSelectedRoots()) {
     GitRepository repository = repositoryManager.getRepositoryForRoot(root);
     if (repository == null) {
       continue;
     }
     if (!repository.isOnBranch()) {
       return new DetachedRoot(root, repository.isRebaseInProgress());
     }
   }
   return null;
 }
コード例 #4
0
  private static List<String> getBranchNamesExceptCurrent(GitRepository repository) {
    List<GitBranch> localBranches =
        new ArrayList<GitBranch>(repository.getBranches().getLocalBranches());
    Collections.sort(localBranches);
    List<GitBranch> remoteBranches =
        new ArrayList<GitBranch>(repository.getBranches().getRemoteBranches());
    Collections.sort(remoteBranches);

    if (repository.isOnBranch()) {
      localBranches.remove(repository.getCurrentBranch());
    }

    final List<String> branchNames = new ArrayList<String>();
    for (GitBranch branch : localBranches) {
      branchNames.add(branch.getName());
    }
    for (GitBranch branch : remoteBranches) {
      branchNames.add(branch.getName());
    }
    return branchNames;
  }