CreateChange: Do not fail with NPE if parent is given and target branch does not exist

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Ib7c471dc1c541b08407a55504272b4e4c5e7c4b4
This commit is contained in:
Edwin Kempin
2019-10-08 14:26:08 +02:00
committed by David Pursehouse
parent 6ccfa30fa2
commit 05e5d34793
2 changed files with 19 additions and 0 deletions

View File

@@ -363,7 +363,12 @@ public class CreateChange
}
RevCommit parentRevCommit = revWalk.parseCommit(parentCommit);
if (destRef == null) {
throw new BadRequestException("Destination branch does not exist");
}
RevCommit destRefRevCommit = revWalk.parseCommit(destRef.getObjectId());
if (!revWalk.isMergedInto(parentRevCommit, destRefRevCommit)) {
throw new BadRequestException(
String.format("Commit %s doesn't exist on ref %s", baseCommit, inputBranch));

View File

@@ -258,6 +258,20 @@ public class CreateChangeIT extends AbstractDaemonTest {
String.format("Commit %s doesn't exist on ref refs/heads/foo", input.baseCommit));
}
@Test
public void createChangeWithParentCommitWithNonExistingTargetBranch() throws Exception {
Result initialCommit =
pushFactory
.create(user.newIdent(), testRepo, "initial commit", "readme.txt", "initial commit")
.to("refs/heads/master");
initialCommit.assertOkStatus();
ChangeInput input = newChangeInput(ChangeStatus.NEW);
input.branch = "non-existing";
input.baseCommit = initialCommit.getCommit().getName();
assertCreateFails(input, BadRequestException.class, "Destination branch does not exist");
}
@Test
public void createChangeOnNonExistingBaseChangeFails() throws Exception {
ChangeInput input = newChangeInput(ChangeStatus.NEW);