CreateChange: Allow create change on new branch
We currently disallow creating a new change through CreateChange endpoint against a non-existent branch, but we don't really have a problem with that (except for preventing typos). In this change, we split ChangeInfo into ChangeInfo and ChangeInput. Added a new new_branch field in ChangeInput, default to false to protect against typos, and when it's set to true, allow new change against a non-existent branch. Currently it's only implemented in the API, but not in the UI. Change-Id: I6e661f036b121a33de183c126b763d29b5f2bc93
This commit is contained in:
committed by
Edwin Kempin
parent
d9cafb7ca2
commit
af6807f564
@@ -48,6 +48,7 @@ import com.google.gerrit.extensions.client.SubmitType;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.ApprovalInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.ChangeInput;
|
||||
import com.google.gerrit.extensions.common.ChangeMessageInfo;
|
||||
import com.google.gerrit.extensions.common.GitPerson;
|
||||
import com.google.gerrit.extensions.common.LabelInfo;
|
||||
@@ -585,7 +586,7 @@ public class ChangeIT extends AbstractDaemonTest {
|
||||
|
||||
@Test
|
||||
public void createEmptyChange() throws Exception {
|
||||
ChangeInfo in = new ChangeInfo();
|
||||
ChangeInput in = new ChangeInput();
|
||||
in.branch = Constants.MASTER;
|
||||
in.subject = "Create a change from the API";
|
||||
in.project = project.get();
|
||||
@@ -981,6 +982,39 @@ public class ChangeIT extends AbstractDaemonTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createEmptyChangeOnNonExistingBranch() throws Exception {
|
||||
ChangeInput in = new ChangeInput();
|
||||
in.branch = "foo";
|
||||
in.subject = "Create a change on new branch from the API";
|
||||
in.project = project.get();
|
||||
in.newBranch = true;
|
||||
ChangeInfo info = gApi
|
||||
.changes()
|
||||
.create(in)
|
||||
.get();
|
||||
assertThat(info.project).isEqualTo(in.project);
|
||||
assertThat(info.branch).isEqualTo(in.branch);
|
||||
assertThat(info.subject).isEqualTo(in.subject);
|
||||
assertThat(Iterables.getOnlyElement(info.messages).message)
|
||||
.isEqualTo("Uploaded patch set 1.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createEmptyChangeOnExistingBranchWithNewBranch() throws Exception {
|
||||
ChangeInput in = new ChangeInput();
|
||||
in.branch = Constants.MASTER;
|
||||
in.subject = "Create a change on new branch from the API";
|
||||
in.project = project.get();
|
||||
in.newBranch = true;
|
||||
|
||||
exception.expect(ResourceConflictException.class);
|
||||
ChangeInfo info = gApi
|
||||
.changes()
|
||||
.create(in)
|
||||
.get();
|
||||
}
|
||||
|
||||
private static Iterable<Account.Id> getReviewers(
|
||||
Collection<AccountInfo> r) {
|
||||
return Iterables.transform(r, new Function<AccountInfo, Account.Id>() {
|
||||
|
||||
Reference in New Issue
Block a user