@Override public void setTransaction(@Nullable final Transaction transaction) { Preconditions.checkArgument(!Transaction.AUTO_COMMIT.equals(transaction)); if (transaction != null && this.tx != null) { throw new IllegalStateException( "New transaction set without closing old transaction first."); } this.tx = transaction; if (transaction == null) { // Transaction.removeState has been called (during // transaction.close()) if (this.geogigTx != null) { // throw new // IllegalStateException("Transaction is attempting to " // + "close a non committed or aborted geogig transaction"); geogigTx.abort(); } this.geogigTx = null; } else { if (this.geogigTx != null) { geogigTx.abort(); } GeoGigDataStore dataStore = (GeoGigDataStore) entry.getDataStore(); Context commandLocator = dataStore.resolveContext(this.tx); this.geogigTx = commandLocator.command(TransactionBegin.class).call(); // checkout the working branch final String workingBranch = dataStore.getOrFigureOutHead(); this.geogigTx.command(CheckoutOp.class).setForce(true).setSource(workingBranch).call(); } }
@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()); }
@Test public void testCheckoutTheirs() throws Exception { createConflictedState(); String path = NodeRef.appendChild(pointsName, idP1); geogig.command(CheckoutOp.class).addPath(path).setTheirs(true).call(); Optional<Node> node = geogig.getRepository().workingTree().findUnstaged(path); String headPath = Ref.MERGE_HEAD + ":" + path; Optional<ObjectId> id = geogig.command(RevParse.class).setRefSpec(headPath).call(); assertEquals(id.get(), node.get().getObjectId()); }
@Test public void testCheckoutOurs() throws Exception { createConflictedState(); String path = NodeRef.appendChild(pointsName, idP1); geogig.command(CheckoutOp.class).addPath(path).setOurs(true).call(); Optional<Node> node = geogig.getRepository().workingTree().findUnstaged(path); String headPath = Ref.HEAD + ":" + path; Optional<ObjectId> id = geogig.command(RevParse.class).setRefSpec(headPath).call(); assertEquals(id.get(), node.get().getObjectId()); }
@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()); }
@Test public void testCheckoutNoParametersSet() { exception.expect(IllegalStateException.class); geogig.command(CheckoutOp.class).call(); }
public CheckoutOp addPaths(final Collection<? extends CharSequence> paths) { checkNotNull(paths); for (CharSequence path : paths) { addPath(path); } return this; }
@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()); }
@Test public void testCheckoutTheirsDeleted() throws Exception { createDeleteTheirsConflictedState(); String path = NodeRef.appendChild(pointsName, idP1); geogig.command(CheckoutOp.class).addPath(path).setTheirs(true).call(); Optional<Node> node = geogig.getRepository().index().findStaged(path); assertFalse(node.isPresent()); String headPath = Ref.MERGE_HEAD + ":" + path; Optional<ObjectId> id = geogig.command(RevParse.class).setRefSpec(headPath).call(); assertFalse(id.isPresent()); }
@Test public void testCheckoutOursDeleted() throws Exception { createDeleteOursConflictedState(); String path = NodeRef.appendChild(pointsName, idP1); geogig.command(CheckoutOp.class).addPath(path).setOurs(true).call(); Optional<Node> node = geogig.getRepository().index().findStaged(path); assertFalse(node.isPresent()); String headPath = Ref.HEAD + ":" + path; Optional<ObjectId> id = geogig.command(RevParse.class).setRefSpec(headPath).call(); assertFalse(id.isPresent()); }