From 7b254e51df2e57842487b13cf7d03b80bd737d5f Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 4 Oct 2013 16:13:59 -0700 Subject: [PATCH] Skip non-commits when verifying access for 'add branch' operation Some projects have refs pointing to a tree (e.g., the Linux kernel's "refs/tags/v2.6.11"), resulting in the message Cannot verify permissions to commit object in repository as a result of exception IncorrectObjectTypeException: Object is not a commit. at org.eclipse.jgit.revwalk.RevWalk.parseCommit(RevWalk.java:724) at com.google.gerrit.server.project.ProjectControl.canReadCommit(ProjectControl.java:496) at com.google.gerrit.server.project.RefControl.canCreate(RefControl.java:250) at com.google.gerrit.server.git.ReceiveCommits.parseCreate(ReceiveCommits.java:852) when trying to create a new branch through gerrit. Change-Id: I9be1fe5046b5db482aa8f80d02c86d3d7a973036 --- .../com/google/gerrit/server/project/ProjectControl.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/project/ProjectControl.java b/gerrit-server/src/main/java/com/google/gerrit/server/project/ProjectControl.java index 937f84362c..a50d33dbd5 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/project/ProjectControl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/project/ProjectControl.java @@ -40,6 +40,7 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.assistedinject.Assisted; +import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; @@ -468,7 +469,12 @@ public class ProjectControl { Repository repo = repoManager.openRepository(projName); try { for (Entry entry : repo.getAllRefs().entrySet()) { - RevCommit tip = rw.parseCommit(entry.getValue().getObjectId()); + RevCommit tip; + try { + tip = rw.parseCommit(entry.getValue().getObjectId()); + } catch (IncorrectObjectTypeException e) { + continue; + } if (rw.isMergedInto(commit, tip) && controlForRef(entry.getKey()).canPerform(Permission.READ)) { return true;