diff options
author | Dave Borowitz <dborowitz@google.com> | 2015-09-02 15:04:33 -0400 |
---|---|---|
committer | Dave Borowitz <dborowitz@google.com> | 2015-09-02 15:17:10 -0400 |
commit | 45e9e28ad9daad3c64a16685bd9c07ed18d2ab50 (patch) | |
tree | 48ec2c694b29954f41d969d028154ef24d0c493e | |
parent | 4a11534c25a17df3acb185ce701e921cca688b4b (diff) | |
download | jgit-45e9e28ad9daad3c64a16685bd9c07ed18d2ab50.tar.gz jgit-45e9e28ad9daad3c64a16685bd9c07ed18d2ab50.zip |
PushCertificateStore: Don't add no-op command to batch
If no refs match the input list and we are writing to a batch,
the returned new commit from write() will match the current commit.
Adding a command to the batch for this case is harmless as it will
succeed, but it's more straightforward to just skip adding a command
in this case.
Add tests or the combination of saving matching refs and saving to a
batch.
Change-Id: I6837389b08e6c80bc2d4c9e9c506d07293ea5fb2
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateStoreTest.java | 28 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java | 2 |
2 files changed, 29 insertions, 1 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 459ca876d1..68e0129525 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 @@ -308,6 +308,34 @@ public class PushCertificateStoreTest { } @Test + public void putMatchingWithNoMatchingRefsInBatchOnEmptyRef() + throws Exception { + PushCertificate addMaster = newCert( + command(zeroId(), ID1, "refs/heads/master"), + command(zeroId(), ID2, "refs/heads/branch")); + store.put(addMaster, newIdent(), Collections.<ReceiveCommand> emptyList()); + BatchRefUpdate batch = repo.getRefDatabase().newBatchUpdate(); + assertFalse(store.save(batch)); + assertEquals(0, batch.getCommands().size()); + } + + @Test + public void putMatchingWithNoMatchingRefsInBatchOnNonEmptyRef() + throws Exception { + PushCertificate addMaster = newCert( + command(zeroId(), ID1, "refs/heads/master")); + store.put(addMaster, newIdent()); + assertEquals(NEW, store.save()); + + PushCertificate addBranch = newCert( + command(zeroId(), ID2, "refs/heads/branch")); + store.put(addBranch, newIdent(), Collections.<ReceiveCommand> emptyList()); + BatchRefUpdate batch = repo.getRefDatabase().newBatchUpdate(); + assertFalse(store.save(batch)); + assertEquals(0, batch.getCommands().size()); + } + + @Test public void putMatchingWithSomeMatchingRefs() throws Exception { PushCertificate addMasterAndBranch = newCert( command(zeroId(), ID1, "refs/heads/master"), 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 389bd689ce..d8672d5a2b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java @@ -401,7 +401,7 @@ public class PushCertificateStore implements AutoCloseable { */ public boolean save(BatchRefUpdate batch) throws IOException { ObjectId newId = write(); - if (newId == null) { + if (newId == null || newId.equals(commit)) { return false; } batch.addCommand(new ReceiveCommand( |