// clone the repository
try {
Repository canonical = getRepository(repository.name);
File folder = new File(repositoryManager.getRepositoriesFolder(), cloneName);
CloneCommand clone = new CloneCommand();
clone.setBare(true);
// fetch branches with exclusions
Collection<Ref> branches = canonical.getRefDatabase().getRefs(Constants.R_HEADS).values();
List<String> branchesToClone = new ArrayList<String>();
for (Ref branch : branches) {
String name = branch.getName();
if (name.startsWith(Constants.R_TICKET)) {
// exclude ticket branches
continue;
}
branchesToClone.add(name);
}
clone.setBranchesToClone(branchesToClone);
clone.setURI(fromUrl);
clone.setDirectory(folder);
Git git = clone.call();
// fetch tags
FetchCommand fetch = git.fetch();
fetch.setRefSpecs(new RefSpec("+refs/tags/*:refs/tags/*"));
fetch.call();