Repository: Deprecate getTags method

Callers should use getRefDatabase().getRefsByPrefix(R_TAGS) instead.

Adjust the tests accordingly.

Bug: 534731
Change-Id: Ib28ae365e42720268996ff46e34cae1745ad545c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
David Pursehouse 2018-05-22 08:34:53 +09:00
parent 4132dc5858
commit 1da2ff7242
3 changed files with 17 additions and 13 deletions

View File

@ -43,10 +43,11 @@
package org.eclipse.jgit.pgm; package org.eclipse.jgit.pgm;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.CLIRepositoryTestCase; import org.eclipse.jgit.lib.CLIRepositoryTestCase;
import org.eclipse.jgit.lib.Ref;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -75,13 +76,9 @@ public void testTagTwice() throws Exception {
@Test @Test
public void testTagDelete() throws Exception { public void testTagDelete() throws Exception {
git.tag().setName("test").call(); git.tag().setName("test").call();
assertNotNull(git.getRepository().exactRef("refs/tags/test"));
Ref ref = git.getRepository().getTags().get("test");
assertEquals("refs/tags/test", ref.getName());
assertEquals("", executeUnchecked("git tag -d test")[0]); assertEquals("", executeUnchecked("git tag -d test")[0]);
Ref deletedRef = git.getRepository().getTags().get("test"); assertNull(git.getRepository().exactRef("refs/tags/test"));
assertEquals(null, deletedRef);
} }
@Test @Test

View File

@ -42,6 +42,7 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.eclipse.jgit.lib.Constants.R_TAGS;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -135,26 +136,30 @@ public void testFailureOnSignedTags() throws GitAPIException {
} }
} }
private List<Ref> getTags() throws Exception {
return db.getRefDatabase().getRefsByPrefix(R_TAGS);
}
@Test @Test
public void testDelete() throws Exception { public void testDelete() throws Exception {
try (Git git = new Git(db)) { try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
Ref tagRef = git.tag().setName("tag").call(); Ref tagRef = git.tag().setName("tag").call();
assertEquals(1, db.getTags().size()); assertEquals(1, getTags().size());
List<String> deleted = git.tagDelete().setTags(tagRef.getName()) List<String> deleted = git.tagDelete().setTags(tagRef.getName())
.call(); .call();
assertEquals(1, deleted.size()); assertEquals(1, deleted.size());
assertEquals(tagRef.getName(), deleted.get(0)); assertEquals(tagRef.getName(), deleted.get(0));
assertEquals(0, db.getTags().size()); assertEquals(0, getTags().size());
Ref tagRef1 = git.tag().setName("tag1").call(); Ref tagRef1 = git.tag().setName("tag1").call();
Ref tagRef2 = git.tag().setName("tag2").call(); Ref tagRef2 = git.tag().setName("tag2").call();
assertEquals(2, db.getTags().size()); assertEquals(2, getTags().size());
deleted = git.tagDelete().setTags(tagRef1.getName(), tagRef2.getName()) deleted = git.tagDelete().setTags(tagRef1.getName(), tagRef2.getName())
.call(); .call();
assertEquals(2, deleted.size()); assertEquals(2, deleted.size());
assertEquals(0, db.getTags().size()); assertEquals(0, getTags().size());
} }
} }
@ -163,13 +168,13 @@ public void testDeleteFullName() throws Exception {
try (Git git = new Git(db)) { try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
Ref tagRef = git.tag().setName("tag").call(); Ref tagRef = git.tag().setName("tag").call();
assertEquals(1, db.getTags().size()); assertEquals(1, getTags().size());
List<String> deleted = git.tagDelete() List<String> deleted = git.tagDelete()
.setTags(Repository.shortenRefName(tagRef.getName())).call(); .setTags(Repository.shortenRefName(tagRef.getName())).call();
assertEquals(1, deleted.size()); assertEquals(1, deleted.size());
assertEquals(tagRef.getName(), deleted.get(0)); assertEquals(tagRef.getName(), deleted.get(0));
assertEquals(0, db.getTags().size()); assertEquals(0, getTags().size());
} }
} }

View File

@ -1108,7 +1108,9 @@ public Map<String, Ref> getAllRefs() {
* @return mutable map of all tags; key is short tag name ("v1.0") and value * @return mutable map of all tags; key is short tag name ("v1.0") and value
* of the entry contains the ref with the full tag name * of the entry contains the ref with the full tag name
* ("refs/tags/v1.0"). * ("refs/tags/v1.0").
* @deprecated use {@code getRefDatabase().getRefsByPrefix(R_TAGS)} instead
*/ */
@Deprecated
@NonNull @NonNull
public Map<String, Ref> getTags() { public Map<String, Ref> getTags() {
try { try {