Skip checks in batch-update when there are no updates

When batch-update does not contain any commands, do not look for
errors in the list otherwise an ArrayIndexOutOfBound would make
the entire call chain to fail.

Change-Id: Ie0ede6780062c02e0615934950e8e61b584af0e0
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteBatchRefUpdate.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteBatchRefUpdate.java
index d93c744..783f6a2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteBatchRefUpdate.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteBatchRefUpdate.java
@@ -221,6 +221,10 @@
   private void updateSharedRefDb(Stream<RefPair> oldRefs) throws IOException {
     List<RefPair> refsToUpdate =
         oldRefs.sorted(comparing(RefPair::hasFailed).reversed()).collect(Collectors.toList());
+    if (refsToUpdate.isEmpty()) {
+      return;
+    }
+
     if (refsToUpdate.get(0).hasFailed()) {
       RefPair failedRef = refsToUpdate.get(0);
       throw new IOException(
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteBatchRefUpdateTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteBatchRefUpdateTest.java
index c23135d..bc558d5 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteBatchRefUpdateTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/MultiSiteBatchRefUpdateTest.java
@@ -99,4 +99,14 @@
     doReturn(false).when(sharedRefDb).compareAndPut(A_TEST_PROJECT_NAME, oldRef, newRef);
     multiSiteRefUpdate.execute(revWalk, progressMonitor, Collections.emptyList());
   }
+
+  @Test
+  public void executeSuccessfullyWithNoExceptionsWhenEmptyList() throws IOException {
+    doReturn(batchRefUpdate).when(refDatabase).newBatchUpdate();
+    doReturn(Collections.emptyList()).when(batchRefUpdate).getCommands();
+
+    multiSiteRefUpdate = new MultiSiteBatchRefUpdate(sharedRefDb, A_TEST_PROJECT_NAME, refDatabase);
+
+    multiSiteRefUpdate.execute(revWalk, progressMonitor, Collections.emptyList());
+  }
 }