checkParameter(commitId.isPresent(), "Couldn't resolve '" + st + "' to a commit, aborting revert."); revert.addCommit(Suppliers.ofInstance(commitId.get())); revert.setCreateCommit(!noCommit).setAbort(abort).setContinue(continueRevert).call(); } catch (RevertConflictsException e) { StringBuilder sb = new StringBuilder();
command(RevertAbort.class).setProgressListener(getProgressListener()).call(); return true; final Optional<Ref> head = command(RefParse.class).setName(Ref.HEAD).call(); checkState(head.isPresent(), "Repository has no HEAD, can't revert."); currHead = head.get(); getProgressListener().started(); final boolean hasConflicts = conflictsDatabase().hasConflicts(null); checkState(!hasConflicts || abort, "Cannot run operation while merge conflicts exist."); Optional<Ref> ref = command(RefParse.class).setName(Ref.ORIG_HEAD).call(); if (continueRevert) { checkState(ref.isPresent(), applyNextCommit(false); checkState(stagingArea().isClean() && workingTree().isClean(), "You must have a clean working tree and index to perform a revert."); getProgressListener().started(); command(UpdateRef.class).setName(Ref.ORIG_HEAD).setNewValue(currHead.getObjectId()) .call(); Repository repository = repository(); List<RevCommit> commitsToRevert = commits.stream().map(c -> repository.getCommit(c)) .collect(Collectors.toList());
private boolean applyNextCommit(boolean useCommitChanges) { Repository repository = repository(); List<String> nextFile = readLines(context().blobStore(), NEXT); List<String> commitFile = readLines(context().blobStore(), commitBlobName); if (commitFile.isEmpty()) { return false; List<Conflict> conflicts = Lists.newArrayList(); if (useCommitChanges) { conflicts = applyRevertedChanges(commit); createCommit(commit); } else { workingTree().updateWorkHead(repository.index().getTree().getId()); if (!conflicts.isEmpty()) { command(ConflictsWriteOp.class).setConflicts(conflicts).call(); context().blobStore().removeBlob(commitBlobName); int newIdx = Integer.parseInt(idx) + 1; putBlob(context().blobStore(), NEXT, Integer.toString(newIdx)); return true;
@Test public void testRevertToWrongCommit() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); exception.expect(IllegalArgumentException.class); geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(RevObjectTestSupport.hashString("wrong"))) .call(); }
.setMessage("commit for modified " + idP1 + " again").call(); try { geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c2.getId())).call(); fail(); } catch (RevertConflictsException e) { assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1).getId()); geogig.command(RevertOp.class).setAbort(true).call();
geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c2.getId())) .addCommit(Suppliers.ofInstance(c3.getId())) .addCommit(Suppliers.ofInstance(c5.getId())).setCreateCommit(false).call();
.setMessage("commit for modified " + idP1 + " again").call(); try { geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c2.getId())).call(); fail(); } catch (RevertConflictsException e) { geogig.command(RevertOp.class).setContinue(true).call();
/** * Adds a commit to revert. * * @param onto a supplier for the commit id * @return {@code this} */ public RevertOp addCommit(final Supplier<ObjectId> commit) { return addCommit(commit.get()); }
@Test public void testHeadWithNoHistory() throws Exception { exception.expect(IllegalStateException.class); geogig.command(RevertOp.class).call(); }
@Test public void testUncleanIndex() throws Exception { insertAndAdd(points1); RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); insertAndAdd(points2); exception.expect(IllegalStateException.class); geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c1.getId())).call(); }
.setMessage("commit for modified " + idP1 + " again").call(); try { geogig.command(RevertOp.class).addCommit(c2.getId()).call(); fail(); } catch (RevertConflictsException e) { assertEquals(conflicts.get(0).getTheirs(), RevFeature.builder().build(points1).getId()); geogig.command(RevertOp.class).setAbort(true).call();
geogig.command(RevertOp.class).addCommit(c2.getId()).addCommit(c3.getId()) .addCommit(c5.getId()).setCreateCommit(false).call();
.setMessage("commit for modified " + idP1 + " again").call(); try { geogig.command(RevertOp.class).addCommit(c2.getId()).call(); fail(); } catch (RevertConflictsException e) { geogig.command(RevertOp.class).setContinue(true).call();
@Test public void testHeadWithNoHistory() throws Exception { exception.expect(IllegalStateException.class); geogig.command(RevertOp.class).call(); }
checkParameter(commitId.isPresent(), "Couldn't resolve '" + st + "' to a commit, aborting revert."); revert.addCommit(Suppliers.ofInstance(commitId.get())); revert.setCreateCommit(!noCommit).setAbort(abort).setContinue(continueRevert).call(); } catch (RevertConflictsException e) { StringBuilder sb = new StringBuilder();
@Test public void testUncleanWorkingTree() throws Exception { insertAndAdd(points1); RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); insert(points2); exception.expect(IllegalStateException.class); geogig.command(RevertOp.class).addCommit(Suppliers.ofInstance(c1.getId())).call(); }
final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call(); Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't revert."); Preconditions.checkState(currHead.get() instanceof SymRef, final boolean indexClean = stagingArea().isClean(); final boolean workTreeClean = workingTree().isClean(); Preconditions.checkState((indexClean && workTreeClean) || abort || continueRevert, "You must have a clean working tree and index to perform a revert."); getProgressListener().started(); final boolean hasConflicts = conflictsDatabase().hasConflicts(null); Preconditions.checkState(!hasConflicts || abort, "Cannot run operation while merge conflicts exist."); Optional<Ref> ref = command(RefParse.class).setName(Ref.ORIG_HEAD).call(); if (abort) { Preconditions.checkState(ref.isPresent(), "Cannot abort. You are not in the middle of a revert process."); command(ResetOp.class).setMode(ResetMode.HARD) .setCommit(Suppliers.ofInstance(ref.get().getObjectId())).call(); command(UpdateRef.class).setDelete(true).setName(Ref.ORIG_HEAD).call(); return true; } else if (continueRevert) { applyNextCommit(false); getProgressListener().started();
private boolean applyNextCommit(final boolean useCommitChanges) { Repository repository = repository(); List<String> nextFile = readLines(context().blobStore(), NEXT); List<String> commitFile = readLines(context().blobStore(), commitBlobName); if (commitFile.isEmpty()) { return false; try (PersistedIterable<Conflict> conflicts = ConflictsUtils.newTemporaryConflictStream()) { if (useCommitChanges) { applyRevertedChanges(commit, conflicts); createCommit(commit); } else { workingTree().updateWorkHead(repository.index().getTree().getId()); if (numConflicts > 0L) { command(ConflictsWriteOp.class).setConflicts(conflicts).call(); context().blobStore().removeBlob(commitBlobName); int newIdx = Integer.parseInt(idx) + 1; putBlob(context().blobStore(), NEXT, Integer.toString(newIdx)); return true;
checkParameter(commitId.isPresent(), "Couldn't resolve '" + st + "' to a commit, aborting revert."); revert.addCommit(Suppliers.ofInstance(commitId.get())); revert.setCreateCommit(!noCommit).setAbort(abort).setContinue(continueRevert).call(); } catch (RevertConflictsException e) { StringBuilder sb = new StringBuilder();
@Test public void testRevertToWrongCommit() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); exception.expect(IllegalArgumentException.class); geogig.command(RevertOp.class).addCommit(RevObjectTestSupport.hashString("wrong")).call(); }