*/
public Collection<Ref> call() throws GitAPIException,
JGitInternalException {
checkCallable();
Transport transport = null;
FetchConnection fc = null;
try {
transport = Transport.open(repo, remote);
transport.setOptionUploadPack(uploadPack);
configure(transport);
Collection<RefSpec> refSpecs = new ArrayList<RefSpec>(1);
if (tags)
refSpecs.add(new RefSpec(
"refs/tags/*:refs/remotes/origin/tags/*"));
if (heads)
refSpecs.add(new RefSpec("refs/heads/*:refs/remotes/origin/*"));
Collection<Ref> refs;
Map<String, Ref> refmap = new HashMap<String, Ref>();
fc = transport.openFetch();
refs = fc.getRefs();
if (refSpecs.isEmpty())
for (Ref r : refs)
refmap.put(r.getName(), r);
else
for (Ref r : refs)
for (RefSpec rs : refSpecs)
if (rs.matchSource(r)) {
refmap.put(r.getName(), r);
break;
}
return refmap.values();
} catch (URISyntaxException e) {
throw new InvalidRemoteException(MessageFormat.format(
JGitText.get().invalidRemote, remote));
} catch (NotSupportedException e) {
throw new JGitInternalException(
JGitText.get().exceptionCaughtDuringExecutionOfLsRemoteCommand,
e);
} catch (TransportException e) {
throw new org.eclipse.jgit.api.errors.TransportException(
JGitText.get().exceptionCaughtDuringExecutionOfLsRemoteCommand,
e);
} finally {
if (fc != null)
fc.close();
if (transport != null)
transport.close();
}
}