try { for (int i = 0; args != null && i < args.size(); i++) { reset.addPattern(args.get(i)); .setRefSpec(commit.get(0)).call(); checkParameter(commitId.isPresent(), "Commit could not be resolved."); reset.setCommit(Suppliers.ofInstance(commitId.get())); reset.setMode(mode); reset.call(); } catch (IllegalArgumentException iae) { throw new InvalidParameterException(iae.getMessage(), iae);
final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call(); Preconditions.checkArgument(currHead.isPresent(), "Repository has no HEAD, can't reset."); Preconditions.checkState(currHead.get() instanceof SymRef, Repository repository = repository(); RevCommit oldCommit = repository.getCommit(commit.get()); DiffTree diffOp = command(DiffTree.class) .setOldTree(repository.index().getTree().getId()) .setNewTree(oldCommit.getTreeId()).setPathFilter(pattern); conflictsDatabase().removeConflict(null, pattern); } else { repository.index().stage(subProgress((1.f / patterns.size()) * 100.f), diff, numChanges); stagingArea().updateStageHead(oldCommit.getTreeId()); workingTree().updateWorkHead(oldCommit.getTreeId()); break; case SOFT: stagingArea().updateStageHead(oldCommit.getTreeId()); break; default: command(UpdateRef.class).setName(currentBranch).setNewValue(oldCommit.getId()).call(); command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(currentBranch).call(); conflictsDatabase().removeConflicts(null);
@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(); }
Preconditions.checkState(origHead.isPresent() && branch.isPresent(), "Cannot abort. You are not in the middle of a rebase process."); command(ResetOp.class).setMode(ResetMode.HARD) .setCommit(Suppliers.ofInstance(origHead.get().getObjectId())).call(); command(UpdateRef.class).setDelete(true).setName(Ref.ORIG_HEAD).call(); return true; command(ResetOp.class).setCommit(Suppliers.ofInstance(rebaseHead)) .setMode(ResetMode.HARD).setClean(false).call(); if (squashCommit == null) { skipCurrentCommit(); command(ResetOp.class).setCommit(Suppliers.ofInstance(rebaseHead)) .setMode(ResetMode.HARD).setClean(false).call();
@Test public void testResetSingle() 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).addPattern(appendChild(pointsName, idP2)).call(); assertEquals(oId1_modified, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); assertFalse(repo.index().findStaged(appendChild(pointsName, idP2)).isPresent()); assertTrue(repo.index().findStaged(appendChild(pointsName, idP3)).isPresent()); assertEquals(oId1_modified, repo.workingTree().findUnstaged(appendChild(pointsName, idP1)).get().getObjectId()); assertEquals(oId2, repo.workingTree().findUnstaged(appendChild(pointsName, idP2)).get().getObjectId()); assertEquals(oId3, repo.workingTree().findUnstaged(appendChild(pointsName, idP3)).get().getObjectId()); }
@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 testResetPathFixesConflict() throws Exception { Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)"); Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)"); insertAndAdd(points1); RevCommit resetCommit = geogig.command(CommitOp.class).call(); geogig.command(BranchCreateOp.class).setName("TestBranch").call(); insertAndAdd(points1Modified); geogig.command(CommitOp.class).call(); geogig.command(CheckoutOp.class).setSource("TestBranch").call(); insertAndAdd(points1ModifiedB); insertAndAdd(points2); geogig.command(CommitOp.class).call(); geogig.command(CheckoutOp.class).setSource("master").call(); Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get(); try { geogig.command(MergeOp.class).addCommit(branch.getObjectId()).call(); fail(); } catch (MergeConflictsException e) { assertTrue(e.getMessage().contains("conflict")); } geogig.command(ResetOp.class).addPattern(pointsName + "/" + idP1) .setCommit(Suppliers.ofInstance(resetCommit.getId())).call(); Repository repository = geogig.getRepository(); ConflictsDatabase conflicts = repository.conflictsDatabase(); assertEquals(0, conflicts.getCountByPrefix(null, null)); }
@Test public void testResetNoCommits() throws Exception { exception.expect(IllegalArgumentException.class); geogig.command(ResetOp.class).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); } }
Preconditions.checkState(origHead.isPresent() && branch.isPresent(), "Cannot abort. You are not in the middle of a rebase process."); command(ResetOp.class).setMode(ResetMode.HARD) .setCommit(Suppliers.ofInstance(origHead.get().getObjectId())).call(); command(UpdateRef.class).setDelete(true).setName(Ref.ORIG_HEAD).call(); return true; command(ResetOp.class).setCommit(Suppliers.ofInstance(rebaseHead)) .setMode(ResetMode.HARD).setClean(false).call(); if (squashCommit == null) { skipCurrentCommit(); command(ResetOp.class).setCommit(Suppliers.ofInstance(rebaseHead)) .setMode(ResetMode.HARD).setClean(false).call();
@Test public void testResetSingle() 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).addPattern(appendChild(pointsName, idP2)).call(); assertEquals(oId1_modified, repo.index().findStaged(appendChild(pointsName, idP1)).get().getObjectId()); assertFalse(repo.index().findStaged(appendChild(pointsName, idP2)).isPresent()); assertTrue(repo.index().findStaged(appendChild(pointsName, idP3)).isPresent()); assertEquals(oId1_modified, repo.workingTree().findUnstaged(appendChild(pointsName, idP1)).get().getObjectId()); assertEquals(oId2, repo.workingTree().findUnstaged(appendChild(pointsName, idP2)).get().getObjectId()); assertEquals(oId3, repo.workingTree().findUnstaged(appendChild(pointsName, idP3)).get().getObjectId()); }
@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 testResetPathFixesConflict() throws Exception { Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)"); Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)"); insertAndAdd(points1); RevCommit resetCommit = geogig.command(CommitOp.class).call(); geogig.command(BranchCreateOp.class).setName("TestBranch").call(); insertAndAdd(points1Modified); geogig.command(CommitOp.class).call(); geogig.command(CheckoutOp.class).setSource("TestBranch").call(); insertAndAdd(points1ModifiedB); insertAndAdd(points2); geogig.command(CommitOp.class).call(); geogig.command(CheckoutOp.class).setSource("master").call(); Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get(); try { geogig.command(MergeOp.class).addCommit(branch.getObjectId()).call(); fail(); } catch (MergeConflictsException e) { assertTrue(e.getMessage().contains("conflict")); } geogig.command(ResetOp.class).addPattern(pointsName + "/" + idP1) .setCommit(Suppliers.ofInstance(resetCommit.getId())).call(); Repository repository = geogig.getRepository(); ConflictsDatabase conflicts = repository.conflictsDatabase(); assertEquals(0, conflicts.getCountByPrefix(null, null)); }
@Test public void testResetNoCommits() throws Exception { exception.expect(IllegalArgumentException.class); geogig.command(ResetOp.class).call(); }
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; } }
try { for (int i = 0; args != null && i < args.size(); i++) { reset.addPattern(args.get(i)); .setRefSpec(commit.get(0)).call(); checkParameter(commitId.isPresent(), "Commit could not be resolved."); reset.setCommit(Suppliers.ofInstance(commitId.get())); reset.setMode(mode); reset.call(); } catch (IllegalArgumentException iae) { throw new InvalidParameterException(iae.getMessage(), iae);
@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(); }
repo.index().findStaged(appendChild(linesName, idL1)).get().getObjectId()); geogig.command(ResetOp.class).addPattern(pointsName).call();
@Test public void testResetAllMixed() 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).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_modified, repo.workingTree().findUnstaged(appendChild(pointsName, idP1)).get().getObjectId()); assertEquals(oId2, repo.workingTree().findUnstaged(appendChild(pointsName, idP2)).get().getObjectId()); assertEquals(oId3, repo.workingTree().findUnstaged(appendChild(pointsName, idP3)).get().getObjectId()); }