CreateChange: Do not fail with ISE if base commit doesn't exist
Signed-off-by: Edwin Kempin <ekempin@google.com> Change-Id: If2886342815234d385e10d7ba7fe27127229ad4a
This commit is contained in:

committed by
David Pursehouse

parent
05e5d34793
commit
41c99c9086
@@ -81,6 +81,7 @@ import java.util.List;
|
|||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||||
import org.eclipse.jgit.errors.InvalidObjectIdException;
|
import org.eclipse.jgit.errors.InvalidObjectIdException;
|
||||||
|
import org.eclipse.jgit.errors.MissingObjectException;
|
||||||
import org.eclipse.jgit.errors.NoMergeBaseException;
|
import org.eclipse.jgit.errors.NoMergeBaseException;
|
||||||
import org.eclipse.jgit.errors.NoMergeBaseException.MergeBaseFailureReason;
|
import org.eclipse.jgit.errors.NoMergeBaseException.MergeBaseFailureReason;
|
||||||
import org.eclipse.jgit.lib.CommitBuilder;
|
import org.eclipse.jgit.lib.CommitBuilder;
|
||||||
@@ -362,7 +363,12 @@ public class CreateChange
|
|||||||
String.format("Base %s doesn't represent a valid SHA-1", baseCommit));
|
String.format("Base %s doesn't represent a valid SHA-1", baseCommit));
|
||||||
}
|
}
|
||||||
|
|
||||||
RevCommit parentRevCommit = revWalk.parseCommit(parentCommit);
|
RevCommit parentRevCommit;
|
||||||
|
try {
|
||||||
|
parentRevCommit = revWalk.parseCommit(parentCommit);
|
||||||
|
} catch (MissingObjectException e) {
|
||||||
|
throw new UnprocessableEntityException(String.format("Base %s doesn't exist", baseCommit));
|
||||||
|
}
|
||||||
|
|
||||||
if (destRef == null) {
|
if (destRef == null) {
|
||||||
throw new BadRequestException("Destination branch does not exist");
|
throw new BadRequestException("Destination branch does not exist");
|
||||||
|
@@ -245,6 +245,16 @@ public class CreateChangeIT extends AbstractDaemonTest {
|
|||||||
input, UnprocessableEntityException.class, "Base notasha1 doesn't represent a valid SHA-1");
|
input, UnprocessableEntityException.class, "Base notasha1 doesn't represent a valid SHA-1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createChangeWithNonExistingParentCommitFails() throws Exception {
|
||||||
|
ChangeInput input = newChangeInput(ChangeStatus.NEW);
|
||||||
|
input.baseCommit = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
|
||||||
|
assertCreateFails(
|
||||||
|
input,
|
||||||
|
UnprocessableEntityException.class,
|
||||||
|
String.format("Base %s doesn't exist", input.baseCommit));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createChangeWithParentCommitOnWrongBranchFails() throws Exception {
|
public void createChangeWithParentCommitOnWrongBranchFails() throws Exception {
|
||||||
Map<String, PushOneCommit.Result> setup =
|
Map<String, PushOneCommit.Result> setup =
|
||||||
|
Reference in New Issue
Block a user