@Signature public ArrayMemory getTags() { Map<String, Ref> tags = getWrappedObject().getRepository().getTags(); ArrayMemory memory = new ArrayMemory(); for (Map.Entry<String, Ref> entry : tags.entrySet()) { memory.put(entry.getKey(), GitUtils.valueOf(entry.getValue())); } return memory; }
/** * List all tag from local git * * @param repo * @return * @throws GitException */ public static List<String> tags(Repository repo) throws GitException { Map<String, Ref> tags = repo.getTags(); List<Ref> refs = Lists.newArrayList(tags.values()); Collections.reverse(refs); return simpleRef(refs); }
public static Set<String> loadVersionTagList(Repository repository, String versionTagNamePattern) { Set<String> versionTagList = new HashSet<String>(); if (versionTagNamePattern != null) { versionTagList = new HashSet<String>(); for (String tagName : repository.getTags().keySet()) { if (tagName.matches(versionTagNamePattern)) { versionTagList.add(tagName); } } } else { versionTagList = repository.getTags().keySet(); } return versionTagList; }
/** * Get all the tag references in the given repository. * * @param repository * @return non-null but possibly array of branch reference names */ public static Collection<String> getTags(final Repository repository) { if (repository == null) throw new IllegalArgumentException( Assert.formatNotNull("Repository")); return repository.getTags().keySet(); }
protected List<Version> getAllVersionsInRepository() { return repository .getTags() .keySet() .stream() .map(key -> { try { return Optional.of(Version.valueOf(key)); } catch (Exception e) { return Optional.<Version>empty(); } }) .filter(Optional::isPresent) .map(Optional::get) .sorted() .collect(Collectors.toList()); }
private List<Ref> getTags() { Repository repository = getCommit().getRepository(); List<Ref> tags = new ArrayList<Ref>(repository.getTags().values()); Collections.sort(tags, new Comparator<Ref>() { public int compare(Ref r1, Ref r2) { return Repository.shortenRefName(r1.getName()) .compareToIgnoreCase( Repository.shortenRefName(r2.getName())); } }); return tags; }
private String getTagsString() { StringBuilder sb = new StringBuilder(); Map<String, Ref> tagsMap = db.getTags(); for (Entry<String, Ref> tagEntry : tagsMap.entrySet()) { ObjectId target = tagEntry.getValue().getPeeledObjectId(); if (target == null) target = tagEntry.getValue().getObjectId(); if (target != null && target.equals(commit)) { if (sb.length() > 0) sb.append(", "); //$NON-NLS-1$ sb.append(tagEntry.getKey()); } } return sb.toString(); }
public boolean isTag(String tagname) throws Exception { Map<String, Ref> allRefs = git.getRepository().getTags(); for(String key : allRefs.keySet()) { Ref ref = allRefs.get(key); log.trace("Checking tag key{}, ref{}", key, ref.getName()); if(key.equals(tagname) && ref.getName().equals("refs/tags/" + tagname)) { return true; } } return false; }
private Ref getLatestTag(String component) { Map<String, Ref> forComponent = Maps.filterKeys(git.getRepository().getTags(), startsWith(component + "-")); if (!forComponent.isEmpty()) { String latest = Ordering.from(new VersionTagComparator()).max(forComponent.keySet()); return forComponent.get(latest); } return null; }
protected static Map<String, Ref> getTagsFromRepo(File projectDir) throws IOException { Repository repository = getRepository(getRepositoryLocation(projectDir)); return repository.getTags(); }
protected List<String> getTagsOnHead() throws IOException { final ObjectId head = repository.resolve(Constants.HEAD); logger.info("Head is {}", head.toString()); return repository.getTags().entrySet().stream() .filter(entry -> { final Boolean value = entry.getValue().getPeeledObjectId() != null && entry.getValue().getPeeledObjectId().compareTo(head) == 0; logger.debug("Comparing {} to {} : result {}", entry.getValue().getPeeledObjectId(), head, value); return value; }) .map(Map.Entry::getKey) .collect(Collectors.toList()); }
public List<Tag> getTagsOnCommit(String revName) throws GitException, IOException { Repository db = getRepository(); ObjectId commit = db.resolve(revName); List<Tag> result = new ArrayList<Tag>(); if (null != commit) { for (final Map.Entry<String, Ref> tag : db.getTags().entrySet()) { Ref ref = tag.getValue(); if (ref.getObjectId().equals(commit)) { result.add(new Tag(tag.getKey(), ref.getObjectId())); } } } return result; }
/** {@inheritDoc} */ @Deprecated public List<Tag> getTagsOnCommit(String revName) throws GitException, IOException { try (Repository db = getRepository()) { final ObjectId commit = db.resolve(revName); final List<Tag> ret = new ArrayList<>(); for (final Map.Entry<String, Ref> tag : db.getTags().entrySet()) { Ref value = tag.getValue(); if (value != null) { final ObjectId tagId = value.getObjectId(); if (commit != null && commit.equals(tagId)) ret.add(new Tag(tag.getKey(), tagId)); } } return ret; } }
private Map<String, List<RevTag>> createCommitIDToTagsMap(Repository repository, RevWalk revWalk) throws IOException { Map<String, Ref> allTags = repository.getTags(); Map<String, List<RevTag>> revTags = new HashMap<String, List<RevTag>>(); for (Ref ref : allTags.values()) { try { RevTag revTag = revWalk.parseTag(ref.getObjectId()); String commitID = revTag.getObject().getId().getName(); if (!revTags.containsKey(commitID)) { revTags.put(commitID, new ArrayList<RevTag>()); } revTags.get(commitID).add(revTag); } catch (IncorrectObjectTypeException e) { log.debug("Light-weight tags not supported. Skipping " + ref.getName()); } } return revTags; }
private RevTree extractTag(String tagName) throws MissingObjectException, IncorrectObjectTypeException, IOException { RevWalk walk = new RevWalk(repository); Map<String, Ref> tags = repository.getTags(); Ref tag = tags.get(tagName); RevTree target = walk.parseTree(tag.getObjectId()); walk.close(); return target; }
/** * @param event * @return the tags * @throws ExecutionException */ protected List<RevTag> getRevTags(ExecutionEvent event) throws ExecutionException { Repository repo = getRepository(event); Collection<Ref> revTags = repo.getTags().values(); List<RevTag> tags = new ArrayList<RevTag>(); RevWalk walk = new RevWalk(repo); for (Ref ref : revTags) { try { tags.add(walk.parseTag(repo.resolve(ref.getName()))); } catch (IOException e) { throw new ExecutionException(e.getMessage(), e); } } return tags; }
/** {@inheritDoc} */ @Override public Set<String> getTagNames(String tagPattern) throws GitException { if (tagPattern == null) tagPattern = "*"; Set<String> tags = new HashSet<>(); try (Repository repo = getRepository()) { FileNameMatcher matcher = new FileNameMatcher(tagPattern, null); Map<String, Ref> tagList = repo.getTags(); for (String name : tagList.keySet()) { matcher.reset(); matcher.append(name); if (matcher.isMatch()) tags.add(name); } } catch (InvalidPatternException e) { throw new GitException(e); } return tags; }
private Map<String, RefWithTagName> mapCommitsToTags(Git git) { RefWithTagNameComparator comparator = new RefWithTagNameComparator(git); // Maps commit hash to list of all refs pointing to given commit hash. // All keys in this map should be same as commit hashes in 'git show-ref --tags -d' Map<String, RefWithTagName> commitHashToTag = new HashMap<>(); for (Map.Entry<String, Ref> entry : git.getRepository().getTags().entrySet()) { RefWithTagName refWithTagName = new RefWithTagName(entry.getValue(), entry.getKey()); ObjectId peeledRef = refWithTagName.getRef().getPeeledObjectId(); if (peeledRef == null) { // lightweight tag (commit object) updateCommitHashMap(commitHashToTag, comparator, entry.getValue().getObjectId(), refWithTagName); } else { // annotated tag (tag object) updateCommitHashMap(commitHashToTag, comparator, peeledRef, refWithTagName); } } return commitHashToTag; }
public Map<String, ByteSource> getEntries(Bundle bundle) throws IOException { Ref ref; if (bundle.isSnapshot()) { // TODO: what does it mean to get entries for an old snapshot version? ref = getBranch(git.getRepository(), bundle.getName()); } else { ref = git.getRepository().getTags().get(bundle.getName() + "-" + bundle.getVersionString()); Preconditions.checkNotNull(ref, "cannot find tag for bundle %s:%s", bundle.getName(), bundle.getVersionString()); } RevCommit commit = GitUtils.getCommit(git.getRepository(), ref); return Maps.transformValues(GitUtils.getEntries(git.getRepository(), commit.getTree()), byteSourceFunction(git.getRepository())); }