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 <sanail@yandex.ru>
This commit is contained in:
parent
27e554e465
commit
ad098b3b85
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,6 +113,9 @@ private Set<LfsPointer> 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()));
|
||||
|
|
Loading…
Reference in New Issue