protected @Override java.util.Optional<Ref> _call() { Ref head = command(RefParse.class).setName(branchName).call().orNull(); if (head != null && Ref.HEAD.equals(branchName) && (head instanceof SymRef)) { head = head.peel(); } return Optional.ofNullable(head); }
/** * Gets the remote ref that matches the provided ref spec. * * @param refspec the refspec to parse * @return the matching {@link Ref} or {@link Optional#absent()} if the ref could not be found */ @Override protected Optional<Ref> getRemoteRef(String refspec) { return remoteRepo.command(RefParse.class).setName(refspec).call(); }
/** * @param revStr the string to parse * @return the parsed {@link Ref}, or {@link Optional#absent()} if it did not parse. */ @Override public Optional<Ref> getRef(final String revStr) { Optional<Ref> ref = command(RefParse.class).setName(revStr).call(); return ref; }
/** * Gets the remote ref that matches the provided ref spec. * * @param refspec the refspec to parse * @return the matching {@link Ref} or {@link Optional#absent()} if the ref could not be found */ @Override protected Optional<Ref> getRemoteRef(String refspec) { return remoteRepo.command(RefParse.class).setName(refspec).call(); }
/** * @param ref the ref to find * @return an {@link Optional} of the ref, or {@link Optional#absent()} if it wasn't found */ public Optional<Ref> findRemoteRef(String ref) { String remoteRef = Ref.REMOTES_PREFIX + remote.get().get().getName() + "/" + ref; return command(RefParse.class).setName(remoteRef).call(); } }
/** * @return the remote's HEAD {@link Ref}. */ @Override public Optional<Ref> headRef() { final Optional<Ref> currHead = remoteRepository.command(RefParse.class).setName(Ref.HEAD) .call(); return currHead; }
/** * @param revStr the string to parse * @return the parsed {@link Ref}, or {@link Optional#absent()} if it did not parse. */ @Override public Optional<Ref> getRef(final String revStr) { Optional<Ref> ref = command(RefParse.class).setName(revStr).call(); return ref; }
@Test public void testResolveSymbolicRef() { when(mockRefDb.getRef(eq("HEAD"))).thenThrow(new IllegalArgumentException()); when(mockRefDb.getSymRef(eq("HEAD"))).thenReturn("refs/heads/branch1"); Optional<Ref> ref = command.setName("HEAD").call(); assertTrue(ref.isPresent()); assertTrue(ref.get() instanceof SymRef); assertEquals("HEAD", ref.get().getName()); assertEquals("refs/heads/branch1", ((SymRef) ref.get()).getTarget()); } }
private void testRsolvePartial(String refSpec, String refName) { Optional<Ref> ref; ref = command.setName(refSpec).call(); assertTrue(ref.isPresent()); assertEquals(refName, ref.get().getName()); assertEquals(RevObjectTestSupport.hashString(refName), ref.get().getObjectId()); }
public TestData checkout(String branch) { getContext().command(CheckoutOp.class).setSource(branch).call(); Ref head = getContext().command(RefParse.class).setName(Ref.HEAD).call().get(); if (head instanceof SymRef) { String target = ((SymRef) head).getTarget(); head = getContext().command(RefParse.class).setName(target).call().get(); } String headBranch = head.localName(); checkState(branch.equals(headBranch), "expected %s, got %s", branch, headBranch); return this; }
public TestData mergeNoFF(String branchToMerge, String mergeCommitMessage) { ObjectId branchHead = getContext().command(RefParse.class).setName(branchToMerge).call() .get().getObjectId(); MergeReport report = getContext().command(MergeOp.class).setNoFastForward(true) .setMessage(mergeCommitMessage).addCommit(branchHead).call(); RevCommit mergeCommit = report.getMergeCommit(); checkState(mergeCommit.getParentIds().size() == 2); LOG.debug(mergeCommit.toString()); return this; }
@Test public void testRebaseNoCommits() throws Exception { Optional<Ref> master = geogig.command(RefParse.class).setName("master").call(); exception.expect(IllegalStateException.class); geogig.command(RebaseOp.class).setUpstream(Suppliers.ofInstance(master.get().getObjectId())) .call(); }
@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 testRebaseNoUpstreamCommit() throws Exception { Optional<Ref> master = geogig.command(RefParse.class).setName("master").call(); insertAndAdd(points1); geogig.command(CommitOp.class).setMessage("commit for " + idP1).call(); exception.expect(IllegalStateException.class); geogig.command(RebaseOp.class).setUpstream(Suppliers.ofInstance(master.get().getObjectId())) .call(); }
@Given("^I have a remote ref called \"([^\"]*)\"$") public void i_have_a_remote_ref_called(String expected) throws Throwable { String ref = "refs/remotes/origin/" + expected; localRepo.geogigCLI.getGeogig(Hints.readWrite()).command(UpdateRef.class).setName(ref) .setNewValue(ObjectId.NULL).call(); Optional<Ref> refValue = localRepo.geogigCLI.getGeogig(Hints.readWrite()) .command(RefParse.class).setName(ref).call(); assertTrue(refValue.isPresent()); assertEquals(refValue.get().getObjectId(), ObjectId.NULL); }
@Given("^I have a merge conflict state$") public void I_have_a_merge_conflict_state() throws Throwable { I_have_conflicting_branches(); Ref branch = localRepo.geogigCLI.getGeogig(Hints.readOnly()).command(RefParse.class) .setName("branch1").call().get(); try { localRepo.geogigCLI.getGeogig(Hints.readWrite()).command(MergeOp.class) .addCommit(branch.getObjectId()).call(); fail(); } catch (MergeConflictsException e) { } }
@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()); }
private void fakeUpToDate() { Remote remote = request.buildRemote(); GeogigTransaction tx = request.getTransaction(origin.getRepo().context()); tx.command(FetchOp.class).setFetchIndexes(true).addRemote(remote).call(); Ref remoteBranchState = clone.getRef(request.getRemoteBranch()); Ref localRemoteBranchState = tx.command(RefParse.class).setName(request.getOriginRef()) .call().get(); assertEquals(remoteBranchState.getObjectId(), localRemoteBranchState.getObjectId()); } }