Example usage for org.eclipse.jgit.lib BranchConfig getTrackingBranch

List of usage examples for org.eclipse.jgit.lib BranchConfig getTrackingBranch

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib BranchConfig getTrackingBranch.

Prototype

public String getTrackingBranch() 

Source Link

Document

Get the full tracking branch name

Usage

From source file:org.eclipse.egit.ui.internal.history.command.AbstractRebaseHistoryCommandHandler.java

License:Open Source License

/**
 * @param commit//from  w  w  w .j a  va2s. c  o  m
 * @param repository
 * @param currentBranch
 * @return ref pointing to the given commit, prefers tracking branch if
 *         multiple refs are available
 */
protected Ref getRef(PlotCommit commit, Repository repository, String currentBranch) {
    int count = commit.getRefCount();
    if (count == 0)
        return new ObjectIdRef.Unpeeled(Storage.LOOSE, commit.getName(), commit);
    else if (count == 1)
        return commit.getRef(0);
    else {
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), currentBranch);
        String trackingBranch = branchConfig.getTrackingBranch();
        Ref remoteRef = null;

        for (int i = 0; i < count; i++) {
            Ref ref = commit.getRef(i);
            if (trackingBranch != null && trackingBranch.equals(ref.getName()))
                return ref;
            if (ref.getName().startsWith(Constants.R_REMOTES))
                remoteRef = ref;
        }

        if (remoteRef != null)
            return remoteRef;
        else
            // We tried to pick a nice ref, just pick the first then
            return commit.getRef(0);
    }
}

From source file:org.eclipse.egit.ui.internal.history.command.RebaseCurrentHandler.java

License:Open Source License

private Ref getRef(PlotCommit commit, Repository repository, String currentBranch) {
    int count = commit.getRefCount();
    if (count == 0)
        return new ObjectIdRef.Unpeeled(Storage.LOOSE, commit.getName(), commit);
    else if (count == 1)
        return commit.getRef(0);
    else {/* w  w w.  j  a  va2  s .  c  o  m*/
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), currentBranch);
        String trackingBranch = branchConfig.getTrackingBranch();
        Ref remoteRef = null;

        for (int i = 0; i < count; i++) {
            Ref ref = commit.getRef(i);
            if (trackingBranch != null && trackingBranch.equals(ref.getName()))
                return ref;
            if (ref.getName().startsWith(Constants.R_REMOTES))
                remoteRef = ref;
        }

        if (remoteRef != null)
            return remoteRef;
        else
            // We tried to pick a nice ref, just pick the first then
            return commit.getRef(0);
    }
}