]> source.dussan.org Git - jgit.git/commitdiff
TestRepository: Add delete() method 11/72111/2
authorJonathan Nieder <jrn@google.com>
Wed, 4 May 2016 22:48:36 +0000 (15:48 -0700)
committerJonathan Nieder <jrn@google.com>
Wed, 4 May 2016 22:48:36 +0000 (15:48 -0700)
Change-Id: Ib4841397ceab44bd38cf2f154314ac36ded73ae0

org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java

index 1119e638241fde62ec8f48232f96d6beeb7e493c..d0045d69846f6d48cafb844787464ac8ede44211 100644 (file)
@@ -586,6 +586,31 @@ public class TestRepository<R extends Repository> {
                }
        }
 
+       /**
+        * Delete a reference.
+        *
+        * @param ref
+        *            the name of the reference to delete. This is normalized
+        *            in the same way as {@link #update(String, T)}.
+        * @throws Exception
+        * @since 4.4
+        */
+       public void delete(String ref) throws Exception {
+               ref = normalizeRef(ref);
+               RefUpdate u = db.updateRef(ref);
+               switch (u.delete()) {
+               case FAST_FORWARD:
+               case FORCED:
+               case NEW:
+               case NO_CHANGE:
+                       updateServerInfo();
+                       return;
+
+               default:
+                       throw new IOException("Cannot delete " + ref + " " + u.getResult());
+               }
+       }
+
        private static String normalizeRef(String ref) {
                if (Constants.HEAD.equals(ref)) {
                        // nothing
@@ -959,6 +984,15 @@ public class TestRepository<R extends Repository> {
                public RevCommit update(RevCommit to) throws Exception {
                        return TestRepository.this.update(ref, to);
                }
+
+               /**
+                * Delete this branch.
+                * @throws Exception
+                * @since 4.4
+                */
+               public void delete() throws Exception {
+                       TestRepository.this.delete(ref);
+               }
        }
 
        /** Helper to generate a commit. */