MergeOp: Throw more descriptive ResourceConflictExceptions

Keep track of problems that occur during the various early validation
phases of submitting a batch of changes. This replaces usage of
CommitMergeStatus for some statuses (e.g. REVISION_GONE) that should
really fail the batch before any merge attempt is made. It also
avoids throwing IntegrationExceptions early, looping through the full
list of changes to collect more errors.

Currently the failFast() method throws ResourceConflictException,
since that is the easiest way to expose the error message to users. In
the future we will probably rearrange exception types a bit more.

Change-Id: I4846043333eaedb06975825b8aa75b3bfc97e698
This commit is contained in:
Dave Borowitz
2015-12-18 16:47:20 -05:00
parent 7c7643bb64
commit bd77ad3609
3 changed files with 111 additions and 97 deletions

View File

@@ -34,7 +34,6 @@ import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.git.MetaDataUpdate;
import com.google.gerrit.server.git.VersionedMetaData;
import com.google.gerrit.testutil.ConfigSuite;
@@ -237,13 +236,11 @@ public class SubmitTypeRuleIT extends AbstractDaemonTest {
gApi.changes().id(r2.getChangeId()).current().submit();
fail("Expected ResourceConflictException");
} catch (ResourceConflictException e) {
assertThat(e).hasMessage("Merge Conflict");
Throwable t = e.getCause();
assertThat(t).isInstanceOf(IntegrationException.class);
assertThat(t.getMessage()).isEqualTo(
"Change " + r1.getChange().getId() + " has submit type CHERRY_PICK, "
+ "but previously chose submit type MERGE_IF_NECESSARY from change "
+ r2.getChange().getId() + " in the same batch");
assertThat(e).hasMessage(
"Failed to submit 2 changes due to the following problems:\n"
+ "Change " + r1.getChange().getId() + ": Change has submit type "
+ "CHERRY_PICK, but previously chose submit type MERGE_IF_NECESSARY "
+ "from change " + r2.getChange().getId() + " in the same batch");
}
}