Example usage for org.eclipse.jgit.lib Constants R_HEADS

List of usage examples for org.eclipse.jgit.lib Constants R_HEADS

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants R_HEADS.

Prototype

String R_HEADS

To view the source code for org.eclipse.jgit.lib Constants R_HEADS.

Click Source Link

Document

Prefix for branch refs

Usage

From source file:jbyoshi.gitupdate.processor.Push.java

License:Apache License

private static void process(Repository repo, Git git, String remote, Collection<String> branches, Report report)
        throws Exception {
    // Figure out if anything needs to be pushed.
    Map<String, ObjectId> oldIds = new HashMap<>();
    boolean canPush = false;
    for (String branch : branches) {
        BranchConfig config = new BranchConfig(repo.getConfig(), branch);
        ObjectId target = repo.getRef(branch).getObjectId();

        Ref remoteRef = repo.getRef(config.getRemoteTrackingBranch());
        if (remoteRef == null || !target.equals(remoteRef.getObjectId())) {
            canPush = true;//from   w  w  w.  ja v a2 s.  co  m
        }
        oldIds.put(branch, remoteRef == null ? ObjectId.zeroId() : remoteRef.getObjectId());
    }

    if (!canPush) {
        return;
    }

    PushCommand push = git.push().setCredentialsProvider(Prompts.INSTANCE).setTimeout(5).setRemote(remote);
    for (String branch : branches) {
        push.add(Constants.R_HEADS + branch);
    }
    for (PushResult result : push.call()) {
        for (RemoteRefUpdate update : result.getRemoteUpdates()) {
            if (update.getStatus() == RemoteRefUpdate.Status.OK) {
                String branchName = Utils.getShortBranch(update.getSrcRef());
                ObjectId oldId = oldIds.get(branchName);
                String old = oldId.equals(ObjectId.zeroId()) ? "new branch" : oldId.name();
                report.newChild(branchName + ": " + old + " -> " + update.getNewObjectId().name()).modified();
            }
        }
    }
}

From source file:jbyoshi.gitupdate.Utils.java

License:Apache License

public static Map<String, Ref> getLocalBranches(Repository repo) throws IOException {
    return repo.getRefDatabase().getRefs(Constants.R_HEADS);
}

From source file:jbyoshi.gitupdate.Utils.java

License:Apache License

public static String getShortBranch(String fullBranch) {
    if (fullBranch.startsWith(Constants.R_HEADS)) {
        return fullBranch.substring(Constants.R_HEADS.length());
    }/*  ww w  .  j  a  va  2 s.  c  om*/
    if (fullBranch.startsWith(Constants.R_REMOTES)) {
        return fullBranch.substring(Constants.R_REMOTES.length());
    }
    return fullBranch;
}

From source file:jenkins.plugins.git.GitBranchSCMHead.java

License:Open Source License

@Override
public final String getRef() {
    return Constants.R_HEADS + getName();
}

From source file:jenkins.plugins.git.GitSCMTelescope.java

License:Open Source License

/**
 * {@inheritDoc}/* w  w  w  .  j a v  a2  s . c  o  m*/
 */
@Override
public final SCMFileSystem build(@NonNull Item owner, @NonNull SCM scm, SCMRevision rev)
        throws IOException, InterruptedException {
    if (scm instanceof GitSCM) {
        // we only support the GitSCM if the branch is completely unambiguous
        GitSCM git = (GitSCM) scm;
        List<UserRemoteConfig> configs = git.getUserRemoteConfigs();
        List<BranchSpec> branches = git.getBranches();
        if (configs.size() == 1 && supports(configs.get(0).getUrl()) && branches.size() == 1
                && !branches.get(0).getName().contains("*")) {
            UserRemoteConfig config = configs.get(0);
            StandardCredentials credentials;
            String credentialsId = config.getCredentialsId();
            String remote = config.getUrl();
            if (credentialsId != null) {
                List<StandardUsernameCredentials> urlCredentials = CredentialsProvider.lookupCredentials(
                        StandardUsernameCredentials.class, owner,
                        owner instanceof Queue.Task ? Tasks.getAuthenticationOf((Queue.Task) owner)
                                : ACL.SYSTEM,
                        URIRequirementBuilder.fromUri(remote).build());
                credentials = CredentialsMatchers.firstOrNull(urlCredentials, CredentialsMatchers
                        .allOf(CredentialsMatchers.withId(credentialsId), GitClient.CREDENTIALS_MATCHER));
            } else {
                credentials = null;
            }
            validate(remote, credentials);
            SCMHead head;
            if (rev == null) {
                String name = branches.get(0).getName();
                if (name.startsWith(Constants.R_TAGS)) {
                    head = new GitTagSCMHead(name.substring(Constants.R_TAGS.length()),
                            getTimestamp(remote, credentials, name));
                } else if (name.startsWith(Constants.R_HEADS)) {
                    head = new GitBranchSCMHead(name.substring(Constants.R_HEADS.length()));
                } else {
                    if (name.startsWith(config.getName() + "/")) {
                        head = new GitBranchSCMHead(name.substring(config.getName().length() + 1));
                    } else {
                        head = new GitBranchSCMHead(name);
                    }
                }
            } else {
                head = rev.getHead();
            }
            return build(remote, credentials, head, rev);
        }
    }
    return null;
}

From source file:jenkins.plugins.git.GitSCMTelescope.java

License:Open Source License

/**
 * Retrieves the timestamp of the specified reference or object hash.
 *
 * @param remote      the repository URL.
 * @param credentials the credentials or {@code null} for an anonymous connection.
 * @param head        the head.//ww w. j  a  va  2  s  . c  om
 * @return the timestamp.
 * @throws IOException          if the operation failed due to an IO error.
 * @throws InterruptedException if the operation was interrupted.
 */
public long getTimestamp(@NonNull String remote, @CheckForNull StandardCredentials credentials,
        @NonNull SCMHead head) throws IOException, InterruptedException {
    if ((head instanceof TagSCMHead)) {
        return getTimestamp(remote, credentials, Constants.R_TAGS + head.getName());
    } else {
        return getTimestamp(remote, credentials, Constants.R_HEADS + head.getName());
    }
}

From source file:jenkins.plugins.git.GitSCMTelescope.java

License:Open Source License

/**
 * Retrieves the current revision of the specified head.
 *
 * @param remote      the repository URL.
 * @param credentials the credentials or {@code null} for an anonymous connection.
 * @param head        the head.//from   w w  w. j a  v  a2 s .  c o  m
 * @return the revision or {@code null} if the head does not exist.
 * @throws IOException          if the operation failed due to an IO error.
 * @throws InterruptedException if the operation was interrupted.
 */
@CheckForNull
public SCMRevision getRevision(@NonNull String remote, @CheckForNull StandardCredentials credentials,
        @NonNull SCMHead head) throws IOException, InterruptedException {
    if ((head instanceof TagSCMHead)) {
        return getRevision(remote, credentials, Constants.R_TAGS + head.getName());
    } else {
        return getRevision(remote, credentials, Constants.R_HEADS + head.getName());
    }
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitUtils.java

License:Apache License

public static String getShortBranchName(@NotNull String fullRefName) {
    if (isRegularBranch(fullRefName))
        return fullRefName.substring(Constants.R_HEADS.length());
    return fullRefName;
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitUtils.java

License:Apache License

public static boolean isRegularBranch(@NotNull String fullRefName) {
    return fullRefName.startsWith(Constants.R_HEADS);
}

From source file:kr.re.ec.grigit.graph.ui.AWTPlotRenderer.java

License:Eclipse Distribution License

@Override
protected int drawLabel(int x, int y, Ref ref) {
    String txt;//from w  ww.  ja  v  a 2  s  .  c om
    String name = ref.getName();
    if (name.startsWith(Constants.R_HEADS)) {
        g.setBackground(Color.GREEN);
        txt = name.substring(Constants.R_HEADS.length());
    } else if (name.startsWith(Constants.R_REMOTES)) {
        g.setBackground(Color.LIGHT_GRAY);
        txt = name.substring(Constants.R_REMOTES.length());
    } else if (name.startsWith(Constants.R_TAGS)) {
        g.setBackground(Color.YELLOW);
        txt = name.substring(Constants.R_TAGS.length());
    } else {
        // Whatever this would be
        g.setBackground(Color.WHITE);
        if (name.startsWith(Constants.R_REFS))
            txt = name.substring(Constants.R_REFS.length());
        else
            txt = name; // HEAD and such
    }
    if (ref.getPeeledObjectId() != null) {
        float[] colorComponents = g.getBackground().getRGBColorComponents(null);
        colorComponents[0] *= 0.9;
        colorComponents[1] *= 0.9;
        colorComponents[2] *= 0.9;
        g.setBackground(new Color(colorComponents[0], colorComponents[1], colorComponents[2]));
    }
    if (txt.length() > 12)
        txt = txt.substring(0, 11) + "\u2026"; // ellipsis "" (in UTF-8) //$NON-NLS-1$

    final int texth = g.getFontMetrics().getHeight();
    int textw = g.getFontMetrics().stringWidth(txt);
    g.setColor(g.getBackground());
    int arcHeight = texth / 4;
    int y0 = y - texth / 2 + (cell.getHeight() - texth) / 2;
    g.fillRoundRect(x, y0, textw + arcHeight * 2, texth - 1, arcHeight, arcHeight);
    g.setColor(g.getColor().darker());
    g.drawRoundRect(x, y0, textw + arcHeight * 2, texth - 1, arcHeight, arcHeight);
    g.setColor(Color.BLACK);
    g.drawString(txt, x + arcHeight, y0 + texth - g.getFontMetrics().getDescent());

    return arcHeight * 3 + textw;
}