/** * Executes the tag removal operation. * * @return the tag to remove * */ @Override protected RevTag _call() throws RuntimeException { String fullPath = Ref.TAGS_PREFIX + name; Optional<RevObject> revTag = command(RevObjectParse.class).setRefSpec(fullPath).call(); Preconditions.checkArgument(revTag.isPresent(), "Wrong tag name: " + name); Preconditions.checkArgument(revTag.get().getType().equals(RevObject.TYPE.TAG), name + " does not resolve to a tag"); UpdateRef updateRef = command(UpdateRef.class).setName(fullPath).setDelete(true) .setReason("Delete tag " + name); Optional<Ref> tagRef = updateRef.call(); checkState(tagRef.isPresent()); return (RevTag) revTag.get(); }
/** * Executes the tag removal operation. * * @return the tag to remove * */ @Override protected RevTag _call() throws RuntimeException { String fullPath = Ref.TAGS_PREFIX + name; Optional<RevObject> revTag = command(RevObjectParse.class).setRefSpec(fullPath).call(); Preconditions.checkArgument(revTag.isPresent(), "Wrong tag name: " + name); Preconditions.checkArgument(revTag.get().getType().equals(RevObject.TYPE.TAG), name + " does not resolve to a tag"); UpdateRef updateRef = command(UpdateRef.class).setName(fullPath).setDelete(true) .setReason("Delete tag " + name); Optional<Ref> tagRef = updateRef.call(); checkState(tagRef.isPresent()); return (RevTag) revTag.get(); }
.setReason("Delete branch " + ref.getName()); branchRef = updateRef.call(); checkState(branchRef.isPresent());
.setReason("Delete branch " + ref.getName()); branchRef = updateRef.call(); checkState(branchRef.isPresent());
@Test public void testCreateNewRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); verify(injector, times(1)).repository(); verify(mockUpdateRef, times(1)).setName(eq(Ref.MASTER)); verify(mockUpdateRef, times(1)).setName(eq(Ref.WORK_HEAD)); verify(mockUpdateRef, times(1)).setName(eq(Ref.STAGE_HEAD)); verify(mockUpdateRef, times(1)).setNewValue(eq(ObjectId.NULL)); verify(mockUpdateRef, times(2)).setNewValue(eq(RevTree.EMPTY_TREE_ID)); verify(mockUpdateRef, times(3)).setReason(anyString()); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).setName(eq(Ref.HEAD)); verify(mockUpdateSymRef, times(1)).setNewValue(eq(Ref.MASTER)); verify(mockUpdateSymRef, times(1)).call(); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }
private void createDefaultRefs() { Optional<Ref> master = command(RefParse.class).setName(Ref.MASTER).call(); Preconditions.checkState(!master.isPresent(), Ref.MASTER + " was already initialized."); command(UpdateRef.class).setName(Ref.MASTER).setNewValue(ObjectId.NULL) .setReason("Repository initialization").call(); Optional<Ref> head = command(RefParse.class).setName(Ref.HEAD).call(); Preconditions.checkState(!head.isPresent(), Ref.HEAD + " was already initialized."); command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(Ref.MASTER) .setReason("Repository initialization").call(); Optional<Ref> workhead = command(RefParse.class).setName(Ref.WORK_HEAD).call(); Preconditions.checkState(!workhead.isPresent(), Ref.WORK_HEAD + " was already initialized."); command(UpdateRef.class).setName(Ref.WORK_HEAD).setNewValue(RevTree.EMPTY.getId()) .setReason("Repository initialization").call(); Optional<Ref> stagehead = command(RefParse.class).setName(Ref.STAGE_HEAD).call(); Preconditions.checkState(!stagehead.isPresent(), Ref.STAGE_HEAD + " was already initialized."); command(UpdateRef.class).setName(Ref.STAGE_HEAD).setNewValue(RevTree.EMPTY.getId()) .setReason("Repository initialization").call(); } }
@Test public void testCreateNewRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); verify(injector, times(1)).repository(); verify(mockUpdateRef, times(1)).setName(eq(Ref.MASTER)); verify(mockUpdateRef, times(1)).setName(eq(Ref.WORK_HEAD)); verify(mockUpdateRef, times(1)).setName(eq(Ref.STAGE_HEAD)); verify(mockUpdateRef, times(1)).setNewValue(eq(ObjectId.NULL)); verify(mockUpdateRef, times(2)).setNewValue(eq(RevTree.EMPTY_TREE_ID)); verify(mockUpdateRef, times(3)).setReason(anyString()); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).setName(eq(Ref.HEAD)); verify(mockUpdateSymRef, times(1)).setNewValue(eq(Ref.MASTER)); verify(mockUpdateSymRef, times(1)).call(); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }
private void createDefaultRefs() { Optional<Ref> master = command(RefParse.class).setName(Ref.MASTER).call(); Preconditions.checkState(!master.isPresent(), Ref.MASTER + " was already initialized."); command(UpdateRef.class).setName(Ref.MASTER).setNewValue(ObjectId.NULL) .setReason("Repository initialization").call(); Optional<Ref> head = command(RefParse.class).setName(Ref.HEAD).call(); Preconditions.checkState(!head.isPresent(), Ref.HEAD + " was already initialized."); command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(Ref.MASTER) .setReason("Repository initialization").call(); Optional<Ref> workhead = command(RefParse.class).setName(Ref.WORK_HEAD).call(); Preconditions.checkState(!workhead.isPresent(), Ref.WORK_HEAD + " was already initialized."); command(UpdateRef.class).setName(Ref.WORK_HEAD).setNewValue(RevTree.EMPTY.getId()) .setReason("Repository initialization").call(); Optional<Ref> stagehead = command(RefParse.class).setName(Ref.STAGE_HEAD).call(); Preconditions.checkState(!stagehead.isPresent(), Ref.STAGE_HEAD + " was already initialized."); command(UpdateRef.class).setName(Ref.STAGE_HEAD).setNewValue(RevTree.EMPTY.getId()) .setReason("Repository initialization").call(); } }
when(mockUpdateRef.setNewValue((ObjectId) anyObject())).thenReturn(mockUpdateRef); when(mockUpdateRef.setOldValue((ObjectId) anyObject())).thenReturn(mockUpdateRef); when(mockUpdateRef.setReason(anyString())).thenReturn(mockUpdateRef);
when(mockUpdateRef.setNewValue((ObjectId) anyObject())).thenReturn(mockUpdateRef); when(mockUpdateRef.setOldValue((ObjectId) anyObject())).thenReturn(mockUpdateRef); when(mockUpdateRef.setReason(anyString())).thenReturn(mockUpdateRef);
@Test public void testConstructorAndMutators() throws Exception { insertAndAdd(points1); RevCommit commit1 = geogig.command(CommitOp.class).call(); geogig.command(BranchCreateOp.class).setName("branch1").call(); insertAndAdd(points2); RevCommit commit2 = geogig.command(CommitOp.class).call(); Optional<Ref> newBranch = geogig.command(UpdateRef.class).setName("refs/heads/branch1") .setNewValue(commit2.getId()).setOldValue(commit1.getId()).setReason("Testing") .call(); assertTrue(newBranch.get().getObjectId().equals(commit2.getId())); assertFalse(newBranch.get().getObjectId().equals(commit1.getId())); }
@Test public void testConstructorAndMutators() throws Exception { insertAndAdd(points1); RevCommit commit1 = geogig.command(CommitOp.class).call(); geogig.command(BranchCreateOp.class).setName("branch1").call(); insertAndAdd(points2); RevCommit commit2 = geogig.command(CommitOp.class).call(); Optional<Ref> newBranch = geogig.command(UpdateRef.class).setName("refs/heads/branch1") .setNewValue(commit2.getId()).setOldValue(commit1.getId()).setReason("Testing") .call(); assertTrue(newBranch.get().getObjectId().equals(commit2.getId())); assertFalse(newBranch.get().getObjectId().equals(commit1.getId())); }