summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Kempin <ekempin@google.com>2019-12-05 10:56:36 +0100
committerDavid Pursehouse <dpursehouse@collab.net>2019-12-06 09:39:00 +0900
commitb56d2cb2add7720495638c8d8d3f0187ece6d098 (patch)
treedf762c1ed5afb02000b16f7b2fcf862d079ca427
parentdd07f8bcd1fe89b7247f05ce8c766536fedc799c (diff)
CreateTag: 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: I78afe991d274d0feba134612382a65c76916cfd5
-rw-r--r--java/com/google/gerrit/server/restapi/project/CreateTag.java2
-rw-r--r--javatests/com/google/gerrit/acceptance/rest/project/TagsIT.java33
2 files changed, 34 insertions, 1 deletions
diff --git a/java/com/google/gerrit/server/restapi/project/CreateTag.java b/java/com/google/gerrit/server/restapi/project/CreateTag.java
index e72deaf255..cdeba62800 100644
--- a/java/com/google/gerrit/server/restapi/project/CreateTag.java
+++ b/java/com/google/gerrit/server/restapi/project/CreateTag.java
@@ -87,7 +87,7 @@ public class CreateTag implements RestCollectionCreateView<ProjectResource, TagR
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;
}
diff --git a/javatests/com/google/gerrit/acceptance/rest/project/TagsIT.java b/javatests/com/google/gerrit/acceptance/rest/project/TagsIT.java
index d4edc0de95..8e5f361cbc 100644
--- a/javatests/com/google/gerrit/acceptance/rest/project/TagsIT.java
+++ b/javatests/com/google/gerrit/acceptance/rest/project/TagsIT.java
@@ -35,6 +35,7 @@ import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import java.sql.Timestamp;
import java.util.List;
+import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
@NoHttpd
@@ -326,6 +327,38 @@ public class TagsIT extends AbstractDaemonTest {
tag(input.ref).create(input);
}
+ @Test
+ public void noBaseRevision() throws Exception {
+ grantTagPermissions();
+
+ // If revision is not specified, the tag is created based on HEAD, which points to master.
+ RevCommit expectedRevision = getRemoteHead(project, "master");
+
+ TagInput input = new TagInput();
+ input.ref = "test";
+ input.revision = null;
+
+ TagInfo result = tag(input.ref).create(input).get();
+ assertThat(result.ref).isEqualTo(R_TAGS + input.ref);
+ assertThat(result.revision).isEqualTo(expectedRevision.name());
+ }
+
+ @Test
+ public void emptyBaseRevision() throws Exception {
+ grantTagPermissions();
+
+ // If revision is not specified, the tag is created based on HEAD, which points to master.
+ RevCommit expectedRevision = getRemoteHead(project, "master");
+
+ TagInput input = new TagInput();
+ input.ref = "test";
+ input.revision = "";
+
+ TagInfo result = tag(input.ref).create(input).get();
+ assertThat(result.ref).isEqualTo(R_TAGS + input.ref);
+ assertThat(result.revision).isEqualTo(expectedRevision.name());
+ }
+
private void assertTagList(FluentIterable<String> expected, List<TagInfo> actual)
throws Exception {
assertThat(actual).hasSize(expected.size());