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
This commit is contained in:
parent
4a11534c25
commit
45e9e28ad9
|
@ -307,6 +307,34 @@ public void putMatchingWithNoMatchingRefs() throws Exception {
|
|||
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(
|
||||
|
|
|
@ -401,7 +401,7 @@ public RefUpdate.Result save() throws IOException {
|
|||
*/
|
||||
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…
Reference in New Issue