Fix updating an existing edit via push

It should be possible to update an existing edit via push [1], but
attempting to so (checkout the edit, amend the commit and then push the
edit) fails because updating the edit ref with non-fastword is rejected.

By setting the type to UPDATE_NONFASTFORWARD when creating the
ReceiveCommand for the edit ref update we allow non-fastforwards (see
NoteDbUpdateExecutor#allowNonFastForwards).

[1] https://gerrit-review.googlesource.com/Documentation/user-upload.html#:~:text=When%20a%20change%20edit%20already%20exists%20for%20a%20change%20then%20pushing%20with%20%25edit%20replaces%20the%20existing%20change%20edit.%20This%20option%20is%20useful%20to%20rebase%20a%20change%20edit%20on%20the%20newest%20patch%20set%20when%20the%20rebase%20of%20the%20change%20edit%20in%20the%20web%20UI%20fails%20due%20to%20conflicts.

Release-Notes: Fixed updating an existing edit via push
Bugs: Google b/332704794
Change-Id: Ia609a3c4ef8f949981644f2b36775e962359de48
Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/java/com/google/gerrit/server/git/receive/ReceiveCommits.java b/java/com/google/gerrit/server/git/receive/ReceiveCommits.java
index a5e20c6..68061bd 100644
--- a/java/com/google/gerrit/server/git/receive/ReceiveCommits.java
+++ b/java/com/google/gerrit/server/git/receive/ReceiveCommits.java
@@ -3192,7 +3192,10 @@
             // replace edit
             cmd =
                 new ReceiveCommand(
-                    edit.get().getEditCommit(), newCommitId, edit.get().getRefName());
+                    edit.get().getEditCommit(),
+                    newCommitId,
+                    edit.get().getRefName(),
+                    ReceiveCommand.Type.UPDATE_NONFASTFORWARD);
           } else {
             // delete old edit ref on rebase
             prev =
diff --git a/javatests/com/google/gerrit/acceptance/git/AbstractPushForReview.java b/javatests/com/google/gerrit/acceptance/git/AbstractPushForReview.java
index 8861a9e..aa96d1b 100644
--- a/javatests/com/google/gerrit/acceptance/git/AbstractPushForReview.java
+++ b/javatests/com/google/gerrit/acceptance/git/AbstractPushForReview.java
@@ -1028,6 +1028,19 @@
 
     // verify that the re-indexing was triggered for the change
     assertThat(query("has:edit")).hasSize(1);
+
+    // update the existing edit
+    r = amendChange(r.getChangeId(), "refs/for/master%edit");
+    r.assertOkStatus();
+    r.assertMessage(
+        canonicalWebUrl.get()
+            + "c/"
+            + project.get()
+            + "/+/"
+            + r.getChange().getId()
+            + " "
+            + editInfo.commit.subject
+            + " [EDIT]\n");
   }
 
   @Test