Browse Source

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
stable-4.1
Dave Borowitz 9 years ago
parent
commit
45e9e28ad9
  1. 28
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateStoreTest.java
  2. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java

28
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateStoreTest.java

@ -307,6 +307,34 @@ public class PushCertificateStoreTest {
assertEquals(NO_CHANGE, store.save());
}
@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(

2
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(

Loading…
Cancel
Save