Java 类org.eclipse.jgit.lib.BranchTrackingStatus 实例源码

项目:oxygen-git-plugin    文件:GitAccess.java   
/**
 * Calculates how many commits the local repository is ahead from the current
 * local repository base commit
 * 
 * @return the number of commits ahead
 */
public int getPushesAhead() {
    int numberOfCommits = 0;

  try {
    String branchName = getBranchInfo().getBranchName();
    if (branchName != null && branchName.length() > 0) {
      BranchTrackingStatus bts = BranchTrackingStatus.of(getRepository(), branchName);
      if (bts != null) {
        numberOfCommits = bts.getAheadCount();
      }
    }
  } catch (IOException | NoRepositorySelected e) {
    if (logger.isDebugEnabled()) {
       logger.debug(e, e);
     }
  }

  return numberOfCommits;
}
项目:oxygen-git-plugin    文件:GitAccess.java   
/**
 * Calculates how many commits the remote repository is ahead from the local
 * repository base commit
 * 
 * @return the number of commits the remote is ahead
 */
public int getPullsBehind() {
  int numberOfCommits = 0;

  try {
    String branchName = getBranchInfo().getBranchName();
    if (branchName != null && branchName.length() > 0) {
      BranchTrackingStatus bts = BranchTrackingStatus.of(getRepository(), branchName);
      if (bts != null) {
        numberOfCommits = bts.getBehindCount();
      }
    }
  } catch (IOException | NoRepositorySelected e) {
    if (logger.isDebugEnabled()) {
      logger.debug(e, e);
    }
  }

  return numberOfCommits;}
项目:GitDirStat    文件:RemoteBranch.java   
public LocalBranch getLocalBranch() throws IOException {
    LocalBranch localBranchForRemote = null;
    GitRepository gitRepository = getGitRepository();
    Repository repo = gitRepository.getRepository();
    List<LocalBranch> localRefs = gitRepository.getRefs(LocalBranch.class);
    for (LocalBranch localBranch : localRefs) {
        BranchTrackingStatus branchTrackingStatus = BranchTrackingStatus
                .of(repo, localBranch.getName());
        if (branchTrackingStatus == null) {
            continue;
        }

        String remoteTrackingBranch = branchTrackingStatus
                .getRemoteTrackingBranch();
        if (getName().equals(remoteTrackingBranch)) {
            localBranchForRemote = localBranch;
            break;
        }
    }
    return localBranchForRemote;
}
项目:Elegit    文件:BranchModel.java   
/**
 * Helper method to check if a branch is a current branch
 * @param branch the branch to check
 * @return true if the branch is the current branch or its remote tracking branch
 */
public boolean isBranchCurrent(BranchHelper branch) {
    if (this.currentBranch==branch)
        return true;
    if (this.currentBranch==null)
        return false;
    try {
        // If the branch is the local's remote tracking branch, it is current
        BranchTrackingStatus status = BranchTrackingStatus.of(this.repoHelper.repo, this.currentBranch.getRefName());
        if (branch instanceof RemoteBranchHelper && status != null && this.repoHelper.repo.shortenRefName(
                status.getRemoteTrackingBranch()).equals(branch.getRefName())) {
            return true;
        }
    } catch (IOException e) {
        // Shouldn't happen here, session controller would catch this first
        e.printStackTrace();
    }
    return false;
}
项目:Elegit    文件:MergeWindowController.java   
/**
 * helper method to initialize some text
 * @throws IOException if there is an error getting branch names
 */
private void initText() throws IOException {
    String curBranch = repoHelper.getBranchModel().getCurrentBranch().getRefName();
    BranchTrackingStatus b = BranchTrackingStatus.of(repoHelper.getRepo(), curBranch);
    if(b == null) {
        disable = true;
        mergeRemoteTrackingText.setText("This branch does not have an\n" +
                "upstream remote branch.\n\n" +
                "Push to create a remote branch.");
        hideRemoteMerge();

    } else {
        disable = false;
        String curRemoteTrackingBranch = b.getRemoteTrackingBranch();
        curRemoteTrackingBranch = Repository.shortenRefName(curRemoteTrackingBranch);
        localBranchName1.setText(curBranch);
        remoteTrackingBranchName.setText(curRemoteTrackingBranch);
    }
    localBranchName2.setText(curBranch);
}
项目:GitDirStat    文件:RemoteBranch.java   
public LocalBranch getLocalBranch() throws IOException {
    LocalBranch localBranchForRemote = null;
    GitRepository gitRepository = getGitRepository();
    Repository repo = gitRepository.getRepository();
    List<LocalBranch> localRefs = gitRepository.getRefs(LocalBranch.class);
    for (LocalBranch localBranch : localRefs) {
        BranchTrackingStatus branchTrackingStatus = BranchTrackingStatus
                .of(repo, localBranch.getName());
        if (branchTrackingStatus == null) {
            continue;
        }

        String remoteTrackingBranch = branchTrackingStatus
                .getRemoteTrackingBranch();
        if (getName().equals(remoteTrackingBranch)) {
            localBranchForRemote = localBranch;
            break;
        }
    }
    return localBranchForRemote;
}
项目:GitDirStat    文件:LocalBranch.java   
public boolean isUpToDate() throws IOException {
    GitRepository gitRepository = getGitRepository();
    Repository repo = gitRepository.getRepository();
    BranchTrackingStatus branchTrackingStatus = BranchTrackingStatus.of(
            repo, getName());
    return branchTrackingStatus.getAheadCount() == 0
            && branchTrackingStatus.getBehindCount() == 0;
}
项目:Elegit    文件:BranchModel.java   
public String getCurrentRemoteBranch() throws IOException {
    if (BranchTrackingStatus.of(this.repoHelper.repo, this.currentBranch.getRefName())!=null) {
        return Repository.shortenRefName(
                BranchTrackingStatus.of(this.repoHelper.repo, this.currentBranch.getRefName())
                        .getRemoteTrackingBranch());
    }
    return null;
}
项目:Elegit    文件:BranchModel.java   
public String getCurrentRemoteAbbrevBranch() throws IOException {
    if (BranchTrackingStatus.of(this.repoHelper.repo, this.currentBranch.getRefName())!=null) {
        String name =  Repository.shortenRefName(
                BranchTrackingStatus.of(this.repoHelper.repo, this.currentBranch.getRefName())
                        .getRemoteTrackingBranch());
        if (name.length() > CellLabel.MAX_CHAR_PER_LABEL) {
            name = name.substring(0,24)+"...";
        }
        return name;
    }
    return null;
}
项目:GitDirStat    文件:LocalBranch.java   
public boolean isUpToDate() throws IOException {
    GitRepository gitRepository = getGitRepository();
    Repository repo = gitRepository.getRepository();
    BranchTrackingStatus branchTrackingStatus = BranchTrackingStatus.of(
            repo, getName());
    return branchTrackingStatus.getAheadCount() == 0
            && branchTrackingStatus.getBehindCount() == 0;
}
项目:jgit-cookbook    文件:ShowBranchTrackingStatus.java   
private static List<Integer> getCounts(org.eclipse.jgit.lib.Repository repository, String branchName) throws IOException {
    BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(repository, branchName);
    List<Integer> counts = new ArrayList<>();
    if (trackingStatus != null) {
        counts.add(trackingStatus.getAheadCount());
        counts.add(trackingStatus.getBehindCount());
    } else {
        System.out.println("Returned null, likely no remote tracking of branch " + branchName);
        counts.add(0);
        counts.add(0);
    }
    return counts;
}
项目:Elegit    文件:BranchHelper.java   
public BranchTrackingStatus getStatus() throws IOException {
    return BranchTrackingStatus.of(this.repoHelper.repo, this.refName);
}
项目:jQCCounter    文件:GitInformation.java   
public boolean load(File repoFile) {
    Repository repository;
    Git git = null;

    try {
        repository = new FileRepositoryBuilder().setGitDir(repoFile)
                .setMustExist(true)
                .readEnvironment()
                .build();
        git = new Git(repository);

        branchFull = repository.getFullBranch();
        branchShort = repository.getBranch();
        state = repository.getRepositoryState().getDescription();

        for (Ref branch : git.branchList().call()) {
            if (branch.getName().equals(branchFull)) {
                BranchTrackingStatus bts = BranchTrackingStatus.of(repository, branchFull); 

                if (bts != null) {
                    RemoteConfig rc = new RemoteConfig(repository.getConfig(), repository.getRemoteName(bts.getRemoteTrackingBranch()));

                    for (URIish uri : rc.getURIs()) {
                        if (uri.isRemote() && uri.getHost().toLowerCase().equals("github.com")) {
                            remote = new GitInformationRemote();

                            remote.branch = bts.getRemoteTrackingBranch();
                            remote.uri = uri.toString();
                            remote.link = "http://" + uri.getHost() + uri.getPath().replace(".git", "");
                            remote.name = uri.getHumanishName();

                            remote.ahead = bts.getAheadCount();
                            remote.behind = bts.getBehindCount();
                        }
                    }
                }

                commits = loadCommits(repository, git, branch);
            }
        }

        git.close();
    } catch (IOException | GitAPIException | URISyntaxException e) {
        e.printStackTrace();

        isRepository = false;

        if (git != null) git.close();
        return false;
    }

    isRepository = true;
    return true;
}