]> source.dussan.org Git - jgit.git/commitdiff
Repository: Deprecate getTags method 17/123017/3
authorDavid Pursehouse <david.pursehouse@gmail.com>
Mon, 21 May 2018 23:34:53 +0000 (08:34 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 22 May 2018 00:40:54 +0000 (09:40 +0900)
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>
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/TagTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/TagCommandTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

index 03391a0fb6d7f04c094000f1f89a7873cdf5eb18..d38a41dcb8d9a1ed4a81ec6c94920feea014f68a 100644 (file)
 package org.eclipse.jgit.pgm;
 
 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.lib.CLIRepositoryTestCase;
-import org.eclipse.jgit.lib.Ref;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -75,13 +76,9 @@ public class TagTest extends CLIRepositoryTestCase {
        @Test
        public void testTagDelete() throws Exception {
                git.tag().setName("test").call();
-
-               Ref ref = git.getRepository().getTags().get("test");
-               assertEquals("refs/tags/test", ref.getName());
-
+               assertNotNull(git.getRepository().exactRef("refs/tags/test"));
                assertEquals("", executeUnchecked("git tag -d test")[0]);
-               Ref deletedRef = git.getRepository().getTags().get("test");
-               assertEquals(null, deletedRef);
+               assertNull(git.getRepository().exactRef("refs/tags/test"));
        }
 
        @Test
index 87098b65f494869549bed2fdd89e13c73e5cbf8e..3b29a5bbfba8f48fb1a801ceb1a43eb8bb2c1819 100644 (file)
@@ -42,6 +42,7 @@
  */
 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.fail;
 
@@ -135,26 +136,30 @@ public class TagCommandTest extends RepositoryTestCase {
                }
        }
 
+       private List<Ref> getTags() throws Exception {
+               return db.getRefDatabase().getRefsByPrefix(R_TAGS);
+       }
+
        @Test
        public void testDelete() throws Exception {
                try (Git git = new Git(db)) {
                        git.commit().setMessage("initial commit").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())
                                        .call();
                        assertEquals(1, deleted.size());
                        assertEquals(tagRef.getName(), deleted.get(0));
-                       assertEquals(0, db.getTags().size());
+                       assertEquals(0, getTags().size());
 
                        Ref tagRef1 = git.tag().setName("tag1").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())
                                        .call();
                        assertEquals(2, deleted.size());
-                       assertEquals(0, db.getTags().size());
+                       assertEquals(0, getTags().size());
                }
        }
 
@@ -163,13 +168,13 @@ public class TagCommandTest extends RepositoryTestCase {
                try (Git git = new Git(db)) {
                        git.commit().setMessage("initial commit").call();
                        Ref tagRef = git.tag().setName("tag").call();
-                       assertEquals(1, db.getTags().size());
+                       assertEquals(1, getTags().size());
 
                        List<String> deleted = git.tagDelete()
                                        .setTags(Repository.shortenRefName(tagRef.getName())).call();
                        assertEquals(1, deleted.size());
                        assertEquals(tagRef.getName(), deleted.get(0));
-                       assertEquals(0, db.getTags().size());
+                       assertEquals(0, getTags().size());
                }
        }
 
index e7e2b003493e01a8e351710c101f006ba7f72940..2d34736111a800d9287fcdf363e1efd17ce8e821 100644 (file)
@@ -1108,7 +1108,9 @@ public abstract class Repository implements AutoCloseable {
         * @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
         *         ("refs/tags/v1.0").
+        * @deprecated use {@code getRefDatabase().getRefsByPrefix(R_TAGS)} instead
         */
+       @Deprecated
        @NonNull
        public Map<String, Ref> getTags() {
                try {