public TestData branch(String newBranch) { Ref ref = getContext().command(BranchCreateOp.class).setName(newBranch).call(); checkState(newBranch.equals(ref.localName())); return this; }
@Test public void testCreateBranchFromMasterWithNoCommitsMade() { exception.expect(IllegalArgumentException.class); geogig.command(BranchCreateOp.class).setName("branch1").call(); }
@Test public void testNullNameForBranch() { exception.expect(IllegalStateException.class); geogig.command(BranchCreateOp.class).setName(null).call(); }
@Test public void testNullNameForBranch() { exception.expect(IllegalStateException.class); geogig.command(BranchCreateOp.class).setName(null).call(); }
@Test public void testInvalidNameForBranch() { exception.expect(IllegalArgumentException.class); exception.expectMessage("Component of ref cannot have two consecutive dots (..) anywhere."); geogig.command(BranchCreateOp.class).setName("ma..er").call(); }
@Test public void testCreateBranchWithTheSameNameAsExistingBranch() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); geogig.command(BranchCreateOp.class).setName("branch1").setAutoCheckout(true).call(); exception.expect(IllegalArgumentException.class); geogig.command(BranchCreateOp.class).setName("branch1").call(); }
@Test public void testCreateBranchWithTheSameNameAsExistingBranch() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); geogig.command(BranchCreateOp.class).setName("branch1").setAutoCheckout(true).call(); exception.expect(IllegalArgumentException.class); geogig.command(BranchCreateOp.class).setName("branch1").call(); }
@Test public void testCreateBranchWithTheSameNameAsExistingBranchAndForce() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); geogig.command(BranchCreateOp.class).setName("branch1").call(); insertAndAdd(points2); RevCommit newCommit = geogig.command(CommitOp.class).setMessage("Commit2").call(); geogig.command(BranchCreateOp.class).setName("branch1").setForce(true).call(); Optional<Ref> branch1 = geogig.command(RefParse.class).setName("branch1").call(); assertTrue(branch1.isPresent()); assertEquals(branch1.get().getObjectId(), newCommit.getId()); }
@Test public void testCreateBranch() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); geogig.command(BranchCreateOp.class).setName("branch1").setAutoCheckout(true).call(); Optional<Ref> branch1 = geogig.command(RefParse.class).setName("branch1").call(); assertTrue(branch1.isPresent()); Optional<Ref> master = geogig.command(RefParse.class).setName("master").call(); assertEquals(master.get().getObjectId(), branch1.get().getObjectId()); }
@Test public void testCreateBranch() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); geogig.command(BranchCreateOp.class).setName("branch1").setAutoCheckout(true).call(); Optional<Ref> branch1 = geogig.command(RefParse.class).setName("branch1").call(); assertTrue(branch1.isPresent()); Optional<Ref> master = geogig.command(RefParse.class).setName("master").call(); assertEquals(master.get().getObjectId(), branch1.get().getObjectId()); }
@Test public void testCreateBranchFromNonExistentCommit() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); exception.expect(IllegalArgumentException.class); geogig.command(BranchCreateOp.class).setName("branch1").setAutoCheckout(true) .setSource("Nonexistent Commit").call(); }
@Test public void BranchPresentTest() throws Exception { insertAndAdd(points1); geogig.command(AddOp.class).call(); geogig.command(CommitOp.class).call(); geogig.command(BranchCreateOp.class).setName("TestBranch").call(); geogig.command(BranchDeleteOp.class).setName("TestBranch").call(); Optional<Ref> result = geogig.command(RefParse.class).setName("TestBranch").call(); assertFalse(result.isPresent()); }
@Test public void InvalidBranchNameTest() throws Exception { insertAndAdd(points1); geogig.command(AddOp.class).call(); geogig.command(CommitOp.class).call(); Ref testBranch = geogig.command(BranchCreateOp.class).setName("TestBranch").call(); testBranch = geogig.command(UpdateRef.class).setName("TestBranch") .setNewValue(testBranch.getObjectId()).call().get(); exception.expect(IllegalArgumentException.class); geogig.command(BranchDeleteOp.class).setName("TestBranch").call(); }
@Test public void testCheckoutBranchWithChangesInTheIndex() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); geogig.command(BranchCreateOp.class).setName("branch1").call(); insertAndAdd(points2); exception.expect(CheckoutException.class); geogig.command(CheckoutOp.class).setSource("branch1").call(); }
@Test public void testCheckoutBranchWithChangesInTheWorkTree() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); geogig.command(BranchCreateOp.class).setName("branch1").call(); insert(points2); exception.expect(CheckoutException.class); geogig.command(CheckoutOp.class).setSource("branch1").call(); }
@Test public void testOrphan() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); Ref branch1 = geogig.command(BranchCreateOp.class).setName("branch1").setAutoCheckout(true) .setOrphan(true).call(); assertEquals(ObjectId.NULL, branch1.getObjectId()); assertEquals(Ref.HEADS_PREFIX + "branch1", branch1.getName()); } }
@Test public void testConstructorAndMutators() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).call(); Ref branch = geogig.command(BranchCreateOp.class).setName("branch1").call(); geogig.command(UpdateSymRef.class).setDelete(false).setName(Ref.HEAD) .setNewValue("refs/heads/branch1").setOldValue(Ref.MASTER) .setReason("this is a test").call(); Optional<ObjectId> branchId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call(); assertTrue(branch.getObjectId().equals(branchId.get())); }
@Test public void testOrphan() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("Commit1").call(); Ref branch1 = geogig.command(BranchCreateOp.class).setName("branch1").setAutoCheckout(true) .setOrphan(true).call(); assertEquals(ObjectId.NULL, branch1.getObjectId()); assertEquals(Ref.HEADS_PREFIX + "branch1", branch1.getName()); } }
@Test public void testCreateBranchFromSomethingOtherThanCommit() throws Exception { insertAndAdd(points1); RevCommit c1 = geogig.command(CommitOp.class).setMessage("Commit1").call(); insertAndAdd(points2); geogig.command(CommitOp.class).setMessage("Commit2").call(); insertAndAdd(points3); geogig.command(CommitOp.class).setMessage("Commit3").call(); exception.expect(IllegalArgumentException.class); geogig.command(BranchCreateOp.class).setName("branch1").setAutoCheckout(true) .setSource(c1.getTreeId().toString()).call(); }
@Test public void testCreateBranchFromSomethingOtherThanCommit() throws Exception { insertAndAdd(points1); RevCommit c1 = geogig.command(CommitOp.class).setMessage("Commit1").call(); insertAndAdd(points2); geogig.command(CommitOp.class).setMessage("Commit2").call(); insertAndAdd(points3); geogig.command(CommitOp.class).setMessage("Commit3").call(); exception.expect(IllegalArgumentException.class); geogig.command(BranchCreateOp.class).setName("branch1").setAutoCheckout(true) .setSource(c1.getTreeId().toString()).call(); }