From ad098b3b85c58fffd65b7daee03363b1e71d456c Mon Sep 17 00:00:00 2001 From: Nail Samatov Date: Fri, 21 Jan 2022 19:30:51 +0300 Subject: [PATCH] LFS: Fix error occurring during delete branch Fix TransportException occurring when deleting a branch and push that change to remote repository if BuiltinLFS is used to work with repository. When finding LFS pointers in RemoteRepUpdate, LfsPrePushHook fails to open ObjectReader with new object id equal to ObjectId.zeroId(). If update is a deleting update (new object id is zero id), we can assume that this update doesn't contain LFS Pointer and we can skip step with extracting LFS pointer for that RemoteRefUpdate. Bug: 578313 Change-Id: Ic4367978338b8234d39d9af0d9674490f79fc22d Signed-off-by: Nail Samatov --- .../org/eclipse/jgit/lfs/server/fs/PushTest.java | 16 ++++++++++++++++ .../src/org/eclipse/jgit/lfs/LfsPrePushHook.java | 3 +++ 2 files changed, 19 insertions(+) diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java index 70c0463e1..06708b334 100644 --- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java +++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/PushTest.java @@ -11,6 +11,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.InputStream; import java.nio.file.Files; @@ -29,6 +30,7 @@ import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.filter.PathFilter; @@ -128,4 +130,18 @@ public void testPushSimple() throws Exception { server.getRequests().toString()); } + @Test + public void testDeleteBranch() throws Exception { + String branch = "new-branch"; + git.branchCreate().setName(branch).call(); + + String destRef = Constants.R_HEADS + branch; + git.push().setRefSpecs(new RefSpec().setSource(branch).setDestination(destRef)).call(); + + // Should not fail on push. + git.branchDelete().setBranchNames(branch).setForce(true).call(); + git.push().setRefSpecs(new RefSpec().setSource(null).setDestination(destRef)).call(); + + assertTrue(server.getRequests().isEmpty()); + } } diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java index d6ce85579..ebf46e080 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java @@ -113,6 +113,9 @@ private Set findObjectsToPush() throws IOException, try (ObjectWalk walk = new ObjectWalk(getRepository())) { for (RemoteRefUpdate up : refs) { + if (up.isDelete()) { + continue; + } walk.setRewriteParents(false); excludeRemoteRefs(walk); walk.markStart(walk.parseCommit(up.getNewObjectId()));