Merge "Add allowEmpty to CherryPickInput"
diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt
index bf81779..efc9de8 100644
--- a/Documentation/rest-api-changes.txt
+++ b/Documentation/rest-api-changes.txt
@@ -6199,6 +6199,10 @@
 the created change will have no topic.
 If the change already exists, the topic will not change if not set. If set, the
 topic will be overridden.
+|`allow_empty`      |optional, defaults to false|
+If `true`, the cherry-pick succeeds also if the created commit will be empty.
+If `false`, a cherry-pick that would create an empty commit fails without creating
+the commit.
 |===========================
 
 [[comment-info]]
diff --git a/java/com/google/gerrit/extensions/api/changes/CherryPickInput.java b/java/com/google/gerrit/extensions/api/changes/CherryPickInput.java
index 4ec6f01..69c1790 100644
--- a/java/com/google/gerrit/extensions/api/changes/CherryPickInput.java
+++ b/java/com/google/gerrit/extensions/api/changes/CherryPickInput.java
@@ -30,4 +30,5 @@
   public boolean keepReviewers;
   public boolean allowConflicts;
   public String topic;
+  public boolean allowEmpty;
 }
diff --git a/java/com/google/gerrit/server/restapi/change/CherryPickChange.java b/java/com/google/gerrit/server/restapi/change/CherryPickChange.java
index 6d9716c..0ba4905 100644
--- a/java/com/google/gerrit/server/restapi/change/CherryPickChange.java
+++ b/java/com/google/gerrit/server/restapi/change/CherryPickChange.java
@@ -170,7 +170,6 @@
         patch.commitId(),
         input,
         dest,
-        false,
         TimeUtil.nowTs(),
         null,
         null,
@@ -206,17 +205,7 @@
       throws IOException, InvalidChangeOperationException, UpdateException, RestApiException,
           ConfigInvalidException, NoSuchProjectException {
     return cherryPick(
-        sourceChange,
-        project,
-        sourceCommit,
-        input,
-        dest,
-        false,
-        TimeUtil.nowTs(),
-        null,
-        null,
-        null,
-        null);
+        sourceChange, project, sourceCommit, input, dest, TimeUtil.nowTs(), null, null, null, null);
   }
 
   /**
@@ -230,8 +219,6 @@
    * @param sourceCommit Id of the commit to be cherry picked.
    * @param input Input object for different configurations of cherry pick.
    * @param dest Destination branch for the cherry pick.
-   * @param ignoreIdenticalTree When false, we throw an error when trying to cherry-pick creates an
-   *     empty commit. When true, we allow creation of an empty commit.
    * @param timestamp the current timestamp.
    * @param revertedChange The id of the change that is reverted. This is used for the "revertOf"
    *     field to mark the created cherry pick change as "revertOf" the original change that was
@@ -258,7 +245,6 @@
       ObjectId sourceCommit,
       CherryPickInput input,
       BranchNameKey dest,
-      boolean ignoreIdenticalTree,
       Timestamp timestamp,
       @Nullable Change.Id revertedChange,
       @Nullable ObjectId changeIdForNewChange,
@@ -326,7 +312,7 @@
                 commitMessage,
                 revWalk,
                 input.parent - 1,
-                ignoreIdenticalTree,
+                input.allowEmpty,
                 input.allowConflicts);
 
         Change.Key changeKey;
diff --git a/java/com/google/gerrit/server/restapi/change/RevertSubmission.java b/java/com/google/gerrit/server/restapi/change/RevertSubmission.java
index e7da89a..aa5f654 100644
--- a/java/com/google/gerrit/server/restapi/change/RevertSubmission.java
+++ b/java/com/google/gerrit/server/restapi/change/RevertSubmission.java
@@ -356,6 +356,7 @@
     cherryPickInput.parent = 1;
     cherryPickInput.keepReviewers = true;
     cherryPickInput.topic = revertInput.topic;
+    cherryPickInput.allowEmpty = true;
     return cherryPickInput;
   }
 
@@ -599,7 +600,6 @@
               cherryPickInput,
               BranchNameKey.create(
                   change.getProject(), RefNames.fullName(cherryPickInput.destination)),
-              true,
               timestamp,
               change.getId(),
               computedChangeId,
diff --git a/javatests/com/google/gerrit/acceptance/api/revision/RevisionIT.java b/javatests/com/google/gerrit/acceptance/api/revision/RevisionIT.java
index dc64667..17391de 100644
--- a/javatests/com/google/gerrit/acceptance/api/revision/RevisionIT.java
+++ b/javatests/com/google/gerrit/acceptance/api/revision/RevisionIT.java
@@ -542,6 +542,14 @@
             ResourceConflictException.class,
             () -> orig.revision(r.getCommit().name()).cherryPick(in));
     assertThat(thrown).hasMessageThat().contains("Cherry pick failed: identical tree");
+
+    in.allowEmpty = true;
+    ChangeInfo cherryPickChange = orig.revision(r.getCommit().name()).cherryPick(in).get();
+    assertThat(cherryPickChange.cherryPickOfChange).isEqualTo(r.getChange().change().getChangeId());
+
+    // An empty commit is created
+    assertThat(cherryPickChange.insertions).isEqualTo(0);
+    assertThat(cherryPickChange.deletions).isEqualTo(0);
   }
 
   @Test