From d7377877e0371b6806b49a7ebd4a42ad448a3ad4 Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Wed, 15 Jul 2015 10:18:01 -0700 Subject: [PATCH] PushCertificateStore: Return boolean from batch save methods Change-Id: I9730cb4f60c60ee6d5a7a156a0b6a53f79309ec3 --- .../eclipse/jgit/transport/PushCertificateStoreTest.java | 6 +++++- .../org/eclipse/jgit/transport/PushCertificateStore.java | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateStoreTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateStoreTest.java index ef479ffaa..459ca876d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateStoreTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateStoreTest.java @@ -49,6 +49,8 @@ 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 void lockFailure() throws Exception { @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 commands = batch.getCommands(); assertEquals(1, commands.size()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java index 9b524def6..389bd689c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java @@ -394,17 +394,19 @@ public RefUpdate.Result save() throws IOException { * * @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; } /**