protected @Override Void _call() { getProgressListener().started(); Optional<Ref> origHead = command(RefParse.class).setName(Ref.ORIG_HEAD).call(); Preconditions.checkState(origHead.isPresent(), "Cannot abort. You are not in the middle of a revert process."); // Revert can only be run in a conflicted situation if the abort option is used final boolean hasConflicts = conflictsDatabase().hasConflicts(null); if (hasConflicts) { log.debug("Aborting revert op, will reset conflicts too"); } final ObjectId commitId = origHead.get().getObjectId(); command(ResetOp.class).setMode(ResetMode.HARD).setCommit(commitId).call(); command(UpdateRef.class).setDelete(true).setName(Ref.ORIG_HEAD).call(); getProgressListener().complete(); return null; } }
public TestData resetHard(ObjectId id) { getContext().command(ResetOp.class).setCommit(id).setMode(ResetMode.HARD).call(); return this; }
@Test public void testResetMerge() throws Exception { ObjectId oId1 = insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); assertEquals(oId1, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); ObjectId oId1_modified = insertAndAdd(points1_modified); ObjectId oId2 = insertAndAdd(points2); ObjectId oId3 = insertAndAdd(points3); assertEquals(oId1_modified, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); assertEquals(oId2, repo.index().findStaged(appendChild(pointsName, idP2)).get().getObjectId()); assertEquals(oId3, repo.index().findStaged(appendChild(pointsName, idP3)).get().getObjectId()); exception.expect(UnsupportedOperationException.class); geogig.command(ResetOp.class).setMode(ResetMode.MERGE).call(); }
@Test public void testResetMerge() throws Exception { ObjectId oId1 = insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); assertEquals(oId1, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); ObjectId oId1_modified = insertAndAdd(points1_modified); ObjectId oId2 = insertAndAdd(points2); ObjectId oId3 = insertAndAdd(points3); assertEquals(oId1_modified, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); assertEquals(oId2, repo.index().findStaged(appendChild(pointsName, idP2)).get().getObjectId()); assertEquals(oId3, repo.index().findStaged(appendChild(pointsName, idP3)).get().getObjectId()); exception.expect(UnsupportedOperationException.class); geogig.command(ResetOp.class).setMode(ResetMode.MERGE).call(); }
@SuppressWarnings(value = { "unused" }) @Test public void testRemovalOfAllFeaturesOfAGivenType() throws Exception { List<RevCommit> commits = populate(false, points1, points2, points3, lines1, lines2); String featureId = lines1.getIdentifier().getID(); String path = NodeRef.appendChild(linesName, featureId); String featureId2 = lines2.getIdentifier().getID(); String path2 = NodeRef.appendChild(linesName, featureId2); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(path) .addPathToRemove(path2).call(); assertEquals(2, result.getFeaturesRemoved()); assertEquals(0, result.getTreesRemoved()); RevCommit commit = geogig.command(CommitOp.class).setMessage("Removed lines").call(); Iterator<NodeRef> nodes = geogig.command(LsTreeOp.class).call(); while (nodes.hasNext()) { NodeRef node = nodes.next(); assertNotNull(node); } geogig.command(ResetOp.class).setMode(ResetMode.HARD).call(); nodes = geogig.command(LsTreeOp.class).call(); while (nodes.hasNext()) { NodeRef node = nodes.next(); assertNotNull(node); } }
@SuppressWarnings(value = { "unused" }) @Test public void testRemovalOfAllFeaturesOfAGivenType() throws Exception { List<RevCommit> commits = populate(false, points1, points2, points3, lines1, lines2); String featureId = lines1.getIdentifier().getID(); String path = NodeRef.appendChild(linesName, featureId); String featureId2 = lines2.getIdentifier().getID(); String path2 = NodeRef.appendChild(linesName, featureId2); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(path) .addPathToRemove(path2).call(); assertEquals(2, result.getFeaturesRemoved()); assertEquals(0, result.getTreesRemoved()); RevCommit commit = geogig.command(CommitOp.class).setMessage("Removed lines").call(); Iterator<NodeRef> nodes = geogig.command(LsTreeOp.class).call(); while (nodes.hasNext()) { NodeRef node = nodes.next(); assertNotNull(node); } geogig.command(ResetOp.class).setMode(ResetMode.HARD).call(); nodes = geogig.command(LsTreeOp.class).call(); while (nodes.hasNext()) { NodeRef node = nodes.next(); assertNotNull(node); } }
@Test public void testResetKeep() throws Exception { ObjectId oId1 = insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); assertEquals(oId1, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); ObjectId oId1_modified = insertAndAdd(points1_modified); ObjectId oId2 = insertAndAdd(points2); ObjectId oId3 = insertAndAdd(points3); assertEquals(oId1_modified, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); assertEquals(oId2, repo.index().findStaged(appendChild(pointsName, idP2)).get().getObjectId()); assertEquals(oId3, repo.index().findStaged(appendChild(pointsName, idP3)).get().getObjectId()); exception.expect(UnsupportedOperationException.class); geogig.command(ResetOp.class).setCommit((ObjectId) null).setMode(ResetMode.KEEP).call(); }
@Test public void testResetModePlusPatterns() throws Exception { ObjectId oId1 = insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); assertEquals(oId1, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); ObjectId oId1_modified = insertAndAdd(points1_modified); ObjectId oId2 = insertAndAdd(points2); ObjectId oId3 = insertAndAdd(points3); assertEquals(oId1_modified, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); assertEquals(oId2, repo.index().findStaged(appendChild(pointsName, idP2)).get().getObjectId()); assertEquals(oId3, repo.index().findStaged(appendChild(pointsName, idP3)).get().getObjectId()); exception.expect(IllegalArgumentException.class); geogig.command(ResetOp.class).addPattern(pointsName).setMode(ResetMode.SOFT).call(); }
@Test public void testResetModePlusPatterns() throws Exception { ObjectId oId1 = insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); assertEquals(oId1, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); ObjectId oId1_modified = insertAndAdd(points1_modified); ObjectId oId2 = insertAndAdd(points2); ObjectId oId3 = insertAndAdd(points3); assertEquals(oId1_modified, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); assertEquals(oId2, repo.index().findStaged(appendChild(pointsName, idP2)).get().getObjectId()); assertEquals(oId3, repo.index().findStaged(appendChild(pointsName, idP3)).get().getObjectId()); exception.expect(IllegalArgumentException.class); geogig.command(ResetOp.class).addPattern(pointsName).setMode(ResetMode.SOFT).call(); }
@Test public void testResetKeep() throws Exception { ObjectId oId1 = insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); assertEquals(oId1, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); ObjectId oId1_modified = insertAndAdd(points1_modified); ObjectId oId2 = insertAndAdd(points2); ObjectId oId3 = insertAndAdd(points3); assertEquals(oId1_modified, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); assertEquals(oId2, repo.index().findStaged(appendChild(pointsName, idP2)).get().getObjectId()); assertEquals(oId3, repo.index().findStaged(appendChild(pointsName, idP3)).get().getObjectId()); exception.expect(UnsupportedOperationException.class); geogig.command(ResetOp.class).setCommit(null).setMode(ResetMode.KEEP).call(); }
@Test public void testResetHard() throws Exception { ObjectId oId1 = insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); assertEquals(oId1, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); ObjectId oId1_modified = insertAndAdd(points1_modified); ObjectId oId2 = insertAndAdd(points2); ObjectId oId3 = insertAndAdd(points3); assertEquals(oId1_modified, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); assertEquals(oId2, repo.index().findStaged(appendChild(pointsName, idP2)).get().getObjectId()); assertEquals(oId3, repo.index().findStaged(appendChild(pointsName, idP3)).get().getObjectId()); geogig.command(ResetOp.class).setMode(ResetMode.HARD).call(); assertEquals(oId1, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); assertFalse(repo.index().findStaged(appendChild(pointsName, idP2)).isPresent()); assertFalse(repo.index().findStaged(appendChild(pointsName, idP3)).isPresent()); assertEquals(oId1, repo.workingTree().findUnstaged(appendChild(pointsName, idP1)).get().getObjectId()); assertFalse(repo.workingTree().findUnstaged(appendChild(pointsName, idP2)).isPresent()); assertFalse(repo.workingTree().findUnstaged(appendChild(pointsName, idP3)).isPresent()); }
@Test public void testResetHard() throws Exception { ObjectId oId1 = insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); assertEquals(oId1, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); ObjectId oId1_modified = insertAndAdd(points1_modified); ObjectId oId2 = insertAndAdd(points2); ObjectId oId3 = insertAndAdd(points3); assertEquals(oId1_modified, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); assertEquals(oId2, repo.index().findStaged(appendChild(pointsName, idP2)).get().getObjectId()); assertEquals(oId3, repo.index().findStaged(appendChild(pointsName, idP3)).get().getObjectId()); geogig.command(ResetOp.class).setMode(ResetMode.HARD).call(); assertEquals(oId1, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); assertFalse(repo.index().findStaged(appendChild(pointsName, idP2)).isPresent()); assertFalse(repo.index().findStaged(appendChild(pointsName, idP3)).isPresent()); assertEquals(oId1, repo.workingTree().findUnstaged(appendChild(pointsName, idP1)).get().getObjectId()); assertFalse(repo.workingTree().findUnstaged(appendChild(pointsName, idP2)).isPresent()); assertFalse(repo.workingTree().findUnstaged(appendChild(pointsName, idP3)).isPresent()); }
.setMode(ResetMode.SOFT).call();
.setMode(ResetMode.SOFT).call();
geogig.command(ResetOp.class).setMode(ResetMode.HARD) .setCommit(Suppliers.ofInstance(resetCommit.getId())).call(); Repository repository = geogig.getRepository();
geogig.command(ResetOp.class).setMode(ResetMode.HARD) .setCommit(Suppliers.ofInstance(resetCommit.getId())).call(); Repository repository = geogig.getRepository();
public @Test void healthCheckWithConflicts() { // fake PRPrepareOp fakeUpToDate(); TestData.point1_modified.setAttribute("sp", "changed on pr target repo"); origin.checkout("master").insert(TestData.point1_modified).add().commit("ci for conflict"); GeogigTransaction tx = request.getTransaction(origin.getRepo().context()); tx.command(UpdateRef.class).setName("refs/heads/" + request.getTargetBranch()) .setNewValue(origin.getRef(request.getTargetBranch()).getObjectId()); tx.command(CheckoutOp.class).setSource(request.getTargetBranch()).call(); tx.command(ResetOp.class).setCommit(origin.getRef(request.getTargetBranch()).getObjectId()) .setMode(ResetMode.HARD).call(); ObjectId localRemoteCommit = clone.getRef(request.getRemoteBranch()).getObjectId(); try { tx.command(MergeOp.class).addCommit(localRemoteCommit).call(); fail("Expected MergeConflictsException"); } catch (MergeConflictsException expected) { // } PRStatus status = origin.getRepo().command(PRHealthCheckOp.class).setId(request.getId()) .call(); assertNotNull(status); assertEquals(request, status.getRequest()); assertEquals(Sets.newHashSet("Lines", "Points", "Polygons"), Sets.newHashSet(status.getAffectedLayers())); Optional<ObjectId> mergeCommit = status.getMergeCommit(); assertFalse(mergeCommit.toString(), mergeCommit.isPresent()); assertEquals(0, status.getCommitsBehindRemoteBranch()); assertEquals(1, status.getCommitsBehindTargetBranch()); assertEquals(1, status.getNumConflicts()); }
public @Test void healthCheckTestMergeDoneButOutDated() { // fake PRPrepareOp fakeUpToDate(); GeogigTransaction tx = request.getTransaction(origin.getRepo().context()); tx.command(UpdateRef.class).setName("refs/heads/" + request.getTargetBranch()) .setNewValue(origin.getRef(request.getTargetBranch()).getObjectId()); tx.command(CheckoutOp.class).setSource(request.getTargetBranch()).call(); tx.command(ResetOp.class).setCommit(origin.getRef(request.getTargetBranch()).getObjectId()) .setMode(ResetMode.HARD).call(); ObjectId localRemoteCommit = clone.getRef(request.getRemoteBranch()).getObjectId(); RevCommit merge = tx.command(MergeOp.class).addCommit(localRemoteCommit).call() .getMergeCommit(); tx.command(UpdateRef.class).setName(request.getMergeRef()).setNewValue(merge.getId()) .call(); origin.checkout("master").insert(TestData.line2).add().commit("ahead commit"); PRStatus status = origin.getRepo().command(PRHealthCheckOp.class).setId(request.getId()) .call(); assertNotNull(status); assertEquals(request, status.getRequest()); assertEquals(Sets.newHashSet("Lines", "Points", "Polygons"), Sets.newHashSet(status.getAffectedLayers())); Optional<ObjectId> mergeCommit = status.getMergeCommit(); assertTrue(mergeCommit.toString(), mergeCommit.isPresent()); assertEquals(0, status.getCommitsBehindRemoteBranch()); assertEquals(1, status.getCommitsBehindTargetBranch()); assertEquals(0, status.getNumConflicts()); }