Search in sources :

Example 1 with BranchTrackingStatus

use of org.eclipse.jgit.lib.BranchTrackingStatus in project spring-cloud-config by spring-cloud.

the class JGitEnvironmentRepository method isClean.

private boolean isClean(Git git, String label) {
    StatusCommand status = git.status();
    try {
        BranchTrackingStatus trackingStatus = BranchTrackingStatus.of(git.getRepository(), label);
        boolean isBranchAhead = trackingStatus != null && trackingStatus.getAheadCount() > 0;
        return status.call().isClean() && !isBranchAhead;
    } catch (Exception e) {
        String message = "Could not execute status command on local repository. Cause: (" + e.getClass().getSimpleName() + ") " + e.getMessage();
        warn(message, e);
        return false;
    }
}
Also used : BranchTrackingStatus(org.eclipse.jgit.lib.BranchTrackingStatus) StatusCommand(org.eclipse.jgit.api.StatusCommand) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) NoRemoteRepositoryException(org.eclipse.jgit.errors.NoRemoteRepositoryException) IOException(java.io.IOException) RefNotFoundException(org.eclipse.jgit.api.errors.RefNotFoundException)

Example 2 with BranchTrackingStatus

use of org.eclipse.jgit.lib.BranchTrackingStatus in project egit by eclipse.

the class DecoratableResourceHelper method getBranchStatus.

static String getBranchStatus(Repository repo) throws IOException {
    String cachedStatus = branchState.get(repo);
    if (cachedStatus != null)
        return cachedStatus;
    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 = GitLabels.formatBranchTrackingStatus(status);
    branchState.put(repo, formattedStatus);
    return formattedStatus;
}
Also used : BranchTrackingStatus(org.eclipse.jgit.lib.BranchTrackingStatus)

Example 3 with BranchTrackingStatus

use of org.eclipse.jgit.lib.BranchTrackingStatus in project jbosstools-openshift by jbosstools.

the class EGitUtils method isAhead.

/**
 * Returns <code>true</code> if the given repo has commits that are not
 * contained withing the repo attached to it via the given remote. It is
 * ahead of the given remote config.
 * This will work for non{@link BranchTrackingStatus#of(Repository, String)} will tell you if the
 * given branch is ahead of it's tracking branch. It only works with a
 * branch that is tracking another branch.
 *
 * @param repo
 *            the repo to check
 * @param remote
 *            the name of the remote to check against
 * @param monitor
 *            the monitor to report progress to
 * @return
 * @throws IOException
 * @throws InvocationTargetException
 * @throws URISyntaxException
 *
 * @see BranchTrackingStatus#of
 */
public static boolean isAhead(Repository repo, String remote, IProgressMonitor monitor) throws IOException, URISyntaxException, InvocationTargetException {
    Assert.isLegal(remote != null);
    Assert.isLegal(repo != null);
    if (remote.equals(getRemote(repo.getBranch(), repo.getConfig()))) {
        BranchTrackingStatus status = BranchTrackingStatus.of(repo, repo.getBranch());
        if (status != null) {
            return status.getAheadCount() > 0;
        }
    }
    return isNonTrackingBranchAhead(repo, remote, monitor);
}
Also used : BranchTrackingStatus(org.eclipse.jgit.lib.BranchTrackingStatus)

Example 4 with BranchTrackingStatus

use of org.eclipse.jgit.lib.BranchTrackingStatus in project egit by eclipse.

the class GitLabels method getStyledLabel.

/**
 * Computes detailed repository label that consists of repository name,
 * state, checked-out branch and it's status (returned by
 * {@linkplain #formatBranchTrackingStatus(BranchTrackingStatus)})
 *
 * @param repository
 * @return a styled string for the repository
 * @throws IOException
 */
@NonNull
public static 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) {
            // $NON-NLS-1$
            string.append(" - ", StyledString.DECORATIONS_STYLER);
            string.append(repositoryState.getDescription(), StyledString.DECORATIONS_STYLER);
        }
        string.append(']', StyledString.DECORATIONS_STYLER);
    }
    return string;
}
Also used : BranchTrackingStatus(org.eclipse.jgit.lib.BranchTrackingStatus) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) RepositoryState(org.eclipse.jgit.lib.RepositoryState) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) NonNull(org.eclipse.jgit.annotations.NonNull)

Aggregations

BranchTrackingStatus (org.eclipse.jgit.lib.BranchTrackingStatus)4 IOException (java.io.IOException)1 RepositoryUtil (org.eclipse.egit.core.RepositoryUtil)1 StyledString (org.eclipse.jface.viewers.StyledString)1 NonNull (org.eclipse.jgit.annotations.NonNull)1 StatusCommand (org.eclipse.jgit.api.StatusCommand)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 RefNotFoundException (org.eclipse.jgit.api.errors.RefNotFoundException)1 NoRemoteRepositoryException (org.eclipse.jgit.errors.NoRemoteRepositoryException)1 RepositoryState (org.eclipse.jgit.lib.RepositoryState)1