public ImmutableList<Ref> getBranchList(RepositoryProvider provider, String repoName, boolean includeRemotes) { Repository repository = getRepository(provider, repoName); if (repository != null) { return repository.command(BranchListOp.class).setRemotes(includeRemotes).call(); } return ImmutableList.of(); }
/** * Prepares the list of {@link PushReq} objects based on the command arguments (whether all refs * are to be pushed, or specific ones through {@link #addRefSpec(String)}} * * @param remoteRefs the current state of the remote refs in it's local refs namespace (i.e. as * {@code refs/heads/*}, not {@code refs/remotes/...}) */ private List<PushReq> parseRequests(Set<Ref> remoteRefs) { List<PushReq> pushReqs = new ArrayList<>(); if (this.all) { List<Ref> localBranches; localBranches = command(BranchListOp.class).setLocal(true).setRemotes(false).call(); localBranches.forEach((r) -> pushReqs.add(PushReq.update(r, r.getName(), false))); } else if (this.refSpecs.isEmpty()) { // local branch only Ref headTarget = resolveHeadTarget(); pushReqs.add(PushReq.update(headTarget, headTarget.getName(), false)); } else { for (String refSpec : this.refSpecs) { PushReq pushReq = parseRefSpec(refSpec, remoteRefs); pushReqs.add(pushReq); } } return pushReqs; }
/** * Prepares the list of {@link PushReq} objects based on the command arguments (whether all refs * are to be pushed, or specific ones through {@link #addRefSpec(String)}} * * @param remoteRefs the current state of the remote refs in it's local refs namespace (i.e. as * {@code refs/heads/*}, not {@code refs/remotes/...}) */ private List<PushReq> parseRequests(Set<Ref> remoteRefs) { List<PushReq> pushReqs = new ArrayList<>(); if (this.all) { List<Ref> localBranches; localBranches = command(BranchListOp.class).setLocal(true).setRemotes(false).call(); localBranches.forEach((r) -> pushReqs.add(PushReq.update(r, r.getName(), false))); } else if (this.refSpecs.isEmpty()) { // local branch only Ref headTarget = resolveHeadTarget(); pushReqs.add(PushReq.update(headTarget, headTarget.getName(), false)); } else { for (String refSpec : this.refSpecs) { PushReq pushReq = parseRefSpec(refSpec, remoteRefs); pushReqs.add(pushReq); } } return pushReqs; }
/** * Executes the {@code RebuildGraphOp} operation. * * @return a list of {@link ObjectId}s that were found to be missing or incomplete */ @Override protected ImmutableList<ObjectId> _call() { Repository repository = repository(); Preconditions.checkState(!repository.isSparse(), "Cannot rebuild the graph of a sparse repository."); List<ObjectId> updated = new LinkedList<ObjectId>(); ImmutableList<Ref> branches = command(BranchListOp.class).setLocal(true).setRemotes(true) .call(); GraphDatabase graphDb = repository.graphDatabase(); for (Ref ref : branches) { Iterator<RevCommit> commits = command(LogOp.class).setUntil(ref.getObjectId()).call(); while (commits.hasNext()) { RevCommit next = commits.next(); if (graphDb.put(next.getId(), next.getParentIds())) { updated.add(next.getId()); } } } return ImmutableList.copyOf(updated); } }
/** * Executes the {@code RebuildGraphOp} operation. * * @return a list of {@link ObjectId}s that were found to be missing or incomplete */ @Override protected ImmutableList<ObjectId> _call() { Repository repository = repository(); Preconditions.checkState(!repository.isSparse(), "Cannot rebuild the graph of a sparse repository."); List<ObjectId> updated = new LinkedList<ObjectId>(); ImmutableList<Ref> branches = command(BranchListOp.class).setLocal(true).setRemotes(true) .call(); GraphDatabase graphDb = repository.graphDatabase(); for (Ref ref : branches) { Iterator<RevCommit> commits = command(LogOp.class).setUntil(ref.getObjectId()).call(); while (commits.hasNext()) { RevCommit next = commits.next(); if (graphDb.put(next.getId(), next.getParentIds())) { updated.add(next.getId()); } } } return ImmutableList.copyOf(updated); } }
/** * Builds an index on every reachable commit in the history. * * @param index the {@link IndexInfo} to use * @return the number of trees that were built */ private int indexHistory(IndexInfo index) { ImmutableList<Ref> branches = command(BranchListOp.class).setLocal(true).setRemotes(true) .call(); int builtTrees = 0; ProgressListener listener = getProgressListener(); for (Ref ref : branches) { if (listener.isCanceled()) { break; } Iterator<RevCommit> commits = command(LogOp.class).setUntil(ref.getObjectId()).call(); while (commits.hasNext()) { if (listener.isCanceled()) { break; } RevCommit next = commits.next(); if (indexCommit(index, next)) { builtTrees++; } } } return builtTrees; }
@Test public void testRemoteListing() throws Exception { ImmutableList<Ref> branches = localGeogig.geogig.command(BranchListOp.class).setLocal(true) .setRemotes(true).call(); assertEquals(Ref.HEADS_PREFIX + "Branch1", branches.get(0).getName()); assertEquals(Ref.HEADS_PREFIX + "master", branches.get(1).getName()); assertEquals(Ref.REMOTES_PREFIX + REMOTE_NAME + "/Branch1", branches.get(2).getName()); assertEquals(Ref.REMOTES_PREFIX + REMOTE_NAME + "/master", branches.get(3).getName()); } }
@Test public void testBranchListOp() throws Exception { ImmutableList<Ref> branches = remoteGeogig.geogig.command(BranchListOp.class).setLocal(true) .setRemotes(false).call(); assertEquals(Ref.HEADS_PREFIX + "Branch1", branches.get(0).getName()); assertEquals(Ref.HEADS_PREFIX + "master", branches.get(1).getName()); }
@Test public void testBranchListOp() throws Exception { ImmutableList<Ref> branches = remoteGeogig.geogig.command(BranchListOp.class).setLocal(true) .setRemotes(false).call(); assertEquals(Ref.HEADS_PREFIX + "Branch1", branches.get(0).getName()); assertEquals(Ref.HEADS_PREFIX + "master", branches.get(1).getName()); }
.setRemotes(remote).call();
.setRemotes(remote).call();
.setRemotes(remote).call();
@Test public void testRemoteListing() throws Exception { ImmutableList<Ref> branches = localGeogig.geogig.command(BranchListOp.class).setLocal(true) .setRemotes(true).call(); assertEquals(Ref.HEADS_PREFIX + "Branch1", branches.get(0).getName()); assertEquals(Ref.HEADS_PREFIX + "master", branches.get(1).getName()); assertEquals(Ref.REMOTES_PREFIX + REMOTE_NAME + "/Branch1", branches.get(2).getName()); assertEquals(Ref.REMOTES_PREFIX + REMOTE_NAME + "/HEAD", branches.get(3).getName()); assertEquals(Ref.REMOTES_PREFIX + REMOTE_NAME + "/master", branches.get(4).getName()); } }
/** * Builds an index on every reachable commit in the history. * * @param index the {@link IndexInfo} to use * @return the number of trees that were built */ private int indexHistory(IndexInfo index) { ImmutableList<Ref> branches = command(BranchListOp.class).setLocal(true).setRemotes(true) .call(); int builtTrees = 0; ProgressListener listener = getProgressListener(); for (Ref ref : branches) { if (listener.isCanceled()) { break; } getProgressListener().setDescription("Building index for %s:%s at %s", index.getTreeName(), index.getAttributeName(), ref.getName()); Iterator<RevCommit> commits = command(LogOp.class).setUntil(ref.getObjectId()).call(); while (commits.hasNext()) { if (listener.isCanceled()) { break; } RevCommit next = commits.next(); if (indexCommit(index, next)) { builtTrees++; } } } return builtTrees; }
if (remotes) { remoteBranches = geogig.command(BranchListOp.class).setLocal(false) .setRemotes(remotes).call(); } else { remoteBranches = Lists.newLinkedList();