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:
Edwin Kempin
2019-10-08 14:33:22 +02:00
committed by David Pursehouse
parent 05e5d34793
commit 41c99c9086
2 changed files with 17 additions and 1 deletions

View File

@@ -81,6 +81,7 @@ import java.util.List;
import java.util.TimeZone;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.errors.InvalidObjectIdException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.NoMergeBaseException;
import org.eclipse.jgit.errors.NoMergeBaseException.MergeBaseFailureReason;
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));
}
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) {
throw new BadRequestException("Destination branch does not exist");

View File

@@ -245,6 +245,16 @@ public class CreateChangeIT extends AbstractDaemonTest {
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
public void createChangeWithParentCommitOnWrongBranchFails() throws Exception {
Map<String, PushOneCommit.Result> setup =