Search in sources :

Example 6 with CheckoutResult

use of org.locationtech.geogig.api.porcelain.CheckoutResult in project GeoGig by boundlessgeo.

the class Checkout method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    final GeoGIG geogig = cli.getGeogig();
    checkParameter(branchOrStartPoint.size() != 0 || !paths.isEmpty(), "no branch or paths specified");
    checkParameter(branchOrStartPoint.size() < 2, "too many arguments");
    try {
        final ConsoleReader console = cli.getConsole();
        String branchOrCommit = (branchOrStartPoint.size() > 0 ? branchOrStartPoint.get(0) : null);
        CheckoutResult result = geogig.command(CheckoutOp.class).setForce(force).setSource(branchOrCommit).addPaths(paths).setOurs(ours).setTheirs(theirs).call();
        switch(result.getResult()) {
            case CHECKOUT_LOCAL_BRANCH:
                console.println("Switched to branch '" + result.getNewRef().localName() + "'");
                break;
            case CHECKOUT_REMOTE_BRANCH:
                console.println("Branch '" + result.getNewRef().localName() + "' was set up to track remote branch '" + result.getNewRef().localName() + "' from " + result.getRemoteName() + ".");
                console.println("Switched to a new branch '" + result.getNewRef().localName() + "'");
                break;
            case UPDATE_OBJECTS:
                console.println("Objects in the working tree were updated to the specifed version.");
                break;
            case DETACHED_HEAD:
                console.println("You are in 'detached HEAD' state. HEAD is now at " + result.getOid().toString().substring(0, 7) + "...");
                break;
            default:
                break;
        }
    } catch (CheckoutException e) {
        switch(e.statusCode) {
            case LOCAL_CHANGES_NOT_COMMITTED:
                throw new CommandFailedException("Working tree and index are not clean. To overwrite local changes, use the --force option", e);
            case UNMERGED_PATHS:
                throw new CommandFailedException(e.getMessage(), e);
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) CheckoutResult(org.locationtech.geogig.api.porcelain.CheckoutResult) GeoGIG(org.locationtech.geogig.api.GeoGIG) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) CheckoutException(org.locationtech.geogig.api.porcelain.CheckoutException)

Example 7 with CheckoutResult

use of org.locationtech.geogig.api.porcelain.CheckoutResult in project GeoGig by boundlessgeo.

the class RebaseOpTest method testRebaseSquash.

@Test
public void testRebaseSquash() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - master - Points 1 added
    // |\
    // | o - branch1 - Points 2 added
    // |
    // o - Points 3 added
    // |
    // o - branch2 - HEAD - Lines 1 added
    insertAndAdd(points1);
    final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    // create branch1 and checkout
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
    insertAndAdd(points2);
    final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
    // checkout master, then create branch2 and checkout
    geogig.command(CheckoutOp.class).setSource("master").call();
    final Ref branch2 = geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch2").call();
    insertAndAdd(points3);
    final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
    insertAndAdd(lines1);
    final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    geogig.command(RebaseOp.class).setUpstream(Suppliers.ofInstance(branch1.getObjectId())).setSquashMessage("squashed commit").call();
    CheckoutResult result;
    result = geogig.command(CheckoutOp.class).setSource("branch1").call();
    assertEquals(c2.getTreeId(), result.getNewTree());
    assertTrue(geogig.command(RefParse.class).setName(Ref.HEAD).call().get() instanceof SymRef);
    assertEquals(branch1.getName(), ((SymRef) geogig.command(RefParse.class).setName(Ref.HEAD).call().get()).getTarget());
    result = geogig.command(CheckoutOp.class).setSource("branch2").call();
    assertFalse(c4.getTreeId().equals(result.getNewTree()));
    assertTrue(geogig.command(RefParse.class).setName(Ref.HEAD).call().get() instanceof SymRef);
    assertEquals(branch2.getName(), ((SymRef) geogig.command(RefParse.class).setName(Ref.HEAD).call().get()).getTarget());
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    // Commit 4
    RevCommit logC4 = log.next();
    assertEquals(c4.getAuthor(), logC4.getAuthor());
    assertEquals(c4.getCommitter().getName(), logC4.getCommitter().getName());
    assertEquals(c4.getCommitter().getEmail(), logC4.getCommitter().getEmail());
    assertEquals("squashed commit", logC4.getMessage());
    assertEquals(c4.getAuthor().getTimeZoneOffset(), logC4.getAuthor().getTimeZoneOffset());
    assertEquals(c4.getAuthor().getTimestamp(), logC4.getAuthor().getTimestamp());
    assertEquals(c4.getCommitter().getTimeZoneOffset(), logC4.getCommitter().getTimeZoneOffset());
    assertFalse(c4.getCommitter().getTimestamp() == logC4.getCommitter().getTimestamp());
    assertFalse(c4.getTreeId().equals(logC4.getTreeId()));
    String path = NodeRef.appendChild(linesName, idL1);
    Optional<RevFeature> lines = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(lines.isPresent());
    path = NodeRef.appendChild(pointsName, idP3);
    Optional<RevFeature> points = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(points.isPresent());
    // Commit 2
    RevCommit logC2 = log.next();
    assertEquals(c2.getAuthor(), logC2.getAuthor());
    assertEquals(c2.getCommitter().getName(), logC2.getCommitter().getName());
    assertEquals(c2.getMessage(), logC2.getMessage());
    assertEquals(c2.getAuthor().getTimeZoneOffset(), logC2.getAuthor().getTimeZoneOffset());
    assertEquals(c2.getAuthor().getTimestamp(), logC2.getAuthor().getTimestamp());
    assertEquals(c2.getCommitter().getTimeZoneOffset(), logC2.getCommitter().getTimeZoneOffset());
    assertEquals(c2.getCommitter().getTimestamp(), logC2.getCommitter().getTimestamp());
    assertEquals(c2.getTreeId(), logC2.getTreeId());
    // Commit 1
    RevCommit logC1 = log.next();
    assertEquals(c1.getAuthor(), logC1.getAuthor());
    assertEquals(c1.getCommitter().getName(), logC1.getCommitter().getName());
    assertEquals(c1.getMessage(), logC1.getMessage());
    assertEquals(c1.getAuthor().getTimeZoneOffset(), logC1.getAuthor().getTimeZoneOffset());
    assertEquals(c1.getAuthor().getTimestamp(), logC1.getAuthor().getTimestamp());
    assertEquals(c1.getCommitter().getTimeZoneOffset(), logC1.getCommitter().getTimeZoneOffset());
    assertEquals(c1.getCommitter().getTimestamp(), logC1.getCommitter().getTimestamp());
    assertEquals(c1.getTreeId(), logC1.getTreeId());
}
Also used : LogOp(org.locationtech.geogig.api.porcelain.LogOp) CheckoutOp(org.locationtech.geogig.api.porcelain.CheckoutOp) Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) NodeRef(org.locationtech.geogig.api.NodeRef) SymRef(org.locationtech.geogig.api.SymRef) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) RebaseOp(org.locationtech.geogig.api.porcelain.RebaseOp) CheckoutResult(org.locationtech.geogig.api.porcelain.CheckoutResult) RevFeature(org.locationtech.geogig.api.RevFeature) RefParse(org.locationtech.geogig.api.plumbing.RefParse) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 8 with CheckoutResult

use of org.locationtech.geogig.api.porcelain.CheckoutResult in project GeoGig by boundlessgeo.

the class CheckoutOpTest method testCheckoutPathFilterWithTreeOtherThanIndex.

@Test
public void testCheckoutPathFilterWithTreeOtherThanIndex() throws Exception {
    ObjectId points1Id = insertAndAdd(points1);
    geogig.command(CommitOp.class).setMessage("commit 1").call();
    ObjectId points2Id = insertAndAdd(points2);
    RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit 2").call();
    insertAndAdd(points3);
    geogig.command(CommitOp.class).setMessage("commit 3").call();
    insert(points1_modified);
    CheckoutResult result = geogig.command(CheckoutOp.class).setSource(c2.getTreeId().toString()).addPath("Points").call();
    Optional<RevTree> workTree = geogig.command(RevObjectParse.class).setObjectId(result.getNewTree()).call(RevTree.class);
    Optional<NodeRef> nodeRef = geogig.command(FindTreeChild.class).setParent(workTree.get()).setChildPath("Points/Points.1").call();
    assertEquals(points1Id, nodeRef.get().getNode().getObjectId());
    nodeRef = geogig.command(FindTreeChild.class).setParent(workTree.get()).setChildPath("Points/Points.2").call();
    assertEquals(points2Id, nodeRef.get().getNode().getObjectId());
    nodeRef = geogig.command(FindTreeChild.class).setParent(workTree.get()).setChildPath("Points/Points.3").call();
    assertFalse(nodeRef.isPresent());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) CheckoutResult(org.locationtech.geogig.api.porcelain.CheckoutResult) CheckoutOp(org.locationtech.geogig.api.porcelain.CheckoutOp) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 9 with CheckoutResult

use of org.locationtech.geogig.api.porcelain.CheckoutResult in project GeoGig by boundlessgeo.

the class CheckoutOpTest method testCheckoutBranchWithForceOptionAndChangesInTheIndex.

@Test
public void testCheckoutBranchWithForceOptionAndChangesInTheIndex() throws Exception {
    insertAndAdd(points1);
    RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    Ref branch1 = geogig.command(BranchCreateOp.class).setName("branch1").call();
    insertAndAdd(points2);
    CheckoutResult result = geogig.command(CheckoutOp.class).setSource("branch1").setForce(true).call();
    assertEquals(c1.getTreeId(), result.getNewTree());
    assertTrue(geogig.command(RefParse.class).setName(Ref.HEAD).call().get() instanceof SymRef);
    assertEquals(branch1.getName(), ((SymRef) geogig.command(RefParse.class).setName(Ref.HEAD).call().get()).getTarget());
}
Also used : Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) NodeRef(org.locationtech.geogig.api.NodeRef) SymRef(org.locationtech.geogig.api.SymRef) CheckoutResult(org.locationtech.geogig.api.porcelain.CheckoutResult) CheckoutOp(org.locationtech.geogig.api.porcelain.CheckoutOp) RefParse(org.locationtech.geogig.api.plumbing.RefParse) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 10 with CheckoutResult

use of org.locationtech.geogig.api.porcelain.CheckoutResult in project GeoGig by boundlessgeo.

the class CheckoutOpTest method testCheckoutPathFilterWithMultiplePaths.

@Test
public void testCheckoutPathFilterWithMultiplePaths() throws Exception {
    ObjectId points1Id = insertAndAdd(points1);
    ObjectId lines1Id = insertAndAdd(lines1);
    geogig.command(CommitOp.class).setMessage("commit 1").call();
    insert(points1_modified);
    insert(lines2);
    Collection<String> paths = Arrays.asList("Points/Points.1", "Lines");
    CheckoutResult result = geogig.command(CheckoutOp.class).addPaths(paths).call();
    Optional<RevTree> workTree = geogig.command(RevObjectParse.class).setObjectId(result.getNewTree()).call(RevTree.class);
    Optional<NodeRef> nodeRef = geogig.command(FindTreeChild.class).setParent(workTree.get()).setChildPath("Points/Points.1").call();
    assertEquals(points1Id, nodeRef.get().getNode().getObjectId());
    nodeRef = geogig.command(FindTreeChild.class).setParent(workTree.get()).setChildPath("Lines/Lines.1").call();
    assertEquals(lines1Id, nodeRef.get().getNode().getObjectId());
    nodeRef = geogig.command(FindTreeChild.class).setParent(workTree.get()).setChildPath("Lines/Lines.2").call();
    assertFalse(nodeRef.isPresent());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) CheckoutResult(org.locationtech.geogig.api.porcelain.CheckoutResult) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) RevTree(org.locationtech.geogig.api.RevTree) Test(org.junit.Test)

Aggregations

CheckoutResult (org.locationtech.geogig.api.porcelain.CheckoutResult)11 Test (org.junit.Test)10 NodeRef (org.locationtech.geogig.api.NodeRef)10 CheckoutOp (org.locationtech.geogig.api.porcelain.CheckoutOp)8 RevCommit (org.locationtech.geogig.api.RevCommit)7 Ref (org.locationtech.geogig.api.Ref)6 SymRef (org.locationtech.geogig.api.SymRef)6 RefParse (org.locationtech.geogig.api.plumbing.RefParse)6 RevTree (org.locationtech.geogig.api.RevTree)4 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)4 BranchCreateOp (org.locationtech.geogig.api.porcelain.BranchCreateOp)4 ObjectId (org.locationtech.geogig.api.ObjectId)3 LogOp (org.locationtech.geogig.api.porcelain.LogOp)3 RebaseOp (org.locationtech.geogig.api.porcelain.RebaseOp)2 ConsoleReader (jline.console.ConsoleReader)1 GeoGIG (org.locationtech.geogig.api.GeoGIG)1 RevFeature (org.locationtech.geogig.api.RevFeature)1 CheckoutException (org.locationtech.geogig.api.porcelain.CheckoutException)1 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)1