List of usage examples for org.eclipse.jgit.lib BranchTrackingStatus of
public static BranchTrackingStatus of(Repository repository, String branchName) throws IOException
branchName
in repository
. From source file:com.bb.extensions.plugin.unittests.internal.git.GitWrapper.java
License:Open Source License
/** * // w w w . j a v a 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 {/*from w w w . j a v a2s . 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.ajoberstar.gradle.git.tasks.GitBranchTrackingStatus.java
License:Apache License
@TaskAction public void trackingStatuses() { try {/*ww w.j av a2s. co m*/ trackingStatus = GitUtil.trackingStatusFromGit(getGit().getRepository(), BranchTrackingStatus.of(getGit().getRepository(), localBranch)); } catch (IOException e) { throw new GradleException("Problem listing branches", e); } }
From source file:org.eclipse.egit.ui.internal.components.SimplePushSpecPage.java
License:Open Source License
/** * pre-fills the destination box with a remote ref name if one exists that * matches the local branch name./*from w w w . j a v a 2 s . co m*/ */ protected void updateDestinationField() { setMessage(NLS.bind(UIText.SimplePushSpecPage_message, sourceName)); String checkRemote = sourceName; if (sourceName.startsWith(Constants.R_HEADS)) { try { BranchTrackingStatus status = BranchTrackingStatus.of(repository, sourceName.substring(Constants.R_HEADS.length())); if (status != null) { // calculate the name of the branch on the other side. checkRemote = status.getRemoteTrackingBranch(); checkRemote = Constants.R_HEADS + checkRemote.substring(checkRemote.indexOf('/', Constants.R_REMOTES.length() + 1) + 1); setMessage( NLS.bind(UIText.SimplePushSpecPage_pushAheadInfo, new Object[] { sourceName, Integer.valueOf(status.getAheadCount()), status.getRemoteTrackingBranch() }), IStatus.INFO); } } catch (Exception e) { // ignore and continue... } if (assist == null) { if (checkRemote != null) remoteRefName.setText(checkRemote); return; } if (checkRemote == null) checkRemote = sourceName; for (Ref ref : assist.getRefsForContentAssist(false, true)) if (ref.getName().equals(checkRemote)) remoteRefName.setText(checkRemote); } }
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
/** * @param repository// w w w . j a v a2s. 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// ww w . ja va 2 s. c o m * @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 w w w .j av a2 s . 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; }
From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java
License:Open Source License
/** * Returns <code>true</code> if the given branch in the given repository has * local commits that were not pushed to its remote yet. * //from w w w. j a v a2 s . com * @param repository * @param branchName * @return * @throws IOException */ public static boolean hasCommitsToBePushed(Repository repository) throws IOException { BranchTrackingStatus status = BranchTrackingStatus.of(repository, Constants.MASTER); if (status == null) { return false; } return status.getAheadCount() > 0; }
From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java
License:Open Source License
/** * 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.//from w w w . jav a 2 s . co m * 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, InvocationTargetException, URISyntaxException { 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); }