summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Kempin <ekempin@google.com>2019-12-05 10:03:19 +0100
committerDavid Pursehouse <dpursehouse@collab.net>2019-12-06 09:33:39 +0900
commit65008c3b03680addad780d4e442b6819dd8caec7 (patch)
tree3e073d6ff8ffba9af27f698e034fdb788a15eb6b
parentece80db8e9d9e0c0b5d4bf2fa135a7b948c16815 (diff)
CreateBranch: Allow revision in input to be empty
If a revision in the input is not specified we default to the HEAD revision, but when the revision in the input was empty we failed with 400 Bad Request. Be more tolerant and consistent and default to the HEAD revision too if the specified revision is empty. Signed-off-by: Edwin Kempin <ekempin@google.com> Change-Id: Ibc1461b744b65dba4857b3ffa00b49bd2c96df99
-rw-r--r--java/com/google/gerrit/server/restapi/project/CreateBranch.java3
-rw-r--r--javatests/com/google/gerrit/acceptance/rest/project/CreateBranchIT.java26
2 files changed, 28 insertions, 1 deletions
diff --git a/java/com/google/gerrit/server/restapi/project/CreateBranch.java b/java/com/google/gerrit/server/restapi/project/CreateBranch.java
index 62106e8c1d..05525b5e28 100644
--- a/java/com/google/gerrit/server/restapi/project/CreateBranch.java
+++ b/java/com/google/gerrit/server/restapi/project/CreateBranch.java
@@ -16,6 +16,7 @@ package com.google.gerrit.server.restapi.project;
import static com.google.gerrit.reviewdb.client.RefNames.isConfigRef;
+import com.google.common.base.Strings;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.extensions.api.projects.BranchInfo;
import com.google.gerrit.extensions.api.projects.BranchInput;
@@ -91,7 +92,7 @@ public class CreateBranch
if (input.ref != null && !ref.equals(input.ref)) {
throw new BadRequestException("ref must match URL");
}
- if (input.revision == null) {
+ if (Strings.isNullOrEmpty(input.revision)) {
input.revision = Constants.HEAD;
}
while (ref.startsWith("/")) {
diff --git a/javatests/com/google/gerrit/acceptance/rest/project/CreateBranchIT.java b/javatests/com/google/gerrit/acceptance/rest/project/CreateBranchIT.java
index a4a87d5464..cd442e5458 100644
--- a/javatests/com/google/gerrit/acceptance/rest/project/CreateBranchIT.java
+++ b/javatests/com/google/gerrit/acceptance/rest/project/CreateBranchIT.java
@@ -147,6 +147,32 @@ public class CreateBranchIT extends AbstractDaemonTest {
}
@Test
+ public void createWithoutSpecifyingRevision() throws Exception {
+ // If revision is not specified, the branch is created based on HEAD, which points to master.
+ RevCommit expectedRevision = getRemoteHead(project, "master");
+
+ BranchInput input = new BranchInput();
+ input.revision = null;
+ BranchInfo created = branch(testBranch).create(input).get();
+ assertThat(created.ref).isEqualTo(testBranch.get());
+ assertThat(created.revision).isEqualTo(expectedRevision.name());
+ assertThat(getRemoteHead(project, testBranch.getShortName())).isEqualTo(expectedRevision);
+ }
+
+ @Test
+ public void createWithEmptyRevision() throws Exception {
+ // If revision is not specified, the branch is created based on HEAD, which points to master.
+ RevCommit expectedRevision = getRemoteHead(project, "master");
+
+ BranchInput input = new BranchInput();
+ input.revision = "";
+ BranchInfo created = branch(testBranch).create(input).get();
+ assertThat(created.ref).isEqualTo(testBranch.get());
+ assertThat(created.revision).isEqualTo(expectedRevision.name());
+ assertThat(getRemoteHead(project, testBranch.getShortName())).isEqualTo(expectedRevision);
+ }
+
+ @Test
public void createWithBranchNameAsRevision() throws Exception {
RevCommit expectedRevision = getRemoteHead(project, "master");