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:models.PushedBranch.java

License:Apache License

public String getShortName() {
    return StringUtils.removeStart(this.name, Constants.R_HEADS);
}

From source file:net.erdfelt.android.sdkfido.git.internal.GitCloneCommand.java

License:Apache License

private Ref guessHEAD(final FetchResult result) {
    final Ref idHEAD = result.getAdvertisedRef(Constants.HEAD);
    final List<Ref> availableRefs = new ArrayList<Ref>();
    Ref head = null;/*  www . ja  v  a2  s .c o m*/
    for (final Ref r : result.getAdvertisedRefs()) {
        final String n = r.getName();
        if (!n.startsWith(Constants.R_HEADS))
            continue;
        availableRefs.add(r);
        if (idHEAD == null || head != null)
            continue;
        if (r.getObjectId().equals(idHEAD.getObjectId()))
            head = r;
    }
    Collections.sort(availableRefs, RefComparator.INSTANCE);
    if (idHEAD != null && head == null)
        head = idHEAD;
    return head;
}

From source file:net.erdfelt.android.sdkfido.git.internal.GitCloneCommand.java

License:Apache License

/**
 * Add a 'remote' configuration./*from   w  w  w .j a v a  2 s .c o  m*/
 * 
 * @param remoteName
 *            the name of the remote
 * @param uri
 *            the uri to the remote
 * @throws URISyntaxException
 *             if unable to process uri
 * @throws IOException
 *             if unable to add remote config
 */
private void addRemoteConfig(String remoteName, URIish uri) throws URISyntaxException, IOException {
    RemoteConfig rc = new RemoteConfig(repo.getConfig(), remoteName);
    rc.addURI(uri);

    String dest = Constants.R_HEADS + "*:" + Constants.R_REMOTES + remoteName + "/*";

    RefSpec refspec = new RefSpec(dest);
    refspec.setForceUpdate(true);
    rc.addFetchRefSpec(refspec);
    rc.update(repo.getConfig());
    repo.getConfig().save();
}

From source file:net.erdfelt.android.sdkfido.git.internal.GitInfo.java

License:Apache License

private static void infoRefs(Repository db) {
    Map<String, Ref> refs = db.getAllRefs();
    System.out.printf("%nAll Refs (%d)%n", refs.size());
    Ref head = refs.get(Constants.HEAD);

    if (head == null) {
        System.out.println(" HEAD ref is dead and/or non-existent?");
        return;//from  w  w  w.  j  a va2s .  com
    }

    Map<String, Ref> printRefs = new TreeMap<String, Ref>();

    String current = head.getLeaf().getName();
    if (current.equals(Constants.HEAD)) {
        printRefs.put("(no branch)", head);
    }

    for (Ref ref : RefComparator.sort(refs.values())) {
        String name = ref.getName();
        if (name.startsWith(Constants.R_HEADS) || name.startsWith(Constants.R_REMOTES)) {
            printRefs.put(name, ref);
        }
    }

    int maxLength = 0;
    for (String name : printRefs.keySet()) {
        maxLength = Math.max(maxLength, name.length());
    }

    System.out.printf("Refs (Heads/Remotes) (%d)%n", printRefs.size());
    for (Entry<String, Ref> e : printRefs.entrySet()) {
        Ref ref = e.getValue();
        ObjectId objectId = ref.getObjectId();
        System.out.printf("%c %-" + maxLength + "s %s%n", (current.equals(ref.getName()) ? '*' : ' '),
                e.getKey(), objectId.abbreviate(ABBREV_LEN).name());
    }
}

From source file:net.erdfelt.android.sdkfido.git.internal.GitInfo.java

License:Apache License

public static String abbreviateRef(String ref) {
    if (ref.startsWith(Constants.R_HEADS)) {
        return ref.substring(Constants.R_HEADS.length());
    }/*from w  ww  .java2s.co  m*/
    if (ref.startsWith(Constants.R_TAGS)) {
        return ref.substring(Constants.R_TAGS.length());
    }
    return ref;
}

From source file:net.erdfelt.android.sdkfido.git.internal.GitInfo.java

License:Apache License

public static String asIdLong(Repository db, TrackingRefUpdate update) {
    RefUpdate.Result result = update.getResult();

    // Fast IDs//  w w  w.jav a 2  s  .c  o m
    switch (result) {
    case LOCK_FAILURE:
        return "[lock failure]";
    case IO_FAILURE:
        return "[i/o error]";
    case REJECTED:
        return "[rejected]";
    }

    // Deleted Check Next
    if (ObjectId.zeroId().equals(update.getNewObjectId())) {
        return "[deleted]";
    }

    // All other results
    switch (result) {
    case NEW:
        if (update.getRemoteName().startsWith(Constants.R_HEADS)) {
            return "[new branch]";
        }

        if (update.getLocalName().startsWith(Constants.R_TAGS)) {
            return "[new tag]";
        }

        return "[new]";
    case FORCED: {
        String oldOID = update.getOldObjectId().abbreviate(ABBREV_LEN).name();
        String newOID = update.getNewObjectId().abbreviate(ABBREV_LEN).name();
        return oldOID + "..." + newOID;
    }
    case FAST_FORWARD: {
        String oldOID = update.getOldObjectId().abbreviate(ABBREV_LEN).name();
        String newOID = update.getNewObjectId().abbreviate(ABBREV_LEN).name();
        return oldOID + ".." + newOID;
    }
    case NO_CHANGE:
        return "[up to date]";
    default:
        return "[" + result.name() + "]";
    }
}

From source file:net.mobid.codetraq.runnables.GitChecker.java

License:Open Source License

private String longTypeOf(ObjectReader reader, final TrackingRefUpdate u) {
    final RefUpdate.Result r = u.getResult();
    if (r == RefUpdate.Result.LOCK_FAILURE)
        return "[lock fail]";
    if (r == RefUpdate.Result.IO_FAILURE)
        return "[i/o error]";
    if (r == RefUpdate.Result.REJECTED)
        return "[rejected]";
    if (ObjectId.zeroId().equals(u.getNewObjectId()))
        return "[deleted]";

    if (r == RefUpdate.Result.NEW) {
        if (u.getRemoteName().startsWith(Constants.R_HEADS))
            return "[new branch]";
        else if (u.getLocalName().startsWith(Constants.R_TAGS))
            return "[new tag]";
        return "[new]";
    }// w w w .  ja v  a  2  s.  com

    if (r == RefUpdate.Result.FORCED) {
        final String aOld = safeAbbreviate(reader, u.getOldObjectId());
        final String aNew = safeAbbreviate(reader, u.getNewObjectId());
        return aOld + "..." + aNew;
    }

    if (r == RefUpdate.Result.FAST_FORWARD) {
        final String aOld = safeAbbreviate(reader, u.getOldObjectId());
        final String aNew = safeAbbreviate(reader, u.getNewObjectId());
        return aOld + ".." + aNew;
    }

    if (r == RefUpdate.Result.NO_CHANGE)
        return "[up to date]";
    return "[" + r.name() + "]";
}

From source file:net.mobid.codetraq.runnables.GitChecker.java

License:Open Source License

String abbreviateRef(String dst, boolean abbreviateRemote) {
    if (dst.startsWith(Constants.R_HEADS))
        dst = dst.substring(Constants.R_HEADS.length());
    else if (dst.startsWith(Constants.R_TAGS))
        dst = dst.substring(Constants.R_TAGS.length());
    else if (abbreviateRemote && dst.startsWith(Constants.R_REMOTES))
        dst = dst.substring(Constants.R_REMOTES.length());
    return dst;/*from   w  ww  .  j  a v  a2  s  .c  o  m*/
}

From source file:org.apache.maven.scm.provider.git.jgit.command.branch.JGitBranchCommand.java

License:Apache License

/**
 * {@inheritDoc}/*from w  ww  .  jav a2  s  . c o m*/
 */
@Override
protected ScmResult executeBranchCommand(ScmProviderRepository repo, ScmFileSet fileSet, String branch,
        String message) throws ScmException {
    if (branch == null || StringUtils.isEmpty(branch.trim())) {
        throw new ScmException("branch name must be specified");
    }

    if (!fileSet.getFileList().isEmpty()) {
        throw new ScmException("This provider doesn't support branching subsets of a directory");
    }

    Git git = null;
    try {
        git = Git.open(fileSet.getBasedir());
        Ref branchResult = git.branchCreate().setName(branch).call();
        getLogger().info("created [" + branchResult.getName() + "]");

        if (getLogger().isDebugEnabled()) {
            for (String branchName : getShortLocalBranchNames(git)) {
                getLogger().debug("local branch available: " + branchName);
            }
        }

        if (repo.isPushChanges()) {
            getLogger().info("push branch [" + branch + "] to remote...");
            JGitUtils.push(getLogger(), git, (GitScmProviderRepository) repo,
                    new RefSpec(Constants.R_HEADS + branch));
        }

        // search for the tagged files
        final RevWalk revWalk = new RevWalk(git.getRepository());
        RevCommit commit = revWalk.parseCommit(branchResult.getObjectId());
        revWalk.release();

        final TreeWalk walk = new TreeWalk(git.getRepository());
        walk.reset(); // drop the first empty tree, which we do not need here
        walk.setRecursive(true);
        walk.addTree(commit.getTree());

        List<ScmFile> files = new ArrayList<ScmFile>();
        while (walk.next()) {
            files.add(new ScmFile(walk.getPathString(), ScmFileStatus.CHECKED_OUT));
        }
        walk.release();

        return new BranchScmResult("JGit branch", files);

    } catch (Exception e) {
        throw new ScmException("JGit branch failed!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}

From source file:org.apache.maven.scm.provider.git.jgit.command.checkin.JGitCheckInCommand.java

License:Apache License

/**
 * {@inheritDoc}/*  w  w w.j a va 2 s  . c  o  m*/
 */
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message,
        ScmVersion version) throws ScmException {

    Git git = null;
    try {
        File basedir = fileSet.getBasedir();
        git = Git.open(basedir);

        boolean doCommit = false;

        if (!fileSet.getFileList().isEmpty()) {
            doCommit = JGitUtils.addAllFiles(git, fileSet).size() > 0;
        } else {
            // add all tracked files which are modified manually
            Set<String> changeds = git.status().call().getModified();
            if (changeds.isEmpty()) {
                // warn there is nothing to add
                getLogger().warn("there are no files to be added");
                doCommit = false;
            } else {
                AddCommand add = git.add();
                for (String changed : changeds) {
                    getLogger().debug("add manualy: " + changed);
                    add.addFilepattern(changed);
                    doCommit = true;
                }
                add.call();
            }
        }

        List<ScmFile> checkedInFiles = Collections.emptyList();
        if (doCommit) {
            UserInfo author = getAuthor(repo, git);
            UserInfo committer = getCommitter(repo, git);

            CommitCommand command = git.commit().setMessage(message).setAuthor(author.name, author.email);
            command.setCommitter(committer.name, committer.email);
            RevCommit commitRev = command.call();

            getLogger().info("commit done: " + commitRev.getShortMessage());
            checkedInFiles = JGitUtils.getFilesInCommit(git.getRepository(), commitRev);
            if (getLogger().isDebugEnabled()) {
                for (ScmFile scmFile : checkedInFiles) {
                    getLogger().debug("in commit: " + scmFile);
                }
            }
        }

        if (repo.isPushChanges()) {
            String branch = version != null ? version.getName() : null;
            if (StringUtils.isBlank(branch)) {
                branch = git.getRepository().getBranch();
            }
            RefSpec refSpec = new RefSpec(Constants.R_HEADS + branch + ":" + Constants.R_HEADS + branch);
            getLogger().info("push changes to remote... " + refSpec.toString());
            JGitUtils.push(getLogger(), git, (GitScmProviderRepository) repo, refSpec);
        }

        return new CheckInScmResult("JGit checkin", checkedInFiles);
    } catch (Exception e) {
        throw new ScmException("JGit checkin failure!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}