Example usage for org.eclipse.jgit.lib ObjectId startsWith

List of usage examples for org.eclipse.jgit.lib ObjectId startsWith

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib ObjectId startsWith.

Prototype

public boolean startsWith(AbbreviatedObjectId abbr) 

Source Link

Document

Tests if this ObjectId starts with the given abbreviation.

Usage

From source file:org.tomitribe.lieutenant.git.Git.java

License:Apache License

public Set<String> tagList(String commit) {

    final Set<String> tags = new HashSet<String>();
    final AbbreviatedObjectId abbreviatedCommit = AbbreviatedObjectId.fromString(commit);

    try {/*ww w  .  ja  v a 2s.  c  o  m*/
        List<Ref> refs = this.git.tagList().call();

        for (Ref ref : refs) {

            Ref peeledRef = this.git.getRepository().peel(ref);
            final ObjectId tagCommit;
            if (peeledRef.getPeeledObjectId() != null) {
                tagCommit = peeledRef.getPeeledObjectId();
            } else {
                tagCommit = ref.getObjectId();
            }

            if (tagCommit.startsWith(abbreviatedCommit)) {
                final String name = ref.getName();
                tags.add(name.substring(name.lastIndexOf('/') + 1, name.length()));
            }
        }

    } catch (GitAPIException e) {
        throw new IllegalArgumentException(e);
    }

    return Collections.unmodifiableSet(tags);
}