Search in sources :

Example 1 with CheckoutResult

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

the class CheckoutOpTest method testCheckoutCommitDettachedHead.

@Test
public void testCheckoutCommitDettachedHead() throws Exception {
    insertAndAdd(points1);
    final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    insertAndAdd(points2);
    final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
    insertAndAdd(lines1);
    final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idL2).call();
    CheckoutResult result;
    result = geogig.command(CheckoutOp.class).setSource(c1.getId().toString()).call();
    assertEquals(c1.getTreeId(), result.getNewTree());
    assertFalse(geogig.command(RefParse.class).setName(Ref.HEAD).call().get() instanceof SymRef);
    assertTrue(geogig.command(RefParse.class).setName(Ref.HEAD).call().get() instanceof Ref);
    result = geogig.command(CheckoutOp.class).setSource(c2.getId().toString()).call();
    assertEquals(c2.getTreeId(), result.getNewTree());
    result = geogig.command(CheckoutOp.class).setSource(c3.getId().toString()).call();
    assertEquals(c3.getTreeId(), result.getNewTree());
}
Also used : SymRef(org.locationtech.geogig.api.SymRef) Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) NodeRef(org.locationtech.geogig.api.NodeRef) 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 2 with CheckoutResult

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

the class CheckoutOpTest method testCheckoutPathFilter.

@Test
public void testCheckoutPathFilter() throws Exception {
    ObjectId points1Id = insertAndAdd(points1);
    geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    insert(points1_modified);
    CheckoutResult result = geogig.command(CheckoutOp.class).addPath("Points/Points.1").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());
}
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)

Example 3 with CheckoutResult

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

the class CheckoutOpTest method testCheckoutBranch.

@Test
public void testCheckoutBranch() throws Exception {
    insertAndAdd(points1);
    final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    final Ref branch1 = geogig.command(BranchCreateOp.class).setName("branch1").call();
    insertAndAdd(points2);
    final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
    final Ref branch2 = geogig.command(BranchCreateOp.class).setName("branch2").call();
    insertAndAdd(lines1);
    final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idL2).call();
    final Ref branch3 = geogig.command(BranchCreateOp.class).setName("branch3").call();
    CheckoutResult result;
    result = geogig.command(CheckoutOp.class).setSource("branch1").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());
    result = geogig.command(CheckoutOp.class).setSource("branch2").call();
    assertEquals(c2.getTreeId(), 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());
    result = geogig.command(CheckoutOp.class).setSource("branch3").call();
    assertEquals(c3.getTreeId(), result.getNewTree());
    assertTrue(geogig.command(RefParse.class).setName(Ref.HEAD).call().get() instanceof SymRef);
    assertEquals(branch3.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 4 with CheckoutResult

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

the class RebaseOpTest method testRebaseOnto.

@Test
public void testRebaseOnto() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - Points 1 added
    // |\
    // |-o - Points 2 added
    // |-|
    // |-o - branch1 - Points 3 added
    // |--\
    // |---o - branch 2 - HEAD - Lines 1 added
    // |
    // o - master - Lines 2 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);
    geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
    insertAndAdd(points3);
    final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
    // create branch2 and checkout
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch2").call();
    insertAndAdd(lines1);
    final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
    // checkout master and make a commit
    geogig.command(CheckoutOp.class).setSource("master").call();
    insertAndAdd(lines2);
    final RevCommit c5 = geogig.command(CommitOp.class).setMessage("commit for " + idL2).call();
    // checkout branch2
    geogig.command(CheckoutOp.class).setSource("branch2").call();
    // Rebase branch2 onto master to create the following revision graph
    // o
    // |
    // o - Points 1 added
    // |\
    // | o - Points 2 added
    // | |
    // | o - branch1 - Points 3 added
    // |
    // o - master - Lines 2 added
    // |
    // o - branch 2 - HEAD - Lines 1 added
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    Ref branch2 = geogig.command(RefParse.class).setName("branch2").call().get();
    Optional<Ref> master = geogig.command(RefParse.class).setName("master").call();
    geogig.command(RebaseOp.class).setUpstream(Suppliers.ofInstance(branch1.getObjectId())).setOnto(Suppliers.ofInstance(master.get().getObjectId())).call();
    CheckoutResult result;
    result = geogig.command(CheckoutOp.class).setSource("branch1").call();
    assertEquals(c3.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 3 -- Lines 1
    RevCommit logC3 = log.next();
    assertEquals(c4.getAuthor(), logC3.getAuthor());
    assertEquals(c4.getCommitter().getName(), logC3.getCommitter().getName());
    assertEquals(c4.getMessage(), logC3.getMessage());
    assertEquals(c4.getAuthor().getTimeZoneOffset(), logC3.getAuthor().getTimeZoneOffset());
    assertEquals(c4.getAuthor().getTimestamp(), logC3.getAuthor().getTimestamp());
    assertEquals(c4.getCommitter().getTimeZoneOffset(), logC3.getCommitter().getTimeZoneOffset());
    assertFalse(c4.getCommitter().getTimestamp() == logC3.getCommitter().getTimestamp());
    assertFalse(c4.getTreeId().equals(logC3.getTreeId()));
    // Commit 2 -- Lines 2
    RevCommit logC2 = log.next();
    assertEquals(c5, logC2);
    // Commit 1 -- Points 1
    RevCommit logC1 = log.next();
    assertEquals(c1, logC1);
}
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) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) LogOp(org.locationtech.geogig.api.porcelain.LogOp) RebaseOp(org.locationtech.geogig.api.porcelain.RebaseOp) CheckoutResult(org.locationtech.geogig.api.porcelain.CheckoutResult) RefParse(org.locationtech.geogig.api.plumbing.RefParse) CheckoutOp(org.locationtech.geogig.api.porcelain.CheckoutOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 5 with CheckoutResult

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

the class RebaseOpTest method testRebase.

@Test
public void testRebase() 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();
    // Rebase branch2 onto branch1 to 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
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    geogig.command(RebaseOp.class).setUpstream(Suppliers.ofInstance(branch1.getObjectId())).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(c4.getMessage(), 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()));
    // Commit 3
    RevCommit logC3 = log.next();
    assertEquals(c3.getAuthor(), logC3.getAuthor());
    assertEquals(c3.getCommitter().getName(), logC3.getCommitter().getName());
    assertEquals(c3.getCommitter().getEmail(), logC3.getCommitter().getEmail());
    assertEquals(c3.getMessage(), logC3.getMessage());
    assertEquals(c3.getAuthor().getTimeZoneOffset(), logC3.getAuthor().getTimeZoneOffset());
    assertEquals(c3.getAuthor().getTimestamp(), logC3.getAuthor().getTimestamp());
    assertEquals(c3.getCommitter().getTimeZoneOffset(), logC3.getCommitter().getTimeZoneOffset());
    assertFalse(c3.getCommitter().getTimestamp() == logC3.getCommitter().getTimestamp());
    assertFalse(c3.getTreeId().equals(logC3.getTreeId()));
    // 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 : 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) LogOp(org.locationtech.geogig.api.porcelain.LogOp) CheckoutResult(org.locationtech.geogig.api.porcelain.CheckoutResult) RefParse(org.locationtech.geogig.api.plumbing.RefParse) CheckoutOp(org.locationtech.geogig.api.porcelain.CheckoutOp) RevCommit(org.locationtech.geogig.api.RevCommit) 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