Fix start --wait to track in-flight collisions and to not fail

Previously when an in-flight collision occurred on a push that the
'start --wait' command  was waiting for, the command would terminate
with an error (and if it weren't for an NPE it would stop waiting
prematurely). This was happening because PushOne is not tracking
collisions resulting in its cleanup code assuming there was a failure.
Fix this by tracking the collision in PushOne and skipping the cleanup
in this case.

Ironically, the NPE in change I107d964a33349aaa5d6ae9aca68aab2889689155
was preventing the start command from receiving the premature
termination on the collision, but it was not preventing the error. Thus
this fix should get merged before fixing the NPE to avoid a worse
scenario.

Change-Id: Ibf1ca624739205f6f92e097213828faf29de9300
Bug: Issue 12719
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
index 966d7c0..8ccd54a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
@@ -102,6 +102,7 @@
   private final Set<String> delta = Sets.newHashSetWithExpectedSize(4);
   private boolean pushAllRefs;
   private Repository git;
+  private boolean isCollision;
   private boolean retrying;
   private int retryCount;
   private final int maxRetries;
@@ -277,7 +278,7 @@
   }
 
   private void statesCleanUp() {
-    if (!stateMap.isEmpty() && !isRetrying()) {
+    if (!stateMap.isEmpty() && !isRetrying() && !isCollision) {
       for (Map.Entry<String, ReplicationState> entry : stateMap.entries()) {
         entry
             .getValue()
@@ -315,6 +316,7 @@
     //
     MDC.put(ID_MDC_KEY, HexFormat.fromInt(id));
     RunwayStatus status = pool.requestRunway(this);
+    isCollision = false;
     if (!status.isAllowed()) {
       if (status.isCanceled()) {
         repLog.info("PushOp for replication to {} was canceled and thus won't be rescheduled", uri);
@@ -324,6 +326,7 @@
             uri,
             HexFormat.fromInt(status.getInFlightPushId()));
         pool.reschedule(this, Destination.RetryReason.COLLISION);
+        isCollision = true;
       }
       return;
     }