package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.util.Map;
assertOneResult("tag2", git.nameRev().addAnnotatedTags(), c);
}
+ @Test
+ public void annotatedTagsNoResult() throws Exception {
+ RevCommit c = tr.commit().create();
+ tr.update("refs/heads/master", c);
+ tr.update("refs/tags/tag1", c);
+ tr.update("refs/tags/tag2", c);
+ Map<ObjectId, String> result = git.nameRev()
+ .add(c)
+ .addAnnotatedTags()
+ .call();
+ assertTrue(result.toString(), result.isEmpty());
+ }
+
@Test
public void simpleAncestor() throws Exception {
// 0--1--2
private final RevWalk walk;
private final List<String> prefixes;
- private final List<Ref> refs;
private final List<ObjectId> revs;
+ private List<Ref> refs;
private int mergeCost;
/**
super(repo);
mergeCost = MERGE_COST;
prefixes = new ArrayList<String>(2);
- refs = new ArrayList<Ref>();
revs = new ArrayList<ObjectId>(2);
walk = new RevWalk(repo) {
@Override
try {
Map<ObjectId, String> nonCommits = new HashMap<ObjectId, String>();
FIFORevQueue pending = new FIFORevQueue();
- for (Ref ref : refs)
- addRef(ref, nonCommits, pending);
+ if (refs != null) {
+ for (Ref ref : refs)
+ addRef(ref, nonCommits, pending);
+ }
addPrefixes(nonCommits, pending);
int cutoff = minCommitTime() - COMMIT_TIME_SLOP;
*/
public NameRevCommand addAnnotatedTags() {
checkCallable();
+ if (refs == null)
+ refs = new ArrayList<Ref>();
try {
for (Ref ref : repo.getRefDatabase().getRefs(Constants.R_TAGS).values()) {
ObjectId id = ref.getObjectId();
*/
public NameRevCommand addRef(Ref ref) {
checkCallable();
+ if (refs == null)
+ refs = new ArrayList<Ref>();
refs.add(ref);
return this;
}
if (!prefixes.isEmpty()) {
for (String prefix : prefixes)
addPrefix(prefix, nonCommits, pending);
- } else if (refs.isEmpty())
+ } else if (refs == null)
addPrefix(Constants.R_REFS, nonCommits, pending);
}