]> source.dussan.org Git - jgit.git/commitdiff
PushCertificateStore: Return boolean from batch save methods 16/52016/2
authorDave Borowitz <dborowitz@google.com>
Wed, 15 Jul 2015 17:18:01 +0000 (10:18 -0700)
committerDave Borowitz <dborowitz@google.com>
Thu, 16 Jul 2015 01:09:42 +0000 (18:09 -0700)
Change-Id: I9730cb4f60c60ee6d5a7a156a0b6a53f79309ec3

org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateStoreTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java

index ef479ffaaf086b8043773cd11786a456f270081b..459ca876d184da692c218cf8db08d1656f4d3e78 100644 (file)
@@ -49,6 +49,8 @@ import static org.eclipse.jgit.lib.RefUpdate.Result.LOCK_FAILURE;
 import static org.eclipse.jgit.lib.RefUpdate.Result.NEW;
 import static org.eclipse.jgit.lib.RefUpdate.Result.NO_CHANGE;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -277,10 +279,12 @@ public class PushCertificateStoreTest {
        @Test
        public void saveInBatch() throws Exception {
                BatchRefUpdate batch = repo.getRefDatabase().newBatchUpdate();
+               assertFalse(store.save(batch));
+               assertEquals(0, batch.getCommands().size());
                PushCertificate addMaster = newCert(
                                command(zeroId(), ID1, "refs/heads/master"));
                store.put(addMaster, newIdent());
-               store.save(batch);
+               assertTrue(store.save(batch));
 
                List<ReceiveCommand> commands = batch.getCommands();
                assertEquals(1, commands.size());
index 9b524def660afa87922d9a9304281a07e543569c..389bd689cefb36c3ffc49e52ee70ce95a235b416 100644 (file)
@@ -394,17 +394,19 @@ public class PushCertificateStore implements AutoCloseable {
         *
         * @param batch
         *            update to save to.
+        * @return whether a command was added to the batch.
         * @throws IOException
         *             if there was an error reading from or writing to the
         *             repository.
         */
-       public void save(BatchRefUpdate batch) throws IOException {
+       public boolean save(BatchRefUpdate batch) throws IOException {
                ObjectId newId = write();
                if (newId == null) {
-                       return;
+                       return false;
                }
                batch.addCommand(new ReceiveCommand(
                                commit != null ? commit : ObjectId.zeroId(), newId, REF_NAME));
+               return true;
        }
 
        /**