Example usage for org.eclipse.jgit.lib BranchTrackingStatus getBehindCount

List of usage examples for org.eclipse.jgit.lib BranchTrackingStatus getBehindCount

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib BranchTrackingStatus getBehindCount.

Prototype

public int getBehindCount() 

Source Link

Document

Get number of commits that the local branch is behind of the remote-tracking branch

Usage

From source file:com.bb.extensions.plugin.unittests.internal.git.GitWrapper.java

License:Open Source License

/**
 * /*w w  w .j  ava  2s .c om*/
 * @return true if the git repo is up to date.
 */
public boolean isRepoUpToDate() {
    boolean upToDate = true;
    FetchCommand fetchCmd = this.git.fetch();
    try {
        fetchCmd.call();
        BranchTrackingStatus status = BranchTrackingStatus.of(this.git.getRepository(),
                this.git.getRepository().getBranch());
        upToDate = status.getBehindCount() == 0;
    } catch (InvalidRemoteException e) {
        e.printStackTrace();
    } catch (TransportException e) {
        e.printStackTrace();
    } catch (GitAPIException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return upToDate;
}

From source file:com.buildautomation.jgit.api.ShowBranchTrackingStatus.java

License:Apache License

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 {/* w  ww.  j  av  a  2s. c o  m*/
        System.out.println("Returned null, likely no remote tracking of branch " + branchName);
        counts.add(0);
        counts.add(0);
    }
    return counts;
}

From source file:org.eclipse.egit.ui.internal.decorators.DecoratableResourceHelper.java

License:Open Source License

static String getBranchStatus(Repository repo) throws IOException {
    String branchName = repo.getBranch();
    if (branchName == null)
        return null;

    BranchTrackingStatus status = BranchTrackingStatus.of(repo, branchName);
    if (status == null)
        return null;

    if (status.getAheadCount() == 0 && status.getBehindCount() == 0)
        return null;

    String formattedStatus = GitLabelProvider.formatBranchTrackingStatus(status);
    return formattedStatus;
}

From source file:org.eclipse.egit.ui.internal.GitLabelProvider.java

License:Open Source License

/**
 * Format the branch tracking status suitable for displaying in decorations and labels.
 *
 * @param status/* www.jav  a  2s  .c o m*/
 * @return the branch tracking status as a string
 */
public static String formatBranchTrackingStatus(BranchTrackingStatus status) {
    StringBuilder sb = new StringBuilder();
    int ahead = status.getAheadCount();
    int behind = status.getBehindCount();
    if (ahead != 0) {
        // UPWARDS ARROW
        sb.append('\u2191');
        sb.append(ahead);
    }
    if (behind != 0) {
        if (sb.length() != 0)
            sb.append(' ');
        // DOWNWARDS ARROW
        sb.append('\u2193');
        sb.append(status.getBehindCount());
    }
    return sb.toString();
}

From source file:org.eclipse.egit.ui.internal.GitLabelProvider.java

License:Open Source License

/**
 * @param repository/*from  w ww. j  ava2 s.c  o m*/
 * @return a styled string for the repository
 * @throws IOException
 */
protected StyledString getStyledTextFor(Repository repository) throws IOException {
    File directory = repository.getDirectory();
    StyledString string = new StyledString();
    if (!repository.isBare())
        string.append(directory.getParentFile().getName());
    else
        string.append(directory.getName());

    String branch = Activator.getDefault().getRepositoryUtil().getShortBranch(repository);
    if (branch != null) {
        string.append(' ');
        string.append('[', StyledString.DECORATIONS_STYLER);
        string.append(branch, StyledString.DECORATIONS_STYLER);

        RepositoryState repositoryState = repository.getRepositoryState();
        if (repositoryState != RepositoryState.SAFE) {
            string.append(" - ", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
            string.append(repositoryState.getDescription(), StyledString.DECORATIONS_STYLER);
        }

        BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(repository, branch);
        if (trackingStatus != null
                && (trackingStatus.getAheadCount() != 0 || trackingStatus.getBehindCount() != 0)) {
            String formattedTrackingStatus = formatBranchTrackingStatus(trackingStatus);
            string.append(' ');
            string.append(formattedTrackingStatus, StyledString.DECORATIONS_STYLER);
        }
        string.append(']', StyledString.DECORATIONS_STYLER);
    }

    string.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
    string.append(directory.getAbsolutePath(), StyledString.QUALIFIER_STYLER);

    return string;
}

From source file:org.eclipse.egit.ui.internal.GitLabels.java

License:Open Source License

/**
 * Computes detailed repository label that consists of repository name,
 * state, checked-out branch and it's status (returned by
 * {@linkplain #formatBranchTrackingStatus(BranchTrackingStatus)})
 *
 * @param repository//from   w w  w.j  a  v  a 2s  .  com
 * @return a styled string for the repository
 * @throws IOException
 */
public static @NonNull StyledString getStyledLabel(@NonNull Repository repository) throws IOException {
    RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();

    StyledString string = getChangedPrefix(repository);

    string.append(repositoryUtil.getRepositoryName(repository));

    String branch = repositoryUtil.getShortBranch(repository);
    if (branch != null) {
        string.append(' ');
        string.append('[', StyledString.DECORATIONS_STYLER);
        string.append(branch, StyledString.DECORATIONS_STYLER);

        BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(repository, branch);
        if (trackingStatus != null
                && (trackingStatus.getAheadCount() != 0 || trackingStatus.getBehindCount() != 0)) {
            String formattedTrackingStatus = GitLabels.formatBranchTrackingStatus(trackingStatus);
            string.append(' ');
            string.append(formattedTrackingStatus, StyledString.DECORATIONS_STYLER);
        }

        RepositoryState repositoryState = repository.getRepositoryState();
        if (repositoryState != RepositoryState.SAFE) {
            string.append(" - ", StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
            string.append(repositoryState.getDescription(), StyledString.DECORATIONS_STYLER);
        }
        string.append(']', StyledString.DECORATIONS_STYLER);
    }

    return string;
}

From source file:org.eclipse.oomph.gitbash.decorators.BranchDecorator.java

License:Open Source License

private String getDecoration(org.eclipse.egit.ui.internal.repository.tree.RefNode node) {
    String branchName = Repository.shortenRefName(node.getObject().getName());
    Repository repository = node.getRepository();
    StoredConfig config = repository.getConfig();

    String branch = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
            ConfigConstants.CONFIG_KEY_MERGE);

    if (branch != null) {
        String remote = config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
                ConfigConstants.CONFIG_KEY_REMOTE);

        boolean rebaseFlag = config.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
                ConfigConstants.CONFIG_KEY_REBASE, false);

        if (branch.startsWith(DEFAULT_PATH)) {
            branch = branch.substring(DEFAULT_PATH.length());
        }/*from   www .  ja v a 2s.c o m*/

        String prefix = ".".equals(remote) ? "" : remote + "/";
        String result = (rebaseFlag ? "REBASE" : "MERGE") + ": " + prefix + branch;

        try {
            BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(repository, branchName);
            if (trackingStatus != null
                    && (trackingStatus.getAheadCount() != 0 || trackingStatus.getBehindCount() != 0)) {
                result += " " + formatBranchTrackingStatus(trackingStatus);
            }
        } catch (Throwable t) {
            //$FALL-THROUGH$
        }

        return result;
    }

    return null;
}