Fix MissingObjectException when checking for non-ff update
If the ref was deleted, attempting to check for non-ff update
will cause an exception.
Change-Id: Id0d8b3a0980feee32f06bf499022f3b61a8bc7bd
diff --git a/src/main/java/com/googlesource/gerrit/plugins/refprotection/RefUpdateListener.java b/src/main/java/com/googlesource/gerrit/plugins/refprotection/RefUpdateListener.java
index 6484b38..714b2c6 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/refprotection/RefUpdateListener.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/refprotection/RefUpdateListener.java
@@ -127,6 +127,11 @@
*/
private boolean isNonFastForwardUpdate(Event event, ProjectResource project)
throws RepositoryNotFoundException, IOException {
+ if (isRefDeleted(event)) {
+ // Can't be non-fast-forward if the ref was deleted, and
+ // attempting a check would cause a MissingObjectException.
+ return false;
+ }
try (Repository repo = repoManager.openRepository(project.getNameKey())) {
try (RevWalk walk = new RevWalk(repo)) {
RevCommit oldCommit =