public List<Ref> listBranches(final String repositoryId) throws IOException { Repository geogig = getRepository(repositoryId); List<Ref> refs = geogig.command(BranchListOp.class).call(); return refs; }
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(); }
public List<BranchConfig> getAll() { List<BranchConfig> configs = new ArrayList<>(); final Map<String, String> all = configDatabase().getAll(); for (Ref branch : command(BranchListOp.class).call()) { final String section = String.format("branches.%s", branch.localName()); final String remoteKey = String.format("%s.%s", section, "remote"); final String remoteBranchKey = String.format("%s.%s", section, "merge"); final String descriptionKey = String.format("%s.%s", section, "description"); String remoteName = all.get(remoteKey); String remoteBranch = all.get(remoteBranchKey); String description = all.get(descriptionKey); BranchConfig config = BranchConfig.builder()// .branch(branch)// .remoteName(Optional.ofNullable(remoteName))// .remoteBranch(Optional.ofNullable(remoteBranch))// .description(Optional.ofNullable(description))// .build(); configs.add(config); } return configs; }
/** * 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; }
public static Map<Ref, List<Index>> createIndexes(Repository repo) { Map<Ref, List<Index>> indexes = new HashMap<>(); ImmutableList<Ref> branches = repo.command(BranchListOp.class).call(); branches.forEach(ref -> indexes.put(ref, createIndexes(repo, ref))); return indexes; }
public static List<Ref> getBranches(Repository repo, Optional<String> branch) { List<Ref> branches; if (branch.isPresent()) { Optional<Ref> r = repo.command(RefParse.class).setName(branch.get()).call(); if (r.isPresent()) { branches = Collections.singletonList(r.get()); } else { return Collections.emptyList(); } } else { branches = repo.command(BranchListOp.class).call(); } return branches; }
private RepoInfo toRepoInfo(String name, Repository repo) { RepoInfo info = new RepoInfo(); info.name = name; ImmutableList<Ref> branches = repo.command(BranchListOp.class).call(); info.numBranches = branches.size(); final Set<ObjectId> uniqueCommits = Sets.newConcurrentHashSet();
/** * 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; }
private void verifyBranchConfig(Repository remote, Repository clone) { ImmutableList<Ref> remoteBranches = remote.command(BranchListOp.class).call(); for (Ref remoteBranch : remoteBranches) { BranchConfig config = clone.command(BranchConfigOp.class) .setName(remoteBranch.localName()).get(); assertEquals(remoteBranch.localName(), config.getBranch().localName()); assertEquals("origin", config.getRemoteName().get()); assertEquals(remoteBranch.getName(), config.getRemoteBranch().get()); } }