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;
}
}
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;
}
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);
}
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;
}
Aggregations