Patch toReject = verify.getToReject(); Patch toApply = verify.getToApply(); if (toReject.isEmpty()) { console.println("Patch can be applied."); } else {
Patch toReject = verify.getToReject(); Patch toApply = verify.getToApply(); if (toReject.isEmpty()) { console.println("Patch can be applied."); } else {
Patch toReject = verify.getToReject(); Patch toApply = verify.getToApply(); if (toReject.isEmpty()) { console.println("Patch can be applied."); } else {
/** * Executes the apply command, applying the given patch If it cannot be applied and no partial * application is allowed, a {@link CannotApplyPatchException} exception is thrown. Returns a * patch with rejected entries, in case partial application is allowed * * @return the modified {@link WorkingTree working tree}. */ @Override protected Patch _call() throws RuntimeException { Preconditions.checkArgument(patch != null, "No patch file provided"); VerifyPatchResults verify = command(VerifyPatchOp.class).setPatch(patch).setReverse(reverse) .call(); Patch toReject = verify.getToReject(); Patch toApply = verify.getToApply(); if (!applyPartial) { if (!toReject.isEmpty()) { throw new CannotApplyPatchException(toReject); } applyPatch(toApply); return null; } else { applyPatch(toApply); return toReject; } }
/** * Executes the apply command, applying the given patch If it cannot be applied and no partial * application is allowed, a {@link CannotApplyPatchException} exception is thrown. Returns a * patch with rejected entries, in case partial application is allowed * * @return the modified {@link WorkingTree working tree}. */ @Override protected Patch _call() throws RuntimeException { Preconditions.checkArgument(patch != null, "No patch file provided"); VerifyPatchResults verify = command(VerifyPatchOp.class).setPatch(patch).setReverse(reverse) .call(); Patch toReject = verify.getToReject(); Patch toApply = verify.getToApply(); if (!applyPartial) { if (!toReject.isEmpty()) { throw new CannotApplyPatchException(toReject); } applyPatch(toApply); return null; } else { applyPatch(toApply); return toReject; } }
@Test public void testPartialApplication() throws Exception { insert(points1, points2); Patch patch = new Patch(); String pathRemove = NodeRef.appendChild(pointsName, points2.getIdentifier().getID()); patch.addRemovedFeature(pathRemove, RevFeatureBuilder.build(points2), RevFeatureTypeBuilder.build(pointsType)); String pathModify = NodeRef.appendChild(pointsName, points1B.getIdentifier().getID()); Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap(); Object oldValue = points1B.getProperty("extra").getValue(); GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, null); map.put(modifiedPointsType.getDescriptor("extra"), diff); FeatureDiff featureDiff = new FeatureDiff(pathModify, map, RevFeatureTypeBuilder.build(modifiedPointsType), RevFeatureTypeBuilder.build(pointsType)); patch.addModifiedFeature(featureDiff); Patch rejected = geogig.command(ApplyPatchOp.class).setPatch(patch).setApplyPartial(true) .call(); assertFalse(rejected.isEmpty()); RevTree root = repo.workingTree().getTree(); assertNotNull(root); Optional<Node> featureBlobId = findTreeChild(root, pathRemove); assertFalse(featureBlobId.isPresent()); // now we take the rejected patch and apply it, and the new rejected should be identical to // it Patch newRejected = geogig.command(ApplyPatchOp.class).setPatch(rejected) .setApplyPartial(true).call(); assertEquals(rejected, newRejected); }
@Test public void testPartialApplication() throws Exception { insert(points1, points2); Patch patch = new Patch(); String pathRemove = NodeRef.appendChild(pointsName, points2.getIdentifier().getID()); patch.addRemovedFeature(pathRemove, RevFeature.builder().build(points2), RevFeatureType.builder().type(pointsType).build()); String pathModify = NodeRef.appendChild(pointsName, points1B.getIdentifier().getID()); Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap(); Object oldValue = points1B.getProperty("extra").getValue(); GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, null); map.put(modifiedPointsType.getDescriptor("extra"), diff); FeatureDiff featureDiff = new FeatureDiff(pathModify, map, RevFeatureType.builder().type(modifiedPointsType).build(), RevFeatureType.builder().type(pointsType).build()); patch.addModifiedFeature(featureDiff); Patch rejected = geogig.command(ApplyPatchOp.class).setPatch(patch).setApplyPartial(true) .call(); assertFalse(rejected.isEmpty()); RevTree root = repo.workingTree().getTree(); assertNotNull(root); Optional<Node> featureBlobId = findTreeChild(root, pathRemove); assertFalse(featureBlobId.isPresent()); // now we take the rejected patch and apply it, and the new rejected should be identical to // it Patch newRejected = geogig.command(ApplyPatchOp.class).setPatch(rejected) .setApplyPartial(true).call(); assertEquals(rejected, newRejected); }